Merge topic 'use-cmRange'

7c3f6376 Convert loop into two algorithms.
8a399c8c Convert loop to the common pattern.
abfca975 Move loop inside of condition.
0b61b86d Handle last element outside of the loop.
e21f7829 cmTarget: Use a sorted vector in place of a set.
559dc155 cmSet: Replace loop with cmJoin.
0ea71932 cmFindBase: Replace loop with cmJoin on range.
9380e85f Convert loops to cmJoin algorithm with cmRange.
bb10012f cmStringCommand: Accumulate with cmJoin and range adaptors.
0c12f1ea cmAlgorithms: Add a range adaptor and API for adjusting a range.
27c6f017 Use cmJoin to accumulate string ranges.
4e78ebbd cmAlgorithms: Add a Range container and adaptor method.
89102249 Replace common loop pattern with cmJoin
7b8725bf Convert loops populating maybe-empty content into the common pattern.
7ee56f03 Convert loops into the commonly used pattern.
0a4e5674 cmMacroCommand: Remove counting variable.
...
This commit is contained in:
Brad King 2015-02-12 11:53:04 -05:00 committed by CMake Topic Stage
commit e6ae3c6ae0
27 changed files with 274 additions and 350 deletions

View File

@ -46,6 +46,7 @@
#endif #endif
#include "cmCPackLog.h" #include "cmCPackLog.h"
#include "cmAlgorithms.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -13,6 +13,7 @@
#include "cmCTest.h" #include "cmCTest.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmAlgorithms.h"
#include "cmXMLSafe.h" #include "cmXMLSafe.h"
#include <cmsys/RegularExpression.hxx> #include <cmsys/RegularExpression.hxx>

191
Source/cmAlgorithms.h Normal file
View File

@ -0,0 +1,191 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2015 Stephen Kelly <steveire@gmail.com>
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef cmAlgorithms_h
#define cmAlgorithms_h
#include "cmStandardIncludes.h"
inline bool cmHasLiteralPrefixImpl(const std::string &str1,
const char *str2,
size_t N)
{
return strncmp(str1.c_str(), str2, N) == 0;
}
inline bool cmHasLiteralPrefixImpl(const char* str1,
const char *str2,
size_t N)
{
return strncmp(str1, str2, N) == 0;
}
inline bool cmHasLiteralSuffixImpl(const std::string &str1,
const char *str2,
size_t N)
{
size_t len = str1.size();
return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
}
inline bool cmHasLiteralSuffixImpl(const char* str1,
const char* str2,
size_t N)
{
size_t len = strlen(str1);
return len >= N && strcmp(str1 + len - N, str2) == 0;
}
template<typename T, size_t N>
const T* cmArrayBegin(const T (&a)[N]) { return a; }
template<typename T, size_t N>
const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
template<typename T, size_t N>
size_t cmArraySize(const T (&)[N]) { return N; }
template<typename T, size_t N>
bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
{
return cmHasLiteralPrefixImpl(str1, str2, N - 1);
}
template<typename T, size_t N>
bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
{
return cmHasLiteralSuffixImpl(str1, str2, N - 1);
}
struct cmStrCmp {
cmStrCmp(const char *test) : m_test(test) {}
cmStrCmp(const std::string &test) : m_test(test) {}
bool operator()(const std::string& input) const
{
return m_test == input;
}
bool operator()(const char * input) const
{
return strcmp(input, m_test.c_str()) == 0;
}
private:
const std::string m_test;
};
namespace ContainerAlgorithms {
template<typename T>
struct cmIsPair
{
enum { value = false };
};
template<typename K, typename V>
struct cmIsPair<std::pair<K, V> >
{
enum { value = true };
};
template<typename Container,
bool valueTypeIsPair = cmIsPair<typename Container::value_type>::value>
struct DefaultDeleter
{
void operator()(typename Container::value_type value) {
delete value;
}
};
template<typename Container>
struct DefaultDeleter<Container, /* valueTypeIsPair = */ true>
{
void operator()(typename Container::value_type value) {
delete value.second;
}
};
template<typename const_iterator_>
struct Range
{
typedef const_iterator_ const_iterator;
typedef typename std::iterator_traits<const_iterator>::value_type value_type;
Range(const_iterator begin_, const_iterator end_)
: Begin(begin_), End(end_) {}
const_iterator begin() const { return Begin; }
const_iterator end() const { return End; }
bool empty() const { return std::distance(Begin, End) == 0; }
Range& advance(cmIML_INT_intptr_t amount)
{
std::advance(Begin, amount);
return *this;
}
Range& retreat(cmIML_INT_intptr_t amount)
{
std::advance(End, -amount);
return *this;
}
private:
const_iterator Begin;
const_iterator End;
};
}
template<typename Iter1, typename Iter2>
ContainerAlgorithms::Range<Iter1> cmRange(Iter1 begin, Iter2 end)
{
return ContainerAlgorithms::Range<Iter1>(begin, end);
}
template<typename Range>
ContainerAlgorithms::Range<typename Range::const_iterator>
cmRange(Range const& range)
{
return ContainerAlgorithms::Range<typename Range::const_iterator>(
range.begin(), range.end());
}
template<typename Container>
void cmDeleteAll(Container const& c)
{
std::for_each(c.begin(), c.end(),
ContainerAlgorithms::DefaultDeleter<Container>());
}
template<typename Range>
std::string cmJoin(Range const& r, const char* delimiter)
{
if (r.empty())
{
return std::string();
}
std::ostringstream os;
typedef typename Range::value_type ValueType;
typedef typename Range::const_iterator InputIt;
InputIt first = r.begin();
InputIt last = r.end();
--last;
std::copy(first, last,
std::ostream_iterator<ValueType>(os, delimiter));
os << *last;
return os.str();
}
template<typename Range>
std::string cmJoin(Range const& r, std::string delimiter)
{
return cmJoin(r, delimiter.c_str());
};
#endif

