cmStandardIncludes.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
  17. // CMAKE_NO_STD_NAMESPACE, and other macros.
  18. #include <cmConfigure.h>
  19. #include <cmsys/Configure.hxx>
  20. #ifdef _MSC_VER
  21. #pragma warning ( disable : 4786 )
  22. #pragma warning ( disable : 4503 )
  23. #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
  24. #endif
  25. #ifdef __ICL
  26. #pragma warning ( disable : 985 )
  27. #pragma warning ( disable : 1572 ) /* floating-point equality test */
  28. #endif
  29. // Provide fixed-size integer types.
  30. #include <cmIML/INT.h>
  31. // Include stream compatibility layer from KWSys.
  32. // This is needed to work with large file support
  33. // on some platforms whose stream operators do not
  34. // support the large integer types.
  35. #if defined(CMAKE_BUILD_WITH_CMAKE)
  36. # include <cmsys/IOStream.hxx>
  37. #endif
  38. // Avoid warnings in system headers.
  39. #if defined(_MSC_VER)
  40. # pragma warning (push,1)
  41. #endif
  42. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  43. # include <fstream>
  44. # include <iostream>
  45. # include <iomanip>
  46. #else
  47. # include <fstream.h>
  48. # include <iostream.h>
  49. # include <iomanip.h>
  50. #endif
  51. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  52. # include <sstream>
  53. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  54. # include <strstream>
  55. #else
  56. # include <strstream.h>
  57. #endif
  58. // we must have stl with the standard include style
  59. #include <vector>
  60. #include <string>
  61. #include <iterator>
  62. #include <algorithm>
  63. #include <functional>
  64. #include <map>
  65. #include <list>
  66. #include <set>
  67. #include <deque>
  68. #if defined(_MSC_VER)
  69. # pragma warning(pop)
  70. #endif
  71. // include the "c" string header
  72. #include <string.h>
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. // if std:: is not supported, then just #define it away
  76. #ifdef CMAKE_NO_STD_NAMESPACE
  77. #define std
  78. #endif
  79. #if defined( _MSC_VER )
  80. typedef unsigned short mode_t;
  81. #endif
  82. // use this class to shrink the size of symbols in .o files
  83. // std::string is really basic_string<....lots of stuff....>
  84. // when combined with a map or set, the symbols can be > 2000 chars!
  85. #include <cmsys/String.hxx>
  86. //typedef cmsys::String std::string;
  87. // Define cmOStringStream and cmIStringStream wrappers to hide
  88. // differences between std::stringstream and the old strstream.
  89. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  90. class cmOStringStream: public std::ostringstream
  91. {
  92. public:
  93. cmOStringStream();
  94. ~cmOStringStream();
  95. private:
  96. cmOStringStream(const cmOStringStream&);
  97. void operator=(const cmOStringStream&);
  98. };
  99. class cmIStringStream: public std::istringstream
  100. {
  101. public:
  102. typedef std::istringstream Superclass;
  103. cmIStringStream() {}
  104. cmIStringStream(const std::string& s): Superclass(s) {}
  105. private:
  106. cmIStringStream(const cmIStringStream&);
  107. void operator=(const cmIStringStream&);
  108. };
  109. #else
  110. class cmOStrStreamCleanup
  111. {
  112. public:
  113. cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
  114. ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
  115. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  116. protected:
  117. std::ostrstream& OStrStream;
  118. };
  119. class cmOStringStream: public std::ostrstream
  120. {
  121. public:
  122. typedef std::ostrstream Superclass;
  123. cmOStringStream() {}
  124. std::string str()
  125. {
  126. cmOStrStreamCleanup cleanup(*this);
  127. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  128. int pcount = this->pcount();
  129. const char* ptr = this->Superclass::str();
  130. return std::string(ptr?ptr:"", pcount);
  131. }
  132. private:
  133. cmOStringStream(const cmOStringStream&);
  134. void operator=(const cmOStringStream&);
  135. };
  136. class cmIStringStream: private std::string, public std::istrstream
  137. {
  138. public:
  139. typedef std::string StdString;
  140. typedef std::istrstream IStrStream;
  141. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  142. cmIStringStream(const std::string& s):
  143. StdString(s), IStrStream(StdString::c_str()) {}
  144. std::string str() const { return *this; }
  145. void str(const std::string& s)
  146. {
  147. // Very dangerous. If this throws, the object is hosed. When the
  148. // destructor is later called, the program is hosed too.
  149. this->~cmIStringStream();
  150. new (this) cmIStringStream(s);
  151. }
  152. private:
  153. cmIStringStream(const cmIStringStream&);
  154. void operator=(const cmIStringStream&);
  155. };
  156. #endif
  157. /* Poison this operator to avoid common mistakes. */
  158. extern void operator << (std::ostream&, const cmOStringStream&);
  159. /** Standard documentation entry for cmDocumentation's formatting. */
  160. struct cmDocumentationEntry
  161. {
  162. std::string Name;
  163. std::string Brief;
  164. cmDocumentationEntry(){}
  165. cmDocumentationEntry(const char *doc[2])
  166. { if (doc[0]) this->Name = doc[0];
  167. if (doc[1]) this->Brief = doc[1];}
  168. cmDocumentationEntry(const char *n, const char *b)
  169. { if (n) this->Name = n; if (b) this->Brief = b; }
  170. };
  171. /** Data structure to represent a single command line. */
  172. class cmCustomCommandLine: public std::vector<std::string>
  173. {
  174. public:
  175. typedef std::vector<std::string> Superclass;
  176. typedef Superclass::iterator iterator;
  177. typedef Superclass::const_iterator const_iterator;
  178. };
  179. /** Data structure to represent a list of command lines. */
  180. class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
  181. {
  182. public:
  183. typedef std::vector<cmCustomCommandLine> Superclass;
  184. typedef Superclass::iterator iterator;
  185. typedef Superclass::const_iterator const_iterator;
  186. };
  187. // All subclasses of cmCommand or cmCTestGenericHandler should
  188. // invoke this macro.
  189. #define cmTypeMacro(thisClass,superclass) \
  190. virtual const char* GetNameOfClass() { return #thisClass; } \
  191. typedef superclass Superclass; \
  192. static bool IsTypeOf(const char *type) \
  193. { \
  194. if ( !strcmp(#thisClass,type) ) \
  195. { \
  196. return true; \
  197. } \
  198. return Superclass::IsTypeOf(type); \
  199. } \
  200. virtual bool IsA(const char *type) \
  201. { \
  202. return thisClass::IsTypeOf(type); \
  203. } \
  204. static thisClass* SafeDownCast(cmObject *c) \
  205. { \
  206. if ( c && c->IsA(#thisClass) ) \
  207. { \
  208. return static_cast<thisClass *>(c); \
  209. } \
  210. return 0;\
  211. } \
  212. class cmTypeMacro_UseTrailingSemicolon
  213. inline bool cmHasLiteralPrefixImpl(const std::string &str1,
  214. const char *str2,
  215. size_t N)
  216. {
  217. return strncmp(str1.c_str(), str2, N) == 0;
  218. }
  219. inline bool cmHasLiteralPrefixImpl(const char* str1,
  220. const char *str2,
  221. size_t N)
  222. {
  223. return strncmp(str1, str2, N) == 0;
  224. }
  225. inline bool cmHasLiteralSuffixImpl(const std::string &str1,
  226. const char *str2,
  227. size_t N)
  228. {
  229. size_t len = str1.size();
  230. return len >= N && strcmp(str1.c_str() + len - N, str2) == 0;
  231. }
  232. inline bool cmHasLiteralSuffixImpl(const char* str1,
  233. const char* str2,
  234. size_t N)
  235. {
  236. size_t len = strlen(str1);
  237. return len >= N && strcmp(str1 + len - N, str2) == 0;
  238. }
  239. template<typename T, size_t N>
  240. const T* cmArrayBegin(const T (&a)[N]) { return a; }
  241. template<typename T, size_t N>
  242. const T* cmArrayEnd(const T (&a)[N]) { return a + N; }
  243. template<typename T, size_t N>
  244. size_t cmArraySize(const T (&)[N]) { return N; }
  245. template<typename T, size_t N>
  246. bool cmHasLiteralPrefix(T str1, const char (&str2)[N])
  247. {
  248. return cmHasLiteralPrefixImpl(str1, str2, N - 1);
  249. }
  250. template<typename T, size_t N>
  251. bool cmHasLiteralSuffix(T str1, const char (&str2)[N])
  252. {
  253. return cmHasLiteralSuffixImpl(str1, str2, N - 1);
  254. }
  255. struct cmStrCmp {
  256. cmStrCmp(const char *test) : m_test(test) {}
  257. cmStrCmp(const std::string &test) : m_test(test) {}
  258. bool operator()(const std::string& input) const
  259. {
  260. return m_test == input;
  261. }
  262. bool operator()(const char * input) const
  263. {
  264. return strcmp(input, m_test.c_str()) == 0;
  265. }
  266. private:
  267. const std::string m_test;
  268. };
  269. #endif