cmStandardIncludes.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. #else
  108. using ::ostrstream;
  109. #endif
  110. using ::endl;
  111. using ::ends;
  112. using ::flush;
  113. }
  114. // The string class is missing these operators so add them
  115. inline bool operator!=(std::string const& a, const char* b)
  116. { return !(a==std::string(b)); }
  117. inline bool operator==(std::string const& a, const char* b)
  118. { return (a==std::string(b)); }
  119. # endif // end CM_SGI_CC_720
  120. // use this class to shrink the size of symbols in .o files
  121. // std::string is really basic_string<....lots of stuff....>
  122. // when combined with a map or set, the symbols can be > 2000 chars!
  123. struct cmStdString : public std::string
  124. {
  125. typedef std::string StdString;
  126. typedef StdString::value_type value_type;
  127. typedef StdString::pointer pointer;
  128. typedef StdString::reference reference;
  129. typedef StdString::const_reference const_reference;
  130. typedef StdString::size_type size_type;
  131. typedef StdString::difference_type difference_type;
  132. typedef StdString::iterator iterator;
  133. typedef StdString::const_iterator const_iterator;
  134. typedef StdString::reverse_iterator reverse_iterator;
  135. typedef StdString::const_reverse_iterator const_reverse_iterator;
  136. cmStdString(): StdString() {}
  137. cmStdString(const value_type* s): StdString(s) {}
  138. cmStdString(const value_type* s, size_type n): StdString(s, n) {}
  139. cmStdString(const StdString& s, size_type pos=0, size_type n=npos):
  140. StdString(s, pos, n) {}
  141. };
  142. // Define cmStringStream wrapper to hide differences between
  143. // std::stringstream and the old strstream.
  144. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  145. class cmStringStream: public std::ostringstream
  146. {
  147. public:
  148. cmStringStream() {}
  149. private:
  150. cmStringStream(const cmStringStream&);
  151. void operator=(const cmStringStream&);
  152. };
  153. #else
  154. class cmStrStreamCleanup
  155. {
  156. public:
  157. cmStrStreamCleanup(std::ostrstream& ostr): m_StrStream(ostr) {}
  158. ~cmStrStreamCleanup() { m_StrStream.rdbuf()->freeze(0); }
  159. static void IgnoreUnusedVariable(const cmStrStreamCleanup&) {}
  160. protected:
  161. std::ostrstream& m_StrStream;
  162. };
  163. class cmStringStream: public std::ostrstream
  164. {
  165. public:
  166. typedef std::ostrstream Superclass;
  167. cmStringStream() {}
  168. std::string str()
  169. {
  170. cmStrStreamCleanup cleanup(*this);
  171. cmStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  172. int pcount = this->pcount();
  173. const char* ptr = this->Superclass::str();
  174. return std::string(ptr?ptr:"", pcount);
  175. }
  176. private:
  177. cmStringStream(const cmStringStream&);
  178. void operator=(const cmStringStream&);
  179. };
  180. #endif
  181. #endif