cmStandardIncludes.h 5.5 KB

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