[cmake-commits] alex committed cmListCommand.h 1.8 1.9 cmListCommand.cxx 1.13 1.14

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Jul 12 11:56:47 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv31417/Source

Modified Files:
	cmListCommand.h cmListCommand.cxx 
Log Message:

ENH: add LIST(CONTAINS ...) patch from "Miguel A. Figueroa-Villanueva, miguelf (AT) ieee.org
added tests for LIST(CONTAINS, SORT, REVERSE)

Alex


Index: cmListCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.cxx,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- cmListCommand.cxx	26 Aug 2006 14:29:11 -0000	1.13
+++ cmListCommand.cxx	12 Jul 2007 15:56:45 -0000	1.14
@@ -42,6 +42,10 @@
     {
     return this->HandleAppendCommand(args);
     }
+  if(subCommand == "CONTAINS")
+    {
+    return this->HandleContainsCommand(args);
+    }
   if(subCommand == "INSERT")
     {
     return this->HandleInsertCommand(args);
@@ -200,6 +204,39 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmListCommand::HandleContainsCommand(std::vector<std::string> const& args)
+{
+  if(args.size() != 4)
+    {
+    this->SetError("sub-command CONTAINS requires three arguments.");
+    return false;
+    }
+
+  const std::string& listName = args[1];
+  const std::string& variableName = args[args.size() - 1];
+  // expand the variable
+  std::vector<std::string> varArgsExpanded;
+  if ( !this->GetList(varArgsExpanded, listName.c_str()) )
+    {
+    this->Makefile->AddDefinition(variableName.c_str(), "FALSE");
+    return true;
+    }
+
+  std::vector<std::string>::iterator it;
+  for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
+    {
+    if ( *it == args[2] )
+      {
+      this->Makefile->AddDefinition(variableName.c_str(), "TRUE");
+      return true;
+      }
+    }
+
+  this->Makefile->AddDefinition(variableName.c_str(), "FALSE");
+  return true;
+}
+
+//----------------------------------------------------------------------------
 bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
 {
   if(args.size() < 4)

Index: cmListCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cmListCommand.h	24 May 2007 12:18:46 -0000	1.8
+++ cmListCommand.h	12 Jul 2007 15:56:45 -0000	1.9
@@ -68,20 +68,24 @@
       "  LIST(GET <list> <element index> [<element index> ...] "
       "<output variable>)\n"
       "  LIST(APPEND <list> <element> [<element> ...])\n"
+      "  LIST(CONTAINS <list> <value> <output variable>)\n"
       "  LIST(INSERT <list> <element_index> <element> [<element> ...])\n"
       "  LIST(REMOVE_ITEM <list> <value> [<value> ...])\n"
       "  LIST(REMOVE_AT <list> <index> [<index> ...])\n"
-      "  LIST(SORT <list>)\n"
       "  LIST(REVERSE <list>)\n"
+      "  LIST(SORT <list>)\n"
       "LENGTH will return a given list's length.\n"
       "GET will return list of elements specified by indices from the list.\n"
       "APPEND will append elements to the list.\n"
+      "CONTAINS will return TRUE if the element specified is in the list.\n"
       "INSERT will insert elements to the list to the specified location.\n"
       "When specifying an index, negative value corresponds to index from the"
       " end of the list.\n"
       "REMOVE_AT and REMOVE_ITEM will remove items from the list. The "
       "difference is that REMOVE_ITEM will remove the given items, while "
       "REMOVE_AT will remove the items at the given indices.\n"
+      "REVERSE reverses the contents of the list in-place.\n"
+      "SORT sorts the list in-place alphabetically.\n"
       ;
     }
 
@@ -90,6 +94,7 @@
   bool HandleLengthCommand(std::vector<std::string> const& args);
   bool HandleGetCommand(std::vector<std::string> const& args);
   bool HandleAppendCommand(std::vector<std::string> const& args);
+  bool HandleContainsCommand(std::vector<std::string> const& args);
   bool HandleInsertCommand(std::vector<std::string> const& args);
   bool HandleRemoveAtCommand(std::vector<std::string> const& args);
   bool HandleRemoveItemCommand(std::vector<std::string> const& args);



More information about the Cmake-commits mailing list