summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-02-10 20:50:16 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-02-10 21:14:18 (GMT)
commitac26d4b343aece40b6b9a931ab619fc88d4b9492 (patch)
tree7c13c270325312345d84cbd1a147893c8a88a628
parentcbffbf7437ea2d571e26bedee032c23be9347d94 (diff)
downloadCMake-ac26d4b343aece40b6b9a931ab619fc88d4b9492.zip
CMake-ac26d4b343aece40b6b9a931ab619fc88d4b9492.tar.gz
CMake-ac26d4b343aece40b6b9a931ab619fc88d4b9492.tar.bz2
Split cmAlgorithms into a separate header file.
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.cxx1
-rw-r--r--Source/CTest/cmCTestGIT.cxx1
-rw-r--r--Source/cmAlgorithms.h151
-rw-r--r--Source/cmExportSet.cxx1
-rw-r--r--Source/cmExportSetMap.cxx1
-rw-r--r--Source/cmFileLockPool.cxx1
-rw-r--r--Source/cmInstalledFile.h1
-rw-r--r--Source/cmRST.cxx1
-rw-r--r--Source/cmStandardIncludes.h134
-rw-r--r--Source/cmSystemTools.cxx1
-rw-r--r--Source/cmVariableWatch.cxx2
11 files changed, 161 insertions, 134 deletions
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
index a07c29a..4626142 100644
--- a/Source/CPack/cmCPackGeneratorFactory.cxx
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -46,6 +46,7 @@
#endif
#include "cmCPackLog.h"
+#include "cmAlgorithms.h"
//----------------------------------------------------------------------
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx
index 98bc9d7..6b84bab 100644
--- a/Source/CTest/cmCTestGIT.cxx
+++ b/Source/CTest/cmCTestGIT.cxx
@@ -13,6 +13,7 @@
#include "cmCTest.h"
#include "cmSystemTools.h"
+#include "cmAlgorithms.h"
#include "cmXMLSafe.h"
#include <cmsys/RegularExpression.hxx>
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
new file mode 100644
index 0000000..4938140
--- /dev/null
+++ b/Source/cmAlgorithms.h
@@ -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
diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx
index 14812e4..4148fb5 100644
--- a/Source/cmExportSet.cxx
+++ b/Source/cmExportSet.cxx
@@ -12,6 +12,7 @@
#include "cmExportSet.h"
#include "cmTargetExport.h"
+#include "cmAlgorithms.h"
cmExportSet::~cmExportSet()
{
diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx
index 14c4458..cf431c6 100644
--- a/Source/cmExportSetMap.cxx
+++ b/Source/cmExportSetMap.cxx
@@ -12,6 +12,7 @@
#include "cmExportSetMap.h"
#include "cmExportSet.h"
+#include "cmAlgorithms.h"
cmExportSet* cmExportSetMap::operator[](const std::string &name)
{
diff --git a/Source/cmFileLockPool.cxx b/Source/cmFileLockPool.cxx
index cf8e9a9..3710eb0 100644
--- a/Source/cmFileLockPool.cxx
+++ b/Source/cmFileLockPool.cxx
@@ -16,6 +16,7 @@
#include "cmFileLock.h"
#include "cmFileLockResult.h"
+#include "cmAlgorithms.h"
cmFileLockPool::cmFileLockPool()
{
diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h
index 503f92c..cdb0866 100644
--- a/Source/cmInstalledFile.h
+++ b/Source/cmInstalledFile.h
@@ -13,6 +13,7 @@
#define cmInstalledFile_h
#include "cmGeneratorExpression.h"
+#include "cmAlgorithms.h"
/** \class cmInstalledFile
* \brief Represents a file intended for installation.
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index f4607c6..d20d999 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -12,6 +12,7 @@
#include "cmRST.h"
#include "cmSystemTools.h"
+#include "cmAlgorithms.h"
#include "cmVersion.h"
#include <cmsys/FStream.hxx>
#include <ctype.h>
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h
index 77b4f62..a9796b9 100644
--- a/Source/cmStandardIncludes.h
+++ b/Source/cmStandardIncludes.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
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 7dd6121..bf496e9 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -11,6 +11,7 @@
============================================================================*/
#include "cmSystemTools.h"
+#include "cmAlgorithms.h"
#include <ctype.h>
#include <errno.h>
#include <time.h>
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx
index b8a6df2..57dde31 100644
--- a/Source/cmVariableWatch.cxx
+++ b/Source/cmVariableWatch.cxx
@@ -11,6 +11,8 @@
============================================================================*/
#include "cmVariableWatch.h"
+#include "cmAlgorithms.h"
+
static const char* const cmVariableWatchAccessStrings[] =
{
"READ_ACCESS",