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:
commit
e6ae3c6ae0
@ -46,6 +46,7 @@
|
||||
#endif
|
||||
|
||||
#include "cmCPackLog.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "cmCTest.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmXMLSafe.h"
|
||||
|
||||
#include <cmsys/RegularExpression.hxx>
|
||||
|
191
Source/cmAlgorithms.h
Normal file
191
Source/cmAlgorithms.h
Normal 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
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "cmExportSet.h"
|
||||
#include "cmTargetExport.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
cmExportSet::~cmExportSet()
|
||||
{
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "cmExportSetMap.h"
|
||||
#include "cmExportSet.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
cmExportSet* cmExportSetMap::operator[](const std::string &name)
|
||||
{
|
||||
|
@ -217,7 +217,6 @@ bool cmFileCommand
|
||||
bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
|
||||
bool append)
|
||||
{
|
||||
std::string message;
|
||||
std::vector<std::string>::const_iterator i = args.begin();
|
||||
|
||||
i++; // Get rid of subcommand
|
||||
@ -231,10 +230,6 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
|
||||
|
||||
i++;
|
||||
|
||||
for(;i != args.end(); ++i)
|
||||
{
|
||||
message += *i;
|
||||
}
|
||||
if ( !this->Makefile->CanIWriteThisFile(fileName.c_str()) )
|
||||
{
|
||||
std::string e
|
||||
@ -272,6 +267,7 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
|
||||
this->SetError(error);
|
||||
return false;
|
||||
}
|
||||
std::string message = cmJoin(cmRange(i, args.end()), std::string());
|
||||
file << message;
|
||||
file.close();
|
||||
if(mode)
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "cmFileLock.h"
|
||||
#include "cmFileLockResult.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
cmFileLockPool::cmFileLockPool()
|
||||
{
|
||||
|
@ -166,11 +166,9 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
||||
}
|
||||
else
|
||||
{
|
||||
this->VariableDocumentation += "one of the " + this->Names[0];
|
||||
for (unsigned int j = 1; j < this->Names.size() - 1; ++j)
|
||||
{
|
||||
this->VariableDocumentation += ", " + this->Names[j];
|
||||
}
|
||||
this->VariableDocumentation += "one of the ";
|
||||
this->VariableDocumentation += cmJoin(cmRange(this->Names).retreat(1),
|
||||
", ");
|
||||
this->VariableDocumentation += " or "
|
||||
+ this->Names[this->Names.size() - 1] + " libraries be found";
|
||||
}
|
||||
|
@ -1064,26 +1064,11 @@ void cmFindPackageCommand::AppendToFoundProperty(bool found)
|
||||
}
|
||||
|
||||
|
||||
std::string tmp;
|
||||
const char* sep ="";
|
||||
for(size_t i=0; i<foundContents.size(); i++)
|
||||
{
|
||||
tmp += sep;
|
||||
tmp += foundContents[i];
|
||||
sep = ";";
|
||||
}
|
||||
|
||||
std::string tmp = cmJoin(foundContents, ";");
|
||||
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_FOUND",
|
||||
tmp.c_str());
|
||||
|
||||
tmp = "";
|
||||
sep = "";
|
||||
for(size_t i=0; i<notFoundContents.size(); i++)
|
||||
{
|
||||
tmp += sep;
|
||||
tmp += notFoundContents[i];
|
||||
sep = ";";
|
||||
}
|
||||
tmp = cmJoin(notFoundContents, ";");
|
||||
this->Makefile->GetCMakeInstance()->SetProperty("PACKAGES_NOT_FOUND",
|
||||
tmp.c_str());
|
||||
}
|
||||
|
@ -193,12 +193,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
|
||||
if (!this->Depth)
|
||||
{
|
||||
std::string name = this->Args[0];
|
||||
std::vector<std::string>::size_type cc;
|
||||
name += "(";
|
||||
for ( cc = 0; cc < this->Args.size(); cc ++ )
|
||||
{
|
||||
name += " " + this->Args[cc];
|
||||
}
|
||||
name += "( ";
|
||||
name += cmJoin(this->Args, " ");
|
||||
name += " )";
|
||||
|
||||
// create a new command and add it to cmake
|
||||
|
@ -25,7 +25,6 @@ bool cmGetCMakePropertyCommand
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string>::size_type cc;
|
||||
std::string variable = args[0];
|
||||
std::string output = "NOTFOUND";
|
||||
|
||||
@ -35,12 +34,7 @@ bool cmGetCMakePropertyCommand
|
||||
std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
|
||||
if (!vars.empty())
|
||||
{
|
||||
output = vars[0];
|
||||
}
|
||||
for ( cc = 1; cc < vars.size(); ++cc )
|
||||
{
|
||||
output += ";";
|
||||
output += vars[cc];
|
||||
output = cmJoin(vars, ";");
|
||||
}
|
||||
}
|
||||
else if ( args[1] == "MACROS" )
|
||||
@ -52,16 +46,7 @@ bool cmGetCMakePropertyCommand
|
||||
const std::set<std::string>* components
|
||||
= this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
|
||||
->GetInstallComponents();
|
||||
std::set<std::string>::const_iterator compIt;
|
||||
output = "";
|
||||
for (compIt = components->begin(); compIt != components->end(); ++compIt)
|
||||
{
|
||||
if (compIt != components->begin())
|
||||
{
|
||||
output += ";";
|
||||
}
|
||||
output += *compIt;
|
||||
}
|
||||
output = cmJoin(*components, ";");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define cmInstalledFile_h
|
||||
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
/** \class cmInstalledFile
|
||||
* \brief Represents a file intended for installation.
|
||||
|
@ -254,15 +254,12 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
|
||||
// expand the variable
|
||||
std::string listString;
|
||||
this->GetListString(listString, listName);
|
||||
size_t cc;
|
||||
for ( cc = 2; cc < args.size(); ++ cc )
|
||||
|
||||
if(!listString.empty() && !args.empty())
|
||||
{
|
||||
if(!listString.empty())
|
||||
{
|
||||
listString += ";";
|
||||
}
|
||||
listString += args[cc];
|
||||
listString += ";";
|
||||
}
|
||||
listString += cmJoin(cmRange(args).advance(2), ";");
|
||||
|
||||
this->Makefile->AddDefinition(listName, listString.c_str());
|
||||
return true;
|
||||
|
@ -3011,14 +3011,12 @@ cmLocalGenerator::ConvertToRelativePath(const std::vector<std::string>& local,
|
||||
// trailing slash in the input then the last iteration of the loop
|
||||
// will add a slash followed by an empty string which will preserve
|
||||
// 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 += remote[i];
|
||||
relative += "/";
|
||||
}
|
||||
relative += cmJoin(cmRange(remote).advance(common), "/");
|
||||
|
||||
// Finally return the path.
|
||||
return relative;
|
||||
|
@ -2295,21 +2295,19 @@ cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(const char* p,
|
||||
// Begin the quoted result with the root component.
|
||||
result += components[0];
|
||||
|
||||
// Now add the rest of the components separated by the proper slash
|
||||
// direction for this platform.
|
||||
bool first = true;
|
||||
for(unsigned int i=1; i < components.size(); ++i)
|
||||
if (components.size() > 1)
|
||||
{
|
||||
// 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.
|
||||
if(!components[i].empty() || (i == (components.size()-1)))
|
||||
{
|
||||
if(!first)
|
||||
{
|
||||
result += slash;
|
||||
}
|
||||
result += components[i];
|
||||
first = false;
|
||||
}
|
||||
result += slash;
|
||||
result += components.back();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,19 +164,15 @@ bool cmMacroHelperCommand::InvokeInitialPass
|
||||
{
|
||||
if (!argnDefInitialized)
|
||||
{
|
||||
std::vector<std::string>::const_iterator eit;
|
||||
std::vector<std::string>::size_type cnt = 0;
|
||||
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
|
||||
if (expandedArgs.size() > this->Args.size() - 1)
|
||||
{
|
||||
if ( cnt >= this->Args.size()-1 )
|
||||
if (!argnDef.empty() && !expandedArgs.empty())
|
||||
{
|
||||
if (!argnDef.empty())
|
||||
{
|
||||
argnDef += ";";
|
||||
}
|
||||
argnDef += *eit;
|
||||
argnDef += ";";
|
||||
}
|
||||
cnt ++;
|
||||
std::vector<std::string>::const_iterator eit
|
||||
= expandedArgs.begin() + (this->Args.size() - 1);
|
||||
argnDef += cmJoin(cmRange(eit, expandedArgs.end()), ";");
|
||||
}
|
||||
argnDefInitialized = true;
|
||||
}
|
||||
@ -192,15 +188,11 @@ bool cmMacroHelperCommand::InvokeInitialPass
|
||||
// repleace ARGV, compute it only once
|
||||
if (!argvDefInitialized)
|
||||
{
|
||||
std::vector<std::string>::const_iterator eit;
|
||||
for(eit = expandedArgs.begin(); eit != expandedArgs.end(); ++eit)
|
||||
if (!argvDef.empty() && !expandedArgs.empty())
|
||||
{
|
||||
if (!argvDef.empty())
|
||||
{
|
||||
argvDef += ";";
|
||||
}
|
||||
argvDef += *eit;
|
||||
argvDef += ";";
|
||||
}
|
||||
argvDef += cmJoin(expandedArgs, ";");
|
||||
argvDefInitialized = true;
|
||||
}
|
||||
cmSystemTools::ReplaceString(tmps, "${ARGV}", argvDef.c_str());
|
||||
@ -262,11 +254,11 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
|
||||
if (!this->Depth)
|
||||
{
|
||||
std::string name = this->Args[0];
|
||||
std::vector<std::string>::size_type cc;
|
||||
name += "(";
|
||||
for ( cc = 0; cc < this->Args.size(); cc ++ )
|
||||
if (!this->Args.empty())
|
||||
{
|
||||
name += " " + this->Args[cc];
|
||||
name += " ";
|
||||
name += cmJoin(this->Args, " ");
|
||||
}
|
||||
name += " )";
|
||||
mf.AddMacro(this->Args[0].c_str(), name.c_str());
|
||||
|
@ -3752,15 +3752,12 @@ void cmMakefile::GetListOfMacros(std::string& macros) const
|
||||
{
|
||||
StringStringMap::const_iterator it;
|
||||
macros = "";
|
||||
int cc = 0;
|
||||
const char* sep = "";
|
||||
for ( it = this->MacrosMap.begin(); it != this->MacrosMap.end(); ++it )
|
||||
{
|
||||
if ( cc > 0 )
|
||||
{
|
||||
macros += ";";
|
||||
}
|
||||
macros += sep;
|
||||
macros += it->first;
|
||||
cc ++;
|
||||
sep = "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -4205,16 +4202,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
|
||||
}
|
||||
else if (prop == "LISTFILE_STACK")
|
||||
{
|
||||
for (std::deque<std::string>::const_iterator
|
||||
i = this->ListFileStack.begin();
|
||||
i != this->ListFileStack.end(); ++i)
|
||||
{
|
||||
if (i != this->ListFileStack.begin())
|
||||
{
|
||||
output += ";";
|
||||
}
|
||||
output += *i;
|
||||
}
|
||||
output = cmJoin(this->ListFileStack, ";");
|
||||
return output.c_str();
|
||||
}
|
||||
else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES")
|
||||
@ -4224,15 +4212,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
|
||||
{
|
||||
cacheonly = 1;
|
||||
}
|
||||
std::vector<std::string> vars = this->GetDefinitions(cacheonly);
|
||||
for (unsigned int cc = 0; cc < vars.size(); cc ++ )
|
||||
{
|
||||
if ( cc > 0 )
|
||||
{
|
||||
output += ";";
|
||||
}
|
||||
output += vars[cc];
|
||||
}
|
||||
output = cmJoin(this->GetDefinitions(cacheonly), ";");
|
||||
return output.c_str();
|
||||
}
|
||||
else if (prop == "MACROS")
|
||||
@ -4247,19 +4227,7 @@ const char *cmMakefile::GetProperty(const std::string& prop,
|
||||
}
|
||||
else if (prop == "LINK_DIRECTORIES")
|
||||
{
|
||||
std::ostringstream str;
|
||||
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();
|
||||
output = cmJoin(this->GetLinkDirectories(), ";");
|
||||
return output.c_str();
|
||||
}
|
||||
else if (prop == "INCLUDE_DIRECTORIES")
|
||||
|
@ -20,7 +20,6 @@ bool cmMessageCommand
|
||||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
std::string message;
|
||||
std::vector<std::string>::const_iterator i = args.begin();
|
||||
|
||||
cmake::MessageType type = cmake::MESSAGE;
|
||||
@ -70,10 +69,7 @@ bool cmMessageCommand
|
||||
++i;
|
||||
}
|
||||
|
||||
for(;i != args.end(); ++i)
|
||||
{
|
||||
message += *i;
|
||||
}
|
||||
std::string message = cmJoin(cmRange(i, args.end()), std::string());
|
||||
|
||||
if (type != cmake::MESSAGE)
|
||||
{
|
||||
|
@ -34,11 +34,7 @@ bool cmOptionCommand
|
||||
if(argError)
|
||||
{
|
||||
std::string m = "called with incorrect number of arguments: ";
|
||||
for(size_t i =0; i < args.size(); ++i)
|
||||
{
|
||||
m += args[i];
|
||||
m += " ";
|
||||
}
|
||||
m += cmJoin(args, " ");
|
||||
this->SetError(m);
|
||||
return false;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "cmRST.h"
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmVersion.h"
|
||||
#include <cmsys/FStream.hxx>
|
||||
#include <ctype.h>
|
||||
|
@ -108,17 +108,7 @@ bool cmSetCommand
|
||||
}
|
||||
|
||||
// collect any values into a single semi-colon separated value list
|
||||
if(static_cast<unsigned short>(args.size()) >
|
||||
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];
|
||||
}
|
||||
}
|
||||
value = cmJoin(cmRange(args).advance(1).retreat(ignoreLastArgs), ";");
|
||||
|
||||
if (parentScope)
|
||||
{
|
||||
|
@ -131,138 +131,4 @@ static thisClass* SafeDownCast(cmObject *c) \
|
||||
} \
|
||||
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
|
||||
|
@ -303,13 +303,6 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
||||
std::string regex = args[2];
|
||||
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();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
@ -321,6 +314,9 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
||||
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.
|
||||
std::string output;
|
||||
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 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();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
@ -371,6 +360,9 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
||||
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.
|
||||
std::string output;
|
||||
const char* p = input.c_str();
|
||||
@ -456,13 +448,6 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
||||
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();
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
@ -475,6 +460,9 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
||||
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.
|
||||
std::string output;
|
||||
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& variableName = args[3];
|
||||
|
||||
std::string input = args[4];
|
||||
for(unsigned int i=5; i < args.size(); ++i)
|
||||
{
|
||||
input += args[i];
|
||||
}
|
||||
std::string input = cmJoin(cmRange(args).advance(4), std::string());
|
||||
|
||||
cmsys::SystemTools::ReplaceString(input, matchExpression.c_str(),
|
||||
replaceExpression.c_str());
|
||||
@ -756,11 +740,7 @@ bool cmStringCommand
|
||||
}
|
||||
|
||||
std::string const& variableName = args[1];
|
||||
std::string value;
|
||||
for(unsigned int i = 2; i < args.size(); ++i)
|
||||
{
|
||||
value += args[i];
|
||||
}
|
||||
std::string value = cmJoin(cmRange(args).advance(2), std::string());
|
||||
|
||||
this->Makefile->AddDefinition(variableName, value.c_str());
|
||||
return true;
|
||||
|
@ -11,6 +11,7 @@
|
||||
============================================================================*/
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
@ -6687,40 +6687,33 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
|
||||
|
||||
if (!prop.empty())
|
||||
{
|
||||
// Use a std::set to keep the error message sorted.
|
||||
std::set<std::string> props;
|
||||
// Use a sorted std::vector to keep the error message sorted.
|
||||
std::vector<std::string> props;
|
||||
std::set<std::string>::const_iterator i = emittedBools.find(prop);
|
||||
if (i != emittedBools.end())
|
||||
{
|
||||
props.insert(strBool);
|
||||
props.push_back(strBool);
|
||||
}
|
||||
i = emittedStrings.find(prop);
|
||||
if (i != emittedStrings.end())
|
||||
{
|
||||
props.insert(strString);
|
||||
props.push_back(strString);
|
||||
}
|
||||
i = emittedMinNumbers.find(prop);
|
||||
if (i != emittedMinNumbers.end())
|
||||
{
|
||||
props.insert(strNumMin);
|
||||
props.push_back(strNumMin);
|
||||
}
|
||||
i = emittedMaxNumbers.find(prop);
|
||||
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;
|
||||
e << "Property \"" << prop << "\" appears in both the "
|
||||
<< propsString <<
|
||||
|
@ -11,6 +11,8 @@
|
||||
============================================================================*/
|
||||
#include "cmVariableWatch.h"
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
static const char* const cmVariableWatchAccessStrings[] =
|
||||
{
|
||||
"READ_ACCESS",
|
||||
|
@ -406,12 +406,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||
// Clock command
|
||||
else if (args[1] == "time" && args.size() > 2)
|
||||
{
|
||||
std::string command = args[2];
|
||||
for (std::string::size_type cc = 3; cc < args.size(); cc ++)
|
||||
{
|
||||
command += " ";
|
||||
command += args[cc];
|
||||
}
|
||||
std::string command = cmJoin(cmRange(args).advance(2), " ");
|
||||
|
||||
clock_t clock_start, clock_finish;
|
||||
time_t time_start, time_finish;
|
||||
@ -473,14 +468,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
||||
}
|
||||
|
||||
std::string command = "\"";
|
||||
command += args[3];
|
||||
command += cmJoin(cmRange(args).advance(3), "\" \"");
|
||||
command += "\"";
|
||||
for (std::string::size_type cc = 4; cc < args.size(); cc ++)
|
||||
{
|
||||
command += " \"";
|
||||
command += args[cc];
|
||||
command += "\"";
|
||||
}
|
||||
int retval = 0;
|
||||
int timeout = 0;
|
||||
if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
|
||||
|
Loading…
x
Reference in New Issue
Block a user