[cmake-commits] alex committed cmListCommand.h 1.9 1.10 cmListCommand.cxx 1.14 1.15

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Aug 15 10:26:52 EDT 2007


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

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

ENH: change LIST(CONTAINS ...) TO LIST(FIND ...), which returns the index
and which is more useful, because then you can also access the item behind
the one you were looking, useful for writing macros with optional keywords
with parameters

Alex


Index: cmListCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.cxx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cmListCommand.cxx	12 Jul 2007 15:56:45 -0000	1.14
+++ cmListCommand.cxx	15 Aug 2007 14:26:50 -0000	1.15
@@ -42,9 +42,9 @@
     {
     return this->HandleAppendCommand(args);
     }
-  if(subCommand == "CONTAINS")
+  if(subCommand == "FIND")
     {
-    return this->HandleContainsCommand(args);
+    return this->HandleFindCommand(args);
     }
   if(subCommand == "INSERT")
     {
@@ -204,11 +204,11 @@
 }
 
 //----------------------------------------------------------------------------
-bool cmListCommand::HandleContainsCommand(std::vector<std::string> const& args)
+bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
 {
   if(args.size() != 4)
     {
-    this->SetError("sub-command CONTAINS requires three arguments.");
+    this->SetError("sub-command FIND requires three arguments.");
     return false;
     }
 
@@ -218,21 +218,25 @@
   std::vector<std::string> varArgsExpanded;
   if ( !this->GetList(varArgsExpanded, listName.c_str()) )
     {
-    this->Makefile->AddDefinition(variableName.c_str(), "FALSE");
+    this->Makefile->AddDefinition(variableName.c_str(), "-1");
     return true;
     }
 
   std::vector<std::string>::iterator it;
+  unsigned int index = 0;
   for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
     {
     if ( *it == args[2] )
       {
-      this->Makefile->AddDefinition(variableName.c_str(), "TRUE");
+      char indexString[32];
+      sprintf(indexString, "%d", index);
+      this->Makefile->AddDefinition(variableName.c_str(), indexString);
       return true;
       }
+    index++;
     }
 
-  this->Makefile->AddDefinition(variableName.c_str(), "FALSE");
+  this->Makefile->AddDefinition(variableName.c_str(), "-1");
   return true;
 }
 

Index: cmListCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- cmListCommand.h	12 Jul 2007 15:56:45 -0000	1.9
+++ cmListCommand.h	15 Aug 2007 14:26:50 -0000	1.10
@@ -68,7 +68,7 @@
       "  LIST(GET <list> <element index> [<element index> ...] "
       "<output variable>)\n"
       "  LIST(APPEND <list> <element> [<element> ...])\n"
-      "  LIST(CONTAINS <list> <value> <output variable>)\n"
+      "  LIST(FIND <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"
@@ -77,7 +77,8 @@
       "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"
+      "FIND will return the index of the element specified in the list or -1 "
+      "if it wasn't found.\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"
@@ -94,7 +95,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 HandleFindCommand(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