View File

@ -12,6 +12,7 @@
#include "cmExportSet.h" #include "cmExportSet.h"
#include "cmTargetExport.h" #include "cmTargetExport.h"
#include "cmAlgorithms.h"
cmExportSet::~cmExportSet() cmExportSet::~cmExportSet()
{ {

View File

@ -12,6 +12,7 @@
#include "cmExportSetMap.h" #include "cmExportSetMap.h"
#include "cmExportSet.h" #include "cmExportSet.h"
#include "cmAlgorithms.h"
cmExportSet* cmExportSetMap::operator[](const std::string &name) cmExportSet* cmExportSetMap::operator[](const std::string &name)
{ {

View File

@ -217,7 +217,6 @@ bool cmFileCommand
bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args, bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
bool append) bool append)
{ {
std::string message;
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();
i++; // Get rid of subcommand i++; // Get rid of subcommand
@ -231,10 +230,6 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
i++; i++;
for(;i != args.end(); ++i)
{
message += *i;
}
if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) ) if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
{ {
std::string e std::string e
@ -272,6 +267,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
this->SetError(error); this->SetError(error);
return false; return false;
} }
std::string message = cmJoin(cmRange(i, args.end()), std::string());
file << message; file << message;
file.close(); file.close();
if(mode) if(mode)

View File

@ -16,6 +16,7 @@
#include "cmFileLock.h" #include "cmFileLock.h"
#include "cmFileLockResult.h" #include "cmFileLockResult.h"
#include "cmAlgorithms.h"
cmFileLockPool::cmFileLockPool() cmFileLockPool::cmFileLockPool()
{ {

View File

@ -166,11 +166,9 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
} }
else else
{ {
this->VariableDocumentation += "one of the " + this->Names[0]; this->VariableDocumentation += "one of the ";
for (unsigned int j = 1; j < this->Names.size() - 1; ++j) this->VariableDocumentation += cmJoin(cmRange(this->Names).retreat(1),
{ ", ");
this->VariableDocumentation += ", " + this->Names[j];
}
this->VariableDocumentation += " or " this->VariableDocumentation += " or "
+ this->Names[this->Names.size() - 1] + " libraries be found"; + this->Names[this->Names.size() - 1] + " libraries be found";
} }

View File

@ -1064,26 +1064,11 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found)
} }
std::string tmp; std::string tmp = cmJoin(foundContents, ";");
const char* sep ="";
for(size_t i=0; i<foundContents.size(); i++)
{
tmp += sep;
tmp += foundContents[i];
sep = ";";
}
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND", this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND",
tmp.c_str()); tmp.c_str());
tmp = ""; tmp = cmJoin(notFoundContents, ";");
sep = "";
for(size_t i=0; i<notFoundContents.size(); i++)
{
tmp += sep;
tmp += notFoundContents[i];
sep = ";";
}
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND", this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
tmp.c_str()); tmp.c_str());
} }

