Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmStandardIncludes.h
blob69198f5e4414f2c8a2822d26f2cfeb28931a06de
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmStandardIncludes.h,v $
5 Language: C++
6 <<<<<<< cmStandardIncludes.h
7 Date: $Date: 2008/02/24 19:05:11 $
8 Version: $Revision: 1.72 $
9 =======
10 Date: $Date: 2009-03-05 20:17:06 $
11 Version: $Revision: 1.73 $
12 >>>>>>> 1.73
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
22 /**
23 * Include header files as a function of the build process, compiler,
24 * and operating system.
26 #ifndef cmStandardIncludes_h
27 #define cmStandardIncludes_h
29 // include configure generated header to define CMAKE_NO_ANSI_STREAM_HEADERS,
30 // CMAKE_NO_STD_NAMESPACE, and other macros.
31 #include "cmConfigure.h"
32 #include <cmsys/Configure.hxx>
34 #ifdef _MSC_VER
35 #pragma warning ( disable : 4786 )
36 #pragma warning ( disable : 4503 )
37 #pragma warning ( disable : 4512 ) /* operator=() could not be generated */
38 #define CMAKE_NO_ANSI_FOR_SCOPE
39 #endif
41 #ifdef __BORLANDC__
42 #pragma warn -8030 /* Temporary used for parameter */
43 #endif
45 #ifdef __ICL
46 #pragma warning ( disable : 985 )
47 #endif
49 #include <stdarg.h> // Work-around for SGI MIPSpro 7.4.2m header bug
51 // This is a hack to prevent warnings about these functions being
52 // declared but not referenced.
53 #if defined(__sgi) && !defined(__GNUC__)
54 # include <sys/termios.h>
55 class cmStandardIncludesHack
57 public:
58 enum
60 Ref1 = sizeof(cfgetospeed(0)),
61 Ref2 = sizeof(cfgetispeed(0)),
62 Ref3 = sizeof(tcgetattr(0, 0)),
63 Ref4 = sizeof(tcsetattr(0, 0, 0)),
64 Ref5 = sizeof(cfsetospeed(0,0)),
65 Ref6 = sizeof(cfsetispeed(0,0))
68 #endif
70 // Include stream compatibility layer from KWSys.
71 // This is needed to work with large file support
72 // on some platforms whose stream operators do not
73 // support the large integer types.
74 #if defined(CMAKE_BUILD_WITH_CMAKE)
75 # include <cmsys/IOStream.hxx>
76 # undef GetCurrentDirectory // Borland <iosfwd> includes windows.h
77 #endif
79 // Avoid warnings in system headers.
80 #if defined(_MSC_VER)
81 # pragma warning (push,1)
82 #endif
84 #ifndef CMAKE_NO_ANSI_STREAM_HEADERS
85 # include <fstream>
86 # include <iostream>
87 # include <iomanip>
88 #else
89 # include <fstream.h>
90 # include <iostream.h>
91 # include <iomanip.h>
92 #endif
94 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
95 # include <sstream>
96 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
97 # include <strstream>
98 #else
99 # include <strstream.h>
100 #endif
102 // we must have stl with the standard include style
103 #include <vector>
104 #include <string>
105 #include <iterator>
106 #include <algorithm>
107 #include <functional>
108 #include <map>
109 #include <list>
110 #include <set>
111 #include <deque>
113 #if defined(_MSC_VER)
114 # pragma warning(pop)
115 #endif
117 // include the "c" string header
118 #include <string.h>
119 #include <stdio.h>
120 #include <stdlib.h>
122 // Borland C++ defines several of the stdlib.h and string.h symbols in
123 // sub-headers search.h and mem.h. These sub-headers have using
124 // declarations to pull functions from the std namespace to the global
125 // namespace, but they are defined only if the header was not included
126 // through the C++-style cstdlib or cstring header. These outer
127 // headers are included by the streams library in C++-style and
128 // include blockers are put in place that prevent including the
129 // C-style versions from ever including the sub-headers. Therefore we
130 // have to include the sub-headers here to get the using declarations.
131 #if defined(__BORLANDC__)
132 # include <mem.h> /* mem... functions from string.h */
133 # include <search.h> /* search functions from stdlib.h */
134 #endif
137 #if !defined(_WIN32) && defined(__COMO__)
138 // Hack for como strict mode to avoid defining _SVID_SOURCE or _BSD_SOURCE.
139 extern "C"
141 extern FILE *popen (__const char *__command, __const char *__modes) __THROW;
142 extern int pclose (FILE *__stream) __THROW;
143 extern char *realpath (__const char *__restrict __name,
144 char *__restrict __resolved) __THROW;
145 extern char *strdup (__const char *__s) __THROW;
146 extern int putenv (char *__string) __THROW;
148 #endif
150 // if std:: is not supported, then just #define it away
151 #ifdef CMAKE_NO_STD_NAMESPACE
152 #define std
153 #endif
155 // if the compiler does not support ansi for scoping of vars use a
156 // #define hack
157 #ifdef CMAKE_NO_ANSI_FOR_SCOPE
158 #define for if(false) {} else for
159 #endif
161 // check for the 720 compiler on the SGI
162 // which has some strange properties that I don't think are worth
163 // checking for in a general way in configure
164 #if defined(__sgi) && !defined(__GNUC__)
165 # if (_COMPILER_VERSION >= 730)
166 # define CM_SGI_CC_730
167 # elif (_COMPILER_VERSION >= 720)
168 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
169 # endif
170 #endif
172 #ifdef __DECCXX_VER
173 # if __DECCXX_VER <= 60390008
174 # define CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
175 # endif
176 #endif
178 #if defined( _MSC_VER )
179 typedef unsigned short mode_t;
180 #endif
183 #ifdef CM_HAS_STD_BUT_NOT_FOR_IOSTREAM
184 // some compilers have std:: but not for the stream library,
185 // so we have to bring it into the std namespace by hand.
186 namespace std {
187 using ::ostream;
188 using ::istream;
189 using ::ios;
190 using ::cout;
191 using ::cerr;
192 using ::cin;
193 using ::ifstream;
194 using ::ofstream;
196 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
197 using ::ostringstream;
198 using ::istringstream;
199 #else
200 using ::ostrstream;
201 using ::istrstream;
202 #endif
204 using ::endl;
205 using ::ends;
206 using ::flush;
207 using ::dec;
208 using ::hex;
209 using ::setw;
210 using ::setiosflags;
211 using ::setfill;
212 using ::setprecision;
214 // The string class is missing these operators so add them
215 #if !defined(cmsys_STL_STRING_NEQ_CHAR_DEFINED)
216 # define cmsys_STL_STRING_NO_NEQ_CHAR
217 inline bool operator!=(std::string const& a, const char* b)
218 { return !(a==std::string(b)); }
219 #endif
221 inline bool operator==(std::string const& a, const char* b)
222 { return (a==std::string(b)); }
223 # endif // end CM_SGI_CC_720
225 #if defined(__sgi) && !defined(__GNUC__)
226 # pragma set woff 1375 /* base class destructor not virtual */
227 #endif
229 // use this class to shrink the size of symbols in .o files
230 // std::string is really basic_string<....lots of stuff....>
231 // when combined with a map or set, the symbols can be > 2000 chars!
232 #include <cmsys/String.hxx>
233 typedef cmsys::String cmStdString;
235 // Define cmOStringStream and cmIStringStream wrappers to hide
236 // differences between std::stringstream and the old strstream.
237 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
238 class cmOStringStream: public std::ostringstream
240 public:
241 cmOStringStream() {}
242 private:
243 cmOStringStream(const cmOStringStream&);
244 void operator=(const cmOStringStream&);
246 class cmIStringStream: public std::istringstream
248 public:
249 typedef std::istringstream Superclass;
250 cmIStringStream() {}
251 cmIStringStream(const std::string& s): Superclass(s) {}
252 private:
253 cmIStringStream(const cmIStringStream&);
254 void operator=(const cmIStringStream&);
256 #else
257 class cmOStrStreamCleanup
259 public:
260 cmOStrStreamCleanup(std::ostrstream& ostr): OStrStream(ostr) {}
261 ~cmOStrStreamCleanup() { this->OStrStream.rdbuf()->freeze(0); }
262 static void IgnoreUnusedVariable(const cmOStrStreamCleanup&) {}
263 protected:
264 std::ostrstream& OStrStream;
267 class cmOStringStream: public std::ostrstream
269 public:
270 typedef std::ostrstream Superclass;
271 cmOStringStream() {}
272 std::string str()
274 cmOStrStreamCleanup cleanup(*this);
275 cmOStrStreamCleanup::IgnoreUnusedVariable(cleanup);
276 int pcount = this->pcount();
277 const char* ptr = this->Superclass::str();
278 return std::string(ptr?ptr:"", pcount);
280 private:
281 cmOStringStream(const cmOStringStream&);
282 void operator=(const cmOStringStream&);
285 class cmIStringStream: private std::string, public std::istrstream
287 public:
288 typedef std::string StdString;
289 typedef std::istrstream IStrStream;
290 cmIStringStream(): StdString(), IStrStream(StdString::c_str()) {}
291 cmIStringStream(const std::string& s):
292 StdString(s), IStrStream(StdString::c_str()) {}
293 std::string str() const { return *this; }
294 void str(const std::string& s)
296 // Very dangerous. If this throws, the object is hosed. When the
297 // destructor is later called, the program is hosed too.
298 this->~cmIStringStream();
299 new (this) cmIStringStream(s);
301 private:
302 cmIStringStream(const cmIStringStream&);
303 void operator=(const cmIStringStream&);
305 #endif
307 /* Poison this operator to avoid common mistakes. */
308 extern void operator << (std::ostream&, const cmOStringStream&);
310 /** Standard documentation entry for cmDocumentation's formatting. */
311 struct cmDocumentationEntry
313 std::string Name;
314 std::string Brief;
315 std::string Full;
316 cmDocumentationEntry(){};
317 cmDocumentationEntry(const char *doc[3])
318 { if (doc[0]) this->Name = doc[0];
319 if (doc[1]) this->Brief = doc[1];
320 if (doc[2]) this->Full = doc[2]; };
321 cmDocumentationEntry(const char *n, const char *b, const char *f)
322 { if (n) this->Name = n; if (b) this->Brief = b; if (f) this->Full = f; };
325 /** Data structure to represent a single command line. */
326 class cmCustomCommandLine: public std::vector<std::string>
328 public:
329 typedef std::vector<std::string> Superclass;
330 typedef Superclass::iterator iterator;
331 typedef Superclass::const_iterator const_iterator;
334 /** Data structure to represent a list of command lines. */
335 class cmCustomCommandLines: public std::vector<cmCustomCommandLine>
337 public:
338 typedef std::vector<cmCustomCommandLine> Superclass;
339 typedef Superclass::iterator iterator;
340 typedef Superclass::const_iterator const_iterator;
343 #if defined(__sgi) && !defined(__GNUC__)
344 # pragma reset woff 1375 /* base class destructor not virtual */
345 #endif
347 // All subclasses of cmCommand or cmCTestGenericHandler should
348 // invoke this macro.
349 #define cmTypeMacro(thisClass,superclass) \
350 virtual const char* GetNameOfClass() { return #thisClass; } \
351 typedef superclass Superclass; \
352 static bool IsTypeOf(const char *type) \
354 if ( !strcmp(#thisClass,type) ) \
356 return true; \
358 return Superclass::IsTypeOf(type); \
360 virtual bool IsA(const char *type) \
362 return thisClass::IsTypeOf(type); \
364 static thisClass* SafeDownCast(cmObject *c) \
366 if ( c && c->IsA(#thisClass) ) \
368 return static_cast<thisClass *>(c); \
370 return 0;\
375 #endif