[Cmake-commits] [cmake-commits] barre committed cmListCommand.cxx 1.17 1.18 cmListCommand.h 1.14 1.15
cmake-commits at cmake.org
cmake-commits at cmake.org
Wed Mar 12 17:02:12 EDT 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv3656/Source
Modified Files:
cmListCommand.cxx cmListCommand.h
Log Message:
ENH: add REMOVE_DUPLICATES subcommand to LIST command (and test). Remove duplicates from a list (keep the ordering)
Index: cmListCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -C 2 -d -r1.17 -r1.18
*** cmListCommand.cxx 23 Jan 2008 15:27:59 -0000 1.17
--- cmListCommand.cxx 12 Mar 2008 21:02:10 -0000 1.18
***************
*** 60,63 ****
--- 60,67 ----
return this->HandleRemoveItemCommand(args);
}
+ if(subCommand == "REMOVE_DUPLICATES")
+ {
+ return this->HandleRemoveDuplicatesCommand(args);
+ }
if(subCommand == "SORT")
{
***************
*** 395,398 ****
--- 399,464 ----
//----------------------------------------------------------------------------
bool cmListCommand
+ ::HandleRemoveDuplicatesCommand(std::vector<std::string> const& args)
+ {
+ if(args.size() < 2)
+ {
+ this->SetError("sub-command REMOVE_DUPLICATES requires a list as an argument.");
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if ( !this->GetList(varArgsExpanded, listName.c_str()) )
+ {
+ this->SetError("sub-command REMOVE_DUPLICATES requires list to be present.");
+ return false;
+ }
+
+ std::string value;
+
+ #if 0
+ // Fast version, but does not keep the ordering
+
+ std::set<std::string> unique(varArgsExpanded.begin(), varArgsExpanded.end());
+ std::set<std::string>::iterator it;
+ for ( it = unique.begin(); it != unique.end(); ++ it )
+ {
+ if (value.size())
+ {
+ value += ";";
+ }
+ value += it->c_str();
+ }
+
+ #else
+
+ // Slower version, keep the ordering
+
+ std::set<std::string> unique;
+ std::vector<std::string>::iterator it;
+ for ( it = varArgsExpanded.begin(); it != varArgsExpanded.end(); ++ it )
+ {
+ if (unique.find(*it) != unique.end())
+ {
+ continue;
+ }
+ unique.insert(*it);
+
+ if (value.size())
+ {
+ value += ";";
+ }
+ value += it->c_str();
+ }
+ #endif
+
+
+ this->Makefile->AddDefinition(listName.c_str(), value.c_str());
+ return true;
+ }
+
+ //----------------------------------------------------------------------------
+ bool cmListCommand
::HandleSortCommand(std::vector<std::string> const& args)
{
Index: cmListCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmListCommand.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C 2 -d -r1.14 -r1.15
*** cmListCommand.h 23 Jan 2008 15:27:59 -0000 1.14
--- cmListCommand.h 12 Mar 2008 21:02:10 -0000 1.15
***************
*** 74,77 ****
--- 74,78 ----
" list(REMOVE_ITEM <list> <value> [<value> ...])\n"
" list(REMOVE_AT <list> <index> [<index> ...])\n"
+ " list(REMOVE_DUPLICATES <list>)\n"
" list(REVERSE <list>)\n"
" list(SORT <list>)\n"
***************
*** 85,88 ****
--- 86,90 ----
"difference is that REMOVE_ITEM will remove the given items, while "
"REMOVE_AT will remove the items at the given indices.\n"
+ "REMOVE_DUPLICATES will remove duplicated items in the list.\n"
"REVERSE reverses the contents of the list in-place.\n"
"SORT sorts the list in-place alphabetically.\n"
***************
*** 111,114 ****
--- 113,117 ----
bool HandleRemoveAtCommand(std::vector<std::string> const& args);
bool HandleRemoveItemCommand(std::vector<std::string> const& args);
+ bool HandleRemoveDuplicatesCommand(std::vector<std::string> const& args);
bool HandleSortCommand(std::vector<std::string> const& args);
bool HandleReverseCommand(std::vector<std::string> const& args);
More information about the Cmake-commits
mailing list