cmStandardIncludes.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #if !defined(_WIN32) && defined(__COMO__)
  25. # define _BSD_SOURCE
  26. #endif
  27. #ifdef _MSC_VER
  28. #pragma warning ( disable : 4786 )
  29. #pragma warning ( disable : 4503 )
  30. #define CMAKE_NO_ANSI_FOR_SCOPE
  31. #endif
  32. #ifdef __ICL
  33. #pragma warning ( disable : 985 )
  34. #endif
  35. #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
  36. # include <fstream>
  37. # include <iostream>
  38. #else
  39. # include <fstream.h>
  40. # include <iostream.h>
  41. #endif
  42. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  43. # include <sstream>
  44. #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
  45. # include <strstream>
  46. #else
  47. # include <strstream.h>
  48. #endif
  49. // we must have stl with the standard include style
  50. #include <vector>
  51. #include <string>
  52. #include <iterator>
  53. #include <algorithm>
  54. #include <functional>
  55. #include <map>
  56. #include <list>
  57. #include <set>
  58. // include the "c" string header
  59. #include <string.h>
  60. // if std:: is not supported, then just #define it away
  61. #ifdef CMAKE_NO_STD_NAMESPACE
  62. #define std
  63. #endif
  64. // if the compiler does not support ansi for scoping of vars use a
  65. // #define hack
  66. #ifdef CMAKE_NO_ANSI_FOR_SCOPE
  67. #define for if(false) {} else for
  68. #endif
  69. // check for the 720 compiler on the SGI
  70. // which has some strange properties that I don't think are worth
  71. // checking for in a general way in configure
  72. #if defined(__sgi) && !defined(__GNUC__)
  73. # if (_COMPILER_VERSION >= 730)
  74. # define CM_SGI_CC_730
  75. # elif (_COMPILER_VERSION >= 720)
  76. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  77. # endif
  78. #endif
  79. #ifdef __DECCXX_VER
  80. # if __DECCXX_VER <= 60390008
  81. # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  82. # endif
  83. #endif
  84. #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
  85. // some compilers have std:: but not for the stream library,
  86. // so we have to bring it into the std namespace by hand.
  87. namespace std {
  88. using ::ostream;
  89. using ::istream;
  90. using ::ios;
  91. using ::cout;
  92. using ::cerr;
  93. using ::cin;
  94. using ::ifstream;
  95. using ::ofstream;
  96. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  97. using ::ostringstream;
  98. #else
  99. using ::ostrstream;
  100. #endif
  101. using ::endl;
  102. using ::ends;
  103. using ::flush;
  104. }
  105. // The string class is missing these operators so add them
  106. inline bool operator!=(std::string const& a, const char* b)
  107. { return !(a==std::string(b)); }
  108. inline bool operator==(std::string const& a, const char* b)
  109. { return (a==std::string(b)); }
  110. # endif // end CM_SGI_CC_720
  111. // use this class to shrink the size of symbols in .o files
  112. // std::string is really basic_string<....lots of stuff....>
  113. // when combined with a map or set, the symbols can be > 2000 chars!
  114. struct cmStdString : public std::string
  115. {
  116. typedef std::string StdString;
  117. typedef StdString::value_type value_type;
  118. typedef StdString::pointer pointer;
  119. typedef StdString::reference reference;
  120. typedef StdString::const_reference const_reference;
  121. typedef StdString::size_type size_type;
  122. typedef StdString::difference_type difference_type;
  123. typedef StdString::iterator iterator;
  124. typedef StdString::const_iterator const_iterator;
  125. typedef StdString::reverse_iterator reverse_iterator;
  126. typedef StdString::const_reverse_iterator const_reverse_iterator;
  127. cmStdString(): StdString() {}
  128. cmStdString(const value_type* s): StdString(s) {}
  129. cmStdString(const value_type* s, size_type n): StdString(s, n) {}
  130. cmStdString(const StdString& s, size_type pos=0, size_type n=npos):
  131. StdString(s, pos, n) {}
  132. };
  133. // Define cmStringStream wrapper to hide differences between
  134. // std::stringstream and the old strstream.
  135. #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
  136. class cmStringStream: public std::ostringstream
  137. {
  138. public:
  139. cmStringStream() {}
  140. private:
  141. cmStringStream(const cmStringStream&);
  142. void operator=(const cmStringStream&);
  143. };
  144. #else
  145. class cmStrStreamCleanup
  146. {
  147. public:
  148. cmStrStreamCleanup(std::ostrstream& ostr): m_StrStream(ostr) {}
  149. ~cmStrStreamCleanup() { m_StrStream.rdbuf()->freeze(0); }
  150. static void IgnoreUnusedVariable(const cmStrStreamCleanup&) {}
  151. protected:
  152. std::ostrstream& m_StrStream;
  153. };
  154. class cmStringStream: public std::ostrstream
  155. {
  156. public:
  157. typedef std::ostrstream Superclass;
  158. cmStringStream() {}
  159. std::string str()
  160. {
  161. cmStrStreamCleanup cleanup(*this);
  162. cmStrStreamCleanup::IgnoreUnusedVariable(cleanup);
  163. int pcount = this->pcount();
  164. const char* ptr = this->Superclass::str();
  165. return std::string(ptr?ptr:"", pcount);
  166. }
  167. private:
  168. cmStringStream(const cmStringStream&);
  169. void operator=(const cmStringStream&);
  170. };
  171. #endif
  172. #endif