Split cmAlgorithms into a separate header file.
This commit is contained in:
parent
cbffbf7437
commit
ac26d4b343
|
@ -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>
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
/*============================================================================
|
||||
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 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)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "cmFileLock.h"
|
||||
#include "cmFileLockResult.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
cmFileLockPool::cmFileLockPool()
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define cmInstalledFile_h
|
||||
|
||||
#include "cmGeneratorExpression.h"
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
/** \class cmInstalledFile
|
||||
* \brief Represents a file intended for installation.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "cmRST.h"
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmVersion.h"
|
||||
#include <cmsys/FStream.hxx>
|
||||
#include <ctype.h>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
============================================================================*/
|
||||
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
============================================================================*/
|
||||
#include "cmVariableWatch.h"
|
||||
|
||||
#include "cmAlgorithms.h"
|
||||
|
||||
static const char* const cmVariableWatchAccessStrings[] =
|
||||
{
|
||||
"READ_ACCESS",
|
||||
|
|
Loading…
Reference in New Issue