View File

@ -193,12 +193,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
if (!this->Depth) if (!this->Depth)
{ {
std::string name = this->Args[0]; std::string name = this->Args[0];
std::vector<std::string>::size_type cc; name += "( ";
name += "("; name += cmJoin(this->Args, " ");
for ( cc = 0; cc < this->Args.size(); cc ++ )
{
name += " " + this->Args[cc];
}
name += " )"; name += " )";
// create a new command and add it to cmake // create a new command and add it to cmake

View File

@ -25,7 +25,6 @@ bool cmGetCMakePropertyCommand
return false; return false;
} }
std::vector<std::string>::size_type cc;
std::string variable = args[0]; std::string variable = args[0];
std::string output = "NOTFOUND"; std::string output = "NOTFOUND";
@ -35,12 +34,7 @@ bool cmGetCMakePropertyCommand
std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly); std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
if (!vars.empty()) if (!vars.empty())
{ {
output = vars[0]; output = cmJoin(vars, ";");
}
for ( cc = 1; cc < vars.size(); ++cc )
{
output += ";";
output += vars[cc];
} }
} }
else if ( args[1] == "MACROS" ) else if ( args[1] == "MACROS" )
@ -52,16 +46,7 @@ bool cmGetCMakePropertyCommand
const std::set<std::string>* components const std::set<std::string>* components
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator() = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
->GetInstallComponents(); ->GetInstallComponents();
std::set<std::string>::const_iterator compIt; output = cmJoin(*components, ";");
output = "";
for (compIt = components->begin(); compIt != components->end(); ++compIt)
{
if (compIt != components->begin())
{
output += ";";
}
output += *compIt;
}
} }
else else
{ {

View File

@ -13,6 +13,7 @@
#define cmInstalledFile_h #define cmInstalledFile_h
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
#include "cmAlgorithms.h"
/** \class cmInstalledFile /** \class cmInstalledFile
* \brief Represents a file intended for installation. * \brief Represents a file intended for installation.

View File

@ -254,15 +254,12 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
// expand the variable // expand the variable
std::string listString; std::string listString;
this->GetListString(listString, listName); this->GetListString(listString, listName);
size_t cc;
for ( cc = 2; cc < args.size(); ++ cc ) if(!listString.empty() && !args.empty())
{ {
if(!listString.empty()) listString += ";";
{
listString += ";";
}
listString += args[cc];
} }
listString += cmJoin(cmRange(args).advance(2), ";");
this->Makefile->AddDefinition(listName, listString.c_str()); this->Makefile->AddDefinition(listName, listString.c_str());
return true; return true;

View File

@ -3011,14 +3011,12 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
// trailing slash in the input then the last iteration of the loop // trailing slash in the input then the last iteration of the loop
// will add a slash followed by an empty string which will preserve // will add a slash followed by an empty string which will preserve
// the trailing slash in the output. // the trailing slash in the output.
for(unsigned int i=common; i < remote.size(); ++i)
if(!relative.empty() && !remote.empty())
{ {
if(!relative.empty()) relative += "/";
{
relative += "/";
}
relative += remote[i];
} }
relative += cmJoin(cmRange(remote).advance(common), "/");
// Finally return the path. // Finally return the path.
return relative; return relative;

View File

@ -2295,21 +2295,19 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p,
// Begin the quoted result with the root component. // Begin the quoted result with the root component.
result += components[0]; result += components[0];
// Now add the rest of the components separated by the proper slash if (components.size() > 1)
// direction for this platform.
bool first = true;
for(unsigned int i=1; i < components.size(); ++i)
{ {
// Now add the rest of the components separated by the proper slash
// direction for this platform.
std::vector<std::string>::const_iterator compEnd
= std::remove(components.begin() + 1, components.end() - 1,
std::string());
std::vector<std::string>::const_iterator compStart
= components.begin() + 1;
result += cmJoin(cmRange(compStart, compEnd), slash);
// Only the last component can be empty to avoid double slashes. // Only the last component can be empty to avoid double slashes.
if(!components[i].empty() || (i == (components.size()-1))) result += slash;
{ result += components.back();
if(!first)
{
result += slash;
}
result += components[i];
first = false;
}
} }
} }

View File

@ -164,19 +164,15 @@ bool cmMacroHelperCommand::InvokeInitialPass
{ {
if (!argnDefInitialized) if (!argnDefInitialized)
{ {
std::vector<std::string>::const_iterator eit; if (expandedArgs.size() > this->Args.size() - 1)
std::vector<std::string>::size_type cnt = 0;
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
{ {
if ( cnt >= this->Args.size()-1 ) if (!argnDef.empty() && !expandedArgs.empty())
{ {
if (!argnDef.empty()) argnDef += ";";
{
argnDef += ";";
}
argnDef += *eit;
} }
cnt ++; std::vector<std::string>::const_iterator eit
= expandedArgs.begin() + (this->Args.size() - 1);
argnDef += cmJoin(cmRange(eit, expandedArgs.end()), ";");
} }
argnDefInitialized = true; argnDefInitialized = true;
} }
@ -192,15 +188,11 @@ bool cmMacroHelperCommand::InvokeInitialPass
// repleace ARGV, compute it only once // repleace ARGV, compute it only once
if (!argvDefInitialized) if (!argvDefInitialized)
{ {
std::vector<std::string>::const_iterator eit; if (!argvDef.empty() && !expandedArgs.empty())
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
{ {
if (!argvDef.empty()) argvDef += ";";
{
argvDef += ";";
}
argvDef += *eit;
} }
argvDef += cmJoin(expandedArgs, ";");
argvDefInitialized = true; argvDefInitialized = true;
} }
cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str()); cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
@ -262,11 +254,11 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
if (!this->Depth) if (!this->Depth)
{ {
std::string name = this->Args[0]; std::string name = this->Args[0];
std::vector<std::string>::size_type cc;
name += "("; name += "(";
for ( cc = 0; cc < this->Args.size(); cc ++ ) if (!this->Args.empty())
{ {
name += " " + this->Args[cc]; name += " ";
name += cmJoin(this->Args, " ");
} }
name += " )"; name += " )";
mf.AddMacro(this->Args[0].c_str(), name.c_str()); mf.AddMacro(this->Args[0].c_str(), name.c_str());

View File

@ -3752,15 +3752,12 @@ void cmMakefile::GetListOfMacros(std::string& macros) const
{ {
StringStringMap::const_iterator it; StringStringMap::const_iterator it;
macros = ""; macros = "";
int cc = 0; const char* sep = "";
for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it ) for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it )
{ {
if ( cc > 0 ) macros += sep;
{
macros += ";";
}
macros += it->first; macros += it->first;
cc ++; sep = "";
} }
} }
@ -4205,16 +4202,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
} }
else if (prop == "LISTFILE_STACK") else if (prop == "LISTFILE_STACK")
{ {
for (std::deque<std::string>::const_iterator output = cmJoin(this->ListFileStack, ";");
i = this->ListFileStack.begin();
i != this->ListFileStack.end(); ++i)
{
if (i != this->ListFileStack.begin())
{
output += ";";
}
output += *i;
}
return output.c_str(); return output.c_str();
} }
else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES") else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES")
@ -4224,15 +4212,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
{ {
cacheonly = 1; cacheonly = 1;
} }
std::vector<std::string> vars = this->GetDefinitions(cacheonly); output = cmJoin(this->GetDefinitions(cacheonly), ";");
for (unsigned int cc = 0; cc < vars.size(); cc ++ )
{
if ( cc > 0 )
{
output += ";";
}
output += vars[cc];
}
return output.c_str(); return output.c_str();
} }
else if (prop == "MACROS") else if (prop == "MACROS")
@ -4247,19 +4227,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
} }
else if (prop == "LINK_DIRECTORIES") else if (prop == "LINK_DIRECTORIES")
{ {
std::ostringstream str; output = cmJoin(this->GetLinkDirectories(), ";");
for (std::vector<std::string>::const_iterator
it = this->GetLinkDirectories().begin();
it != this->GetLinkDirectories().end();
++ it )
{
if ( it != this->GetLinkDirectories().begin())
{
str << ";";
}
str << it->c_str();
}
output = str.str();
return output.c_str(); return output.c_str();
} }
else if (prop == "INCLUDE_DIRECTORIES") else if (prop == "INCLUDE_DIRECTORIES")

View File

@ -20,7 +20,6 @@ bool cmMessageCommand
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
std::string message;
std::vector<std::string>::const_iterator i = args.begin(); std::vector<std::string>::const_iterator i = args.begin();
cmake::MessageType type = cmake::MESSAGE; cmake::MessageType type = cmake::MESSAGE;
@ -70,10 +69,7 @@ bool cmMessageCommand
++i; ++i;
} }
for(;i != args.end(); ++i) std::string message = cmJoin(cmRange(i, args.end()), std::string());
{
message += *i;
}
if (type != cmake::MESSAGE) if (type != cmake::MESSAGE)
{ {

View File

@ -34,11 +34,7 @@ bool cmOptionCommand
if(argError) if(argError)
{ {
std::string m = "called with incorrect number of arguments: "; std::string m = "called with incorrect number of arguments: ";
for(size_t i =0; i < args.size(); ++i) m += cmJoin(args, " ");
{
m += args[i];
m += " ";
}
this->SetError(m); this->SetError(m);
return false; return false;
} }

View File

@ -12,6 +12,7 @@
#include "cmRST.h" #include "cmRST.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmAlgorithms.h"
#include "cmVersion.h" #include "cmVersion.h"
#include <cmsys/FStream.hxx> #include <cmsys/FStream.hxx>
#include <ctype.h> #include <ctype.h>

View File

@ -108,17 +108,7 @@ bool cmSetCommand
} }
// collect any values into a single semi-colon separated value list // collect any values into a single semi-colon separated value list
if(static_cast<unsigned short>(args.size()) > value = cmJoin(cmRange(args).advance(1).retreat(ignoreLastArgs), ";");
static_cast<unsigned short>(1 + ignoreLastArgs))
{
value = args[1];
size_t endPos = args.size() - ignoreLastArgs;
for(size_t i = 2; i < endPos; ++i)
{
value += ";";
value += args[i];
}
}
if (parentScope) if (parentScope)
{ {

View File

@ -131,138 +131,4 @@ static thisClass* SafeDownCast(cmObject *c) \
} \ } \
class cmTypeMacro_UseTrailingSemicolon class cmTypeMacro_UseTrailingSemicolon
template<typename Range>
std::string cmJoin(Range const& r, const char* delimiter)
{
if (r.empty())
{
return std::string();
}
std::ostringstream os;
typedef typename Range::value_type ValueType;
typedef typename Range::const_iterator InputIt;
InputIt first = r.begin();
InputIt last = r.end();
--last;
std::copy(first, last,
std::ostream_iterator<ValueType>(os, delimiter));
os << *last;
return os.str();
}
template<typename Range>
std::string cmJoin(Range const& r, std::string delimiter)
{
return cmJoin(r, delimiter.c_str());
};
inline bool cmHasLiteralPrefixImpl(const std::string &str1,
const char *str2,
size_t N)
{
return strncmp(str1.c_str(), str2, N) == 0;
}
inline bool cmHasLiteralPrefixImpl(const char* str1,
const char *str2,
size_t N)
{
return strncmp(str1, str2, N) == 0;
}
inline bool cmHasLiteralSuffixImpl(const std::string &str1,
const char *str2,
size_t N)
{
size_t len = str1.size();
return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
}
inline bool cmHasLiteralSuffixImpl(const char* str1,
const char* str2,
size_t N)
{
size_t len = strlen(str1);
return len >= N && strcmp(str1 + len - N, str2) == 0;
}
template<typename T, size_t N>
const T* cmArrayBegin(const T (&a)[N]) { return a; }
template<typename T, size_t N>
const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
template<typename T, size_t N>
size_t cmArraySize(const T (&)[N]) { return N; }
template<typename T, size_t N>
bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
{
return cmHasLiteralPrefixImpl(str1, str2, N - 1);
}
template<typename T, size_t N>
bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
{
return cmHasLiteralSuffixImpl(str1, str2, N - 1);
}
struct cmStrCmp {
cmStrCmp(const char *test) : m_test(test) {}
cmStrCmp(const std::string &test) : m_test(test) {}
bool operator()(const std::string& input) const
{
return m_test == input;
}
bool operator()(const char * input) const
{
return strcmp(input, m_test.c_str()) == 0;
}
private:
const std::string m_test;
};
namespace ContainerAlgorithms {
template<typename T>
struct cmIsPair
{
enum { value = false };
};
template<typename K, typename V>
struct cmIsPair<std::pair<K, V> >
{
enum { value = true };
};
template<typename Container,
bool valueTypeIsPair = cmIsPair<typename Container::value_type>::value>
struct DefaultDeleter
{
void operator()(typename Container::value_type value) {
delete value;
}
};
template<typename Container>
struct DefaultDeleter<Container, /* valueTypeIsPair = */ true>
{
void operator()(typename Container::value_type value) {
delete value.second;
}
};
}
template<typename Container>
void cmDeleteAll(Container const& c)
{
std::for_each(c.begin(), c.end(),
ContainerAlgorithms::DefaultDeleter<Container>());
}
#endif #endif

View File

@ -303,13 +303,6 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
std::string regex = args[2]; std::string regex = args[2];
std::string outvar = args[3]; std::string outvar = args[3];
// Concatenate all the last arguments together.
std::string input = args[4];
for(unsigned int i=5; i < args.size(); ++i)
{
input += args[i];
}
this->Makefile->ClearMatches(); this->Makefile->ClearMatches();
// Compile the regular expression. // Compile the regular expression.
cmsys::RegularExpression re; cmsys::RegularExpression re;
@ -321,6 +314,9 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
return false; return false;
} }
// Concatenate all the last arguments together.
std::string input = cmJoin(cmRange(args).advance(4), std::string());
// Scan through the input for all matches. // Scan through the input for all matches.
std::string output; std::string output;
if(re.find(input.c_str())) if(re.find(input.c_str()))
@ -352,13 +348,6 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
std::string regex = args[2]; std::string regex = args[2];
std::string outvar = args[3]; std::string outvar = args[3];
// Concatenate all the last arguments together.
std::string input = args[4];
for(unsigned int i=5; i < args.size(); ++i)
{
input += args[i];
}
this->Makefile->ClearMatches(); this->Makefile->ClearMatches();
// Compile the regular expression. // Compile the regular expression.
cmsys::RegularExpression re; cmsys::RegularExpression re;
@ -371,6 +360,9 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
return false; return false;
} }
// Concatenate all the last arguments together.
std::string input = cmJoin(cmRange(args).advance(4), std::string());
// Scan through the input for all matches. // Scan through the input for all matches.
std::string output; std::string output;
const char* p = input.c_str(); const char* p = input.c_str();
@ -456,13 +448,6 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
l = r; l = r;
} }
// Concatenate all the last arguments together.
std::string input = args[5];
for(unsigned int i=6; i < args.size(); ++i)
{
input += args[i];
}
this->Makefile->ClearMatches(); this->Makefile->ClearMatches();
// Compile the regular expression. // Compile the regular expression.
cmsys::RegularExpression re; cmsys::RegularExpression re;
@ -475,6 +460,9 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
return false; return false;
} }
// Concatenate all the last arguments together.
std::string input = cmJoin(cmRange(args).advance(5), std::string());
// Scan through the input for all matches. // Scan through the input for all matches.
std::string output; std::string output;
std::string::size_type base = 0; std::string::size_type base = 0;
@ -673,11 +661,7 @@ bool cmStringCommand::HandleReplaceCommand(std::vector<std::string> const&
const std::string& replaceExpression = args[2]; const std::string& replaceExpression = args[2];
const std::string& variableName = args[3]; const std::string& variableName = args[3];
std::string input = args[4]; std::string input = cmJoin(cmRange(args).advance(4), std::string());
for(unsigned int i=5; i < args.size(); ++i)
{
input += args[i];
}
cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(), cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(),
replaceExpression.c_str()); replaceExpression.c_str());
@ -756,11 +740,7 @@ bool cmStringCommand
} }
std::string const& variableName = args[1]; std::string const& variableName = args[1];
std::string value; std::string value = cmJoin(cmRange(args).advance(2), std::string());
for(unsigned int i = 2; i < args.size(); ++i)
{
value += args[i];
}
this->Makefile->AddDefinition(variableName, value.c_str()); this->Makefile->AddDefinition(variableName, value.c_str());
return true; return true;

View File

@ -11,6 +11,7 @@
============================================================================*/ ============================================================================*/
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmAlgorithms.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>

View File

@ -6687,40 +6687,33 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
if (!prop.empty()) if (!prop.empty())
{ {
// Use a std::set to keep the error message sorted. // Use a sorted std::vector to keep the error message sorted.
std::set<std::string> props; std::vector<std::string> props;
std::set<std::string>::const_iterator i = emittedBools.find(prop); std::set<std::string>::const_iterator i = emittedBools.find(prop);
if (i != emittedBools.end()) if (i != emittedBools.end())
{ {
props.insert(strBool); props.push_back(strBool);
} }
i = emittedStrings.find(prop); i = emittedStrings.find(prop);
if (i != emittedStrings.end()) if (i != emittedStrings.end())
{ {
props.insert(strString); props.push_back(strString);
} }
i = emittedMinNumbers.find(prop); i = emittedMinNumbers.find(prop);
if (i != emittedMinNumbers.end()) if (i != emittedMinNumbers.end())
{ {
props.insert(strNumMin); props.push_back(strNumMin);
} }
i = emittedMaxNumbers.find(prop); i = emittedMaxNumbers.find(prop);
if (i != emittedMaxNumbers.end()) if (i != emittedMaxNumbers.end())
{ {
props.insert(strNumMax); props.push_back(strNumMax);
} }
std::sort(props.begin(), props.end());
std::string propsString = cmJoin(cmRange(props).retreat(1), ", ");
propsString += " and the " + props.back();
std::string propsString = *props.begin();
props.erase(props.begin());
while (props.size() > 1)
{
propsString += ", " + *props.begin();
props.erase(props.begin());
}
if (props.size() == 1)
{
propsString += " and the " + *props.begin();
}
std::ostringstream e; std::ostringstream e;
e << "Property \"" << prop << "\" appears in both the " e << "Property \"" << prop << "\" appears in both the "
<< propsString << << propsString <<

View File

@ -11,6 +11,8 @@
============================================================================*/ ============================================================================*/
#include "cmVariableWatch.h" #include "cmVariableWatch.h"
#include "cmAlgorithms.h"
static const char* const cmVariableWatchAccessStrings[] = static const char* const cmVariableWatchAccessStrings[] =
{ {
"READ_ACCESS", "READ_ACCESS",

View File

@ -406,12 +406,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Clock command // Clock command
else if (args[1] == "time" && args.size() > 2) else if (args[1] == "time" && args.size() > 2)
{ {
std::string command = args[2]; std::string command = cmJoin(cmRange(args).advance(2), " ");
for (std::string::size_type cc = 3; cc < args.size(); cc ++)
{
command += " ";
command += args[cc];
}
clock_t clock_start, clock_finish; clock_t clock_start, clock_finish;
time_t time_start, time_finish; time_t time_start, time_finish;
@ -473,14 +468,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
} }
std::string command = "\""; std::string command = "\"";
command += args[3]; command += cmJoin(cmRange(args).advance(3), "\" \"");
command += "\""; command += "\"";
for (std::string::size_type cc = 4; cc < args.size(); cc ++)
{
command += " \"";
command += args[cc];
command += "\"";
}
int retval = 0; int retval = 0;
int timeout = 0; int timeout = 0;
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval, if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,