[cmake-commits] hoffman committed cmListCommand.cxx 1.4.2.5 1.4.2.6 cmListCommand.h 1.2.2.5 1.2.2.6

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Dec 19 10:43:46 EST 2007


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

Modified Files:
      Tag: CMake-2-4
	cmListCommand.cxx cmListCommand.h 
Log Message:
ENH: merge in list find to support Findqt


Index: cmListCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.cxx,v
retrieving revision 1.4.2.5
retrieving revision 1.4.2.6
diff -u -d -r1.4.2.5 -r1.4.2.6
--- cmListCommand.cxx	13 Oct 2006 14:52:02 -0000	1.4.2.5
+++ cmListCommand.cxx	19 Dec 2007 15:43:44 -0000	1.4.2.6
@@ -42,6 +42,10 @@
     {
     return this->HandleAppendCommand(args);
     }
+  if(subCommand == "FIND")
+    {
+    return this->HandleFindCommand(args);
+    }
   if(subCommand == "INSERT")
     {
     return this->HandleInsertCommand(args);
@@ -200,6 +204,43 @@
 }
 
 //----------------------------------------------------------------------------
+bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
+{
+  if(args.size() != 4)
+    {
+    this->SetError("sub-command FIND 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(), "-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] )
+      {
+      char indexString[32];
+      sprintf(indexString, "%d", index);
+      this->Makefile->AddDefinition(variableName.c_str(), indexString);
+      return true;
+      }
+    index++;
+    }
+
+  this->Makefile->AddDefinition(variableName.c_str(), "-1");
+  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.2.2.5
retrieving revision 1.2.2.6
diff -u -d -r1.2.2.5 -r1.2.2.6
--- cmListCommand.h	28 May 2007 14:07:04 -0000	1.2.2.5
+++ cmListCommand.h	19 Dec 2007 15:43:44 -0000	1.2.2.6
@@ -68,6 +68,7 @@
       "  LIST(GET <list> <element index> [<element index> ...] "
       "<output variable>)\n"
       "  LIST(APPEND <list> <element> [<element> ...])\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"
@@ -76,6 +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"
+      "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"
@@ -90,6 +93,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 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