cmStandardIncludes.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. /**
  14. * Include header files as a function of the build process, compiler,
  15. * and operating system.
  16. */
  17. #ifndef cmStandardIncludes_h
  18. #define cmStandardIncludes_h
  19. // include configure generated header to define
  20. // CMAKE_NO_ANSI_STREAM_HEADERS and CMAKE_NO_STD_NAMESPACE
  21. #if defined(CMAKE_HAS_AUTOCONF) || defined(CMAKE_BUILD_WITH_CMAKE)
  22. #include "cmConfigure.h"
  23. #endif
  24. #ifdef _MSC_VER
  25. #pragma warning ( disable : 4786 )
  26. #pragma warning ( disable : 4503 )
  27. #define CMAKE_NO_ANSI_FOR_SCOPE
  28. #endif
  29. #ifdef __ICL
  30. #pragma warning ( disable : 985 )
  31. #endif
  32. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  33. # include <fstream>
  34. # include <iostream>
  35. #else
  36. # include <fstream.h>
  37. # include <iostream.h>
  38. #endif
  39. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  40. # include <sstream>
  41. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  42. # include <strstream>
  43. #else
  44. # include <strstream.h>
  45. #endif
  46. // we must have stl with the standard include style
  47. #include <vector>
  48. #include <string>
  49. #include <iterator>
  50. #include <algorithm>
  51. #include <functional>
  52. #include <map>
  53. #include <list>
  54. #include <set>
  55. // include the "c" string header
  56. #include <string.h>
  57. #if !defined(_WIN32) && defined(__COMO__)
  58. // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
  59. extern "C"
  60. {
  61. extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
  62. extern int pclose (FILE *__stream) __THROW;
  63. extern char *realpath (__const char *__restrict __name,
  64. char *__restrict __resolved) __THROW;
  65. extern char *strdup (__const char *__s) __THROW;
  66. extern int putenv (char *__string) __THROW;
  67. }
  68. #endif
  69. // if std:: is not supported, then just #define it away
  70. #ifdef CMAKE_NO_STD_NAMESPACE
  71. #define std
  72. #endif
  73. // if the compiler does not support ansi for scoping of vars use a
  74. // #define hack
  75. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  76. #define for if(false) {} else for
  77. #endif
  78. // check for the 720 compiler on the SGI
  79. // which has some strange properties that I don't think are worth
  80. // checking for in a general way in configure
  81. #if defined(__sgi) && !defined(__GNUC__)
  82. # if (_COMPILER_VERSION >= 730)
  83. # define CM_SGI_CC_730
  84. # elif (_COMPILER_VERSION >= 720)
  85. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  86. # endif
  87. #endif
  88. #ifdef __DECCXX_VER
  89. # if __DECCXX_VER <= 60390008
  90. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  91. # endif
  92. #endif
  93. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  94. // some compilers have std:: but not for the stream library,
  95. // so we have to bring it into the std namespace by hand.
  96. namespace std {
  97. using ::ostream;
  98. using ::istream;
  99. using ::ios;
  100. using ::cout;
  101. using ::cerr;
  102. using ::cin;
  103. using ::ifstream;
  104. using ::ofstream;
  105. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  106. using ::ostringstream;
  107. using ::istringstream;
  108. #else
  109. using ::ostrstream;
  110. using ::istrstream;
  111. #endif
  112. using ::endl;
  113. using ::ends;
  114. using ::flush;
  115. }
  116. // The string class is missing these operators so add them
  117. inline bool operator!=(std::string const& a, const char* b)
  118. { return !(a==std::string(b)); }
  119. inline bool operator==(std::string const& a, const char* b)
  120. { return (a==std::string(b)); }
  121. # endif // end CM_SGI_CC_720
  122. // use this class to shrink the size of symbols in .o files
  123. // std::string is really basic_string<....lots of stuff....>
  124. // when combined with a map or set, the symbols can be > 2000 chars!
  125. struct cmStdString : public std::string
  126. {
  127. typedef std::string StdString;
  128. typedef StdString::value_type value_type;
  129. typedef StdString::pointer pointer;
  130. typedef StdString::reference reference;
  131. typedef StdString::const_reference const_reference;
  132. typedef StdString::size_type size_type;
  133. typedef StdString::difference_type difference_type;
  134. typedef StdString::iterator iterator;
  135. typedef StdString::const_iterator const_iterator;
  136. typedef StdString::reverse_iterator reverse_iterator;
  137. typedef StdString::const_reverse_iterator const_reverse_iterator;
  138. cmStdString(): StdString() {}
  139. cmStdString(const value_type* s): StdString(s) {}
  140. cmStdString(const value_type* s, size_type n): StdString(s, n) {}
  141. cmStdString(const StdString& s, size_type pos=0, size_type n=npos):
  142. StdString(s, pos, n) {}
  143. };
  144. // Define cmOStringStream and cmIStringStream wrappers to hide
  145. // differences between std::stringstream and the old strstream.
  146. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  147. class cmOStringStream: public std::ostringstream
  148. {
  149. public:
  150. cmOStringStream() {}
  151. private:
  152. cmOStringStream(const cmOStringStream&);
  153. void operator=(const cmOStringStream&);
  154. };
  155. class cmIStringStream: public std::istringstream
  156. {
  157. public:
  158. typedef std::istringstream Superclass;
  159. cmIStringStream() {}
  160. cmIStringStream(const std::string& s): Superclass(s) {}
  161. private:
  162. cmIStringStream(const cmIStringStream&);
  163. void operator=(const cmIStringStream&);
  164. };
  165. #else
  166. class cmOStrStreamCleanup
  167. {
  168. public:
  169. cmOStrStreamCleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
  170. ~cmOStrStreamCleanup() { m_OStrStream.rdbuf()->freeze(0); }
  171. static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
  172. protected:
  173. std::ostrstream& m_OStrStream;
  174. };
  175. class cmOStringStream: public std::ostrstream
  176. {
  177. public:
  178. typedef std::ostrstream Superclass;
  179. cmOStringStream() {}
  180. std::string str()
  181. {
  182. cmOStrStreamCleanup cleanup(*this);
  183. cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  184. int pcount = this->pcount();
  185. const char* ptr = this->Superclass::str();
  186. return std::string(ptr?ptr:"", pcount);
  187. }
  188. private:
  189. cmOStringStream(const cmOStringStream&);
  190. void operator=(const cmOStringStream&);
  191. };
  192. class cmIStringStream: private std::string, public std::istrstream
  193. {
  194. public:
  195. typedef std::string StdString;
  196. typedef std::istrstream IStrStream;
  197. cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
  198. cmIStringStream(const std::string& s):
  199. StdString(s), IStrStream(StdString::c_str()) {}
  200. std::string str() const { return *this; }
  201. void str(const std::string& s)
  202. {
  203. // Very dangerous. If this throws, the object is hosed. When the
  204. // destructor is later called, the program is hosed too.
  205. this->~cmIStringStream();
  206. new (this) cmIStringStream(s);
  207. }
  208. private:
  209. cmIStringStream(const cmIStringStream&);
  210. void operator=(const cmIStringStream&);
  211. };
  212. #endif
  213. #endif