cmStandardIncludes.h 5.3 KB

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