cmStandardIncludes.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. /**
  11. * Include header files as a function of the build process, compiler,
  12. * and operating system.
  13. */
  14. #ifndef cmStandardIncludes_h
  15. #define cmStandardIncludes_h
  16. #include <cmConfigure.h>
  17. #include <cmsys/Configure.hxx>
  18. #ifdef _MSC_VER
  19. #pragma warning ( disable : 4786 )
  20. #pragma warning ( disable : 4503 )
  21. #endif
  22. #ifdef __ICL
  23. #pragma warning ( disable : 985 )
  24. #pragma warning ( disable : 1572 ) /* floating-point equality test */
  25. #endif
  26. // Provide fixed-size integer types.
  27. #include <cmIML/INT.h>
  28. // Include stream compatibility layer from KWSys.
  29. // This is needed to work with large file support
  30. // on some platforms whose stream operators do not
  31. // support the large integer types.
  32. #if defined(CMAKE_BUILD_WITH_CMAKE)
  33. # include <cmsys/IOStream.hxx>
  34. #endif
  35. #include <fstream>
  36. #include <iostream>
  37. #include <iomanip>
  38. #include <sstream>
  39. // we must have stl with the standard include style
  40. #include <vector>
  41. #include <string>
  42. #include <iterator>
  43. #include <algorithm>
  44. #include <functional>
  45. #include <map>
  46. #include <list>
  47. #include <set>
  48. // include the "c" string header
  49. #include <string.h>
  50. #include <stdio.h>
  51. #include <stdlib.h>
  52. #if defined( _MSC_VER )
  53. typedef unsigned short mode_t;
  54. #endif
  55. // use this class to shrink the size of symbols in .o files
  56. // std::string is really basic_string<....lots of stuff....>
  57. // when combined with a map or set, the symbols can be > 2000 chars!
  58. #include <cmsys/String.hxx>
  59. //typedef cmsys::String std::string;
  60. /* Poison this operator to avoid common mistakes. */
  61. extern void operator << (std::ostream&, const std::ostringstream&);
  62. /** Standard documentation entry for cmDocumentation's formatting. */
  63. struct cmDocumentationEntry
  64. {
  65. std::string Name;
  66. std::string Brief;
  67. cmDocumentationEntry(){}
  68. cmDocumentationEntry(const char *doc[2])
  69. { if (doc[0]) this->Name = doc[0];
  70. if (doc[1]) this->Brief = doc[1];}
  71. cmDocumentationEntry(const char *n, const char *b)
  72. { if (n) this->Name = n; if (b) this->Brief = b; }
  73. };
  74. /** Data structure to represent a single command line. */
  75. class cmCustomCommandLine: public std::vector<std::string>
  76. {
  77. public:
  78. typedef std::vector<std::string> Superclass;
  79. typedef Superclass::iterator iterator;
  80. typedef Superclass::const_iterator const_iterator;
  81. };
  82. /** Data structure to represent a list of command lines. */
  83. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  84. {
  85. public:
  86. typedef std::vector<cmCustomCommandLine> Superclass;
  87. typedef Superclass::iterator iterator;
  88. typedef Superclass::const_iterator const_iterator;
  89. };
  90. // All subclasses of cmCommand or cmCTestGenericHandler should
  91. // invoke this macro.
  92. #define cmTypeMacro(thisClass,superclass) \
  93. virtual const char* GetNameOfClass() { return #thisClass; } \
  94. typedef superclass Superclass; \
  95. static bool IsTypeOf(const char *type) \
  96. { \
  97. if ( !strcmp(#thisClass,type) ) \
  98. { \
  99. return true; \
  100. } \
  101. return Superclass::IsTypeOf(type); \
  102. } \
  103. virtual bool IsA(const char *type) \
  104. { \
  105. return thisClass::IsTypeOf(type); \
  106. } \
  107. static thisClass* SafeDownCast(cmObject *c) \
  108. { \
  109. if ( c && c->IsA(#thisClass) ) \
  110. { \
  111. return static_cast<thisClass *>(c); \
  112. } \
  113. return 0;\
  114. } \
  115. class cmTypeMacro_UseTrailingSemicolon
  116. template<typename Range>
  117. std::string cmJoin(Range const& r, const char* delimiter)
  118. {
  119. if (r.empty())
  120. {
  121. return std::string();
  122. }
  123. std::ostringstream os;
  124. typedef typename Range::value_type ValueType;
  125. typedef typename Range::const_iterator InputIt;
  126. InputIt first = r.begin();
  127. InputIt last = r.end();
  128. --last;
  129. std::copy(first, last,
  130. std::ostream_iterator<ValueType>(os, delimiter));
  131. os << *last;
  132. return os.str();
  133. }
  134. template<typename Range>
  135. std::string cmJoin(Range const& r, std::string delimiter)
  136. {
  137. return cmJoin(r, delimiter.c_str());
  138. };
  139. inline bool cmHasLiteralPrefixImpl(const std::string &str1,
  140. const char *str2,
  141. size_t N)
  142. {
  143. return strncmp(str1.c_str(), str2, N) == 0;
  144. }
  145. inline bool cmHasLiteralPrefixImpl(const char* str1,
  146. const char *str2,
  147. size_t N)
  148. {
  149. return strncmp(str1, str2, N) == 0;
  150. }
  151. inline bool cmHasLiteralSuffixImpl(const std::string &str1,
  152. const char *str2,
  153. size_t N)
  154. {
  155. size_t len = str1.size();
  156. return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
  157. }
  158. inline bool cmHasLiteralSuffixImpl(const char* str1,
  159. const char* str2,
  160. size_t N)
  161. {
  162. size_t len = strlen(str1);
  163. return len >= N && strcmp(str1 + len - N, str2) == 0;
  164. }
  165. template<typename T, size_t N>
  166. const T* cmArrayBegin(const T (&a)[N]) { return a; }
  167. template<typename T, size_t N>
  168. const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
  169. template<typename T, size_t N>
  170. size_t cmArraySize(const T (&)[N]) { return N; }
  171. template<typename T, size_t N>
  172. bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
  173. {
  174. return cmHasLiteralPrefixImpl(str1, str2, N - 1);
  175. }
  176. template<typename T, size_t N>
  177. bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
  178. {
  179. return cmHasLiteralSuffixImpl(str1, str2, N - 1);
  180. }
  181. struct cmStrCmp {
  182. cmStrCmp(const char *test) : m_test(test) {}
  183. cmStrCmp(const std::string &test) : m_test(test) {}
  184. bool operator()(const std::string& input) const
  185. {
  186. return m_test == input;
  187. }
  188. bool operator()(const char * input) const
  189. {
  190. return strcmp(input, m_test.c_str()) == 0;
  191. }
  192. private:
  193. const std::string m_test;
  194. };
  195. namespace ContainerAlgorithms {
  196. template<typename T>
  197. struct cmIsPair
  198. {
  199. enum { value = false };
  200. };
  201. template<typename K, typename V>
  202. struct cmIsPair<std::pair<K, V> >
  203. {
  204. enum { value = true };
  205. };
  206. template<typename Container,
  207. bool valueTypeIsPair = cmIsPair<typename Container::value_type>::value>
  208. struct DefaultDeleter
  209. {
  210. void operator()(typename Container::value_type value) {
  211. delete value;
  212. }
  213. };
  214. template<typename Container>
  215. struct DefaultDeleter<Container, /* valueTypeIsPair = */ true>
  216. {
  217. void operator()(typename Container::value_type value) {
  218. delete value.second;
  219. }
  220. };
  221. }
  222. template<typename Container>
  223. void cmDeleteAll(Container const& c)
  224. {
  225. std::for_each(c.begin(), c.end(),
  226. ContainerAlgorithms::DefaultDeleter<Container>());
  227. }
  228. #endif