diff options
author | Sebastien Barre <sebastien.barre@kitware.com> | 2008-03-12 21:02:10 (GMT) |
---|---|---|
committer | Sebastien Barre <sebastien.barre@kitware.com> | 2008-03-12 21:02:10 (GMT) |
commit | f64d3d0b77bfa41d64cf86e1b60e499eba7a813c (patch) | |
tree | 72a30a61f9b6d9325164272a170a6664e52ef420 /Source/cmListCommand.cxx | |
parent | 2ad4f4bb9de4bb5ec85099ec993795d221f8b974 (diff) | |
download | CMake-f64d3d0b77bfa41d64cf86e1b60e499eba7a813c.zip CMake-f64d3d0b77bfa41d64cf86e1b60e499eba7a813c.tar.gz CMake-f64d3d0b77bfa41d64cf86e1b60e499eba7a813c.tar.bz2 |
ENH: add REMOVE_DUPLICATES subcommand to LIST command (and test). Remove duplicates from a list (keep the ordering)
Diffstat (limited to 'Source/cmListCommand.cxx')
-rw-r--r-- | Source/cmListCommand.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index f990ad5..2b7e3f4 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -59,6 +59,10 @@ bool cmListCommand { return this->HandleRemoveItemCommand(args); } + if(subCommand == "REMOVE_DUPLICATES") + { + return this->HandleRemoveDuplicatesCommand(args); + } if(subCommand == "SORT") { return this->HandleSortCommand(args); @@ -394,6 +398,68 @@ bool cmListCommand //---------------------------------------------------------------------------- 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) { if(args.size() < 2) |