fgms 0.11.8
The
FlightGear MultiPlayer Server
project
compiler.h
Go to the documentation of this file.
1 /**************************************************************************
2  * compiler.h -- C++ Compiler Portability Macros
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * $Id: compiler.h,v 1.1.1.1 2007/06/12 10:10:24 oliver Exp $
20  *
21  **************************************************************************/
22 
23 /** \file compiler.h
24  * A set of defines to encapsulate compiler and platform differences.
25  * Please refer to the source code for full documentation on this file.
26  *
27  * Here is a summary of what this file does.
28  *
29  * (1) Defines macros for some STL includes which may be affected
30  * by file name length limitations.
31  *
32  * (2) Defines macros for some features not supported by all C++ compilers.
33  *
34  * (3) Defines 'explicit' as a null macro if the compiler doesn't support
35  * the explicit keyword.
36  *
37  * (4) Defines 'typename' as a null macro if the compiler doesn't support
38  * the typename keyword.
39  *
40  * (5) Defines bool, true and false if the compiler doesn't do so.
41  *
42  * (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
43  * supports calling a function template by providing its template
44  * arguments explicitly.
45  *
46  * (7) Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
47  *
48  * (8) Defines SG_NO_ARROW_OPERATOR if the compiler is unable
49  * to support operator->() for iterators.
50  *
51  * (9) Defines SG_USE_EXCEPTIONS if the compiler supports exceptions.
52  * Note: no FlightGear code uses exceptions.
53  *
54  * (10) Define SG_NAMESPACES if the compiler supports namespaces.
55  *
56  * (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used??
57  *
58  * (12) Define SG_HAVE_STD if std namespace is supported.
59  *
60  * (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler
61  * supports partial specialization of class templates.
62  *
63  * (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
64  *
65  * (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
66  *
67  * (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception class
68  * that clashes with the one defined in <stdexcept>.
69  */
70 
71 #ifndef _SG_COMPILER_H
72 #define _SG_COMPILER_H
73 
74 /*
75  * Helper macro SG_STRINGIZE:
76  * Converts the parameter X to a string after macro replacement
77  * on X has been performed.
78  */
79 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
80 #define SG_DO_STRINGIZE(X) #X
81 
82 #ifdef __GNUC__
83 # if __GNUC__ == 2
84 # if __GNUC_MINOR__ < 8
85 
86  // g++-2.7.x
87 # define STL_ALGORITHM <algorithm>
88 # define STL_FUNCTIONAL <functional>
89 # define STL_IOMANIP <iomanip.h>
90 # define STL_IOSTREAM <iostream.h>
91 # define STL_ITERATOR <iterator.h>
92 # define STL_FSTREAM <fstream.h>
93 # define STL_STDEXCEPT <stdexcept>
94 # define STL_STRING <string>
95 # define STL_STRSTREAM <strstream.h>
96 
97 # define SG_NEED_AUTO_PTR
98 # define SG_NO_DEFAULT_TEMPLATE_ARGS
99 # define SG_INCOMPLETE_FUNCTIONAL
100 # define SG_NO_ARROW_OPERATOR
101 
102 # elif __GNUC_MINOR__ >= 8
103 
104  // g++-2.8.x and egcs-1.x
105 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
106 # define SG_NEED_AUTO_PTR
107 # define SG_MEMBER_TEMPLATES
108 # define SG_NAMESPACES
109 # define SG_HAVE_STD
110 # define SG_HAVE_STREAMBUF
111 # define SG_CLASS_PARTIAL_SPECIALIZATION
112 
113 # define STL_ALGORITHM <algorithm>
114 # define STL_FUNCTIONAL <functional>
115 # define STL_IOMANIP <iomanip>
116 # define STL_IOSTREAM <iostream>
117 # define STL_ITERATOR <iterator>
118 # define STL_FSTREAM <fstream>
119 # define STL_STDEXCEPT <stdexcept>
120 # define STL_STRING <string>
121 # define STL_STRSTREAM <strstream>
122 
123 # endif
124 # elif __GNUC__ >= 3
125  // g++-3.0.x
126 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
127 # define SG_NEED_AUTO_PTR
128 # define SG_MEMBER_TEMPLATES
129 # define SG_NAMESPACES
130 # define SG_HAVE_STD
131 # define SG_HAVE_STREAMBUF
132 # define SG_CLASS_PARTIAL_SPECIALIZATION
133 # define SG_HAVE_STD_INCLUDES
134 
135 # define STL_ALGORITHM <algorithm>
136 # define STL_FUNCTIONAL <functional>
137 # define STL_IOMANIP <iomanip>
138 # define STL_IOSTREAM <iostream>
139 # define STL_ITERATOR <iterator>
140 # define STL_FSTREAM <fstream>
141 # define STL_STDEXCEPT <stdexcept>
142 # define STL_STRING <string>
143 # define STL_STRSTREAM <strstream>
144 # else
145 # error Time to upgrade. GNU compilers < 2.7 not supported
146 # endif
147 
148 # define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
149 
150 #endif // __GNUC__
151 
152 /* KAI C++ */
153 #if defined(__KCC)
154 
155 # define SG_NAMESPACES
156 # define SG_HAVE_STD
157 # define SG_HAVE_STREAMBUF
158 # define SG_HAVE_TRAITS
159 # define SG_HAVE_STD_INCLUDES
160 
161 # define STL_ALGORITHM <algorithm>
162 # define STL_FUNCTIONAL <functional>
163 # define STL_IOMANIP <iomanip>
164 # define STL_IOSTREAM <iostream>
165 # define STL_ITERATOR <iterator>
166 # define STL_FSTREAM <fstream>
167 # define STL_STDEXCEPT <stdexcept>
168 # define STL_STRING <string>
169 # define STL_STRSTREAM <strstream>
170 
171 # define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
172 
173 #endif // __KCC
174 
175 //
176 // Metrowerks
177 //
178 #if defined(__MWERKS__)
179 /*
180  CodeWarrior compiler from Metrowerks, Inc.
181 */
182 # define SG_HAVE_TRAITS
183 # define SG_HAVE_STD_INCLUDES
184 # define SG_HAVE_STD
185 # define SG_NAMESPACES
186 
187 # define STL_ALGORITHM <algorithm>
188 # define STL_FUNCTIONAL <functional>
189 # define STL_IOMANIP <iomanip>
190 # define STL_IOSTREAM <iostream>
191 # define STL_ITERATOR <iterator>
192 # define STL_FSTREAM <fstream>
193 # define STL_STDEXCEPT <stdexcept>
194 # define STL_STRING <string>
195 
196 // Temp:
197 # define bcopy(from, to, n) memcpy(to, from, n)
198 
199 // -rp- please use FG_MEM_COPY everywhere !
200 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
201 
202 // -dw- currently used glut has no game mode stuff
203 # define GLUT_WRONG_VERSION
204 
205 # define SG_COMPILER_STR "Metrowerks CodeWarrior C++ version " SG_STRINGIZE(__MWERKS__)
206 
207 #endif // __MWERKS__
208 
209 //
210 // Microsoft compilers.
211 //
212 #ifdef _MSC_VER
213 # define bcopy(from, to, n) memcpy(to, from, n)
214 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
215 
216 # if _MSC_VER >= 1200 // msvc++ 6.0 or greater
217 # define SG_NAMESPACES
218 # define SG_HAVE_STD
219 # define SG_HAVE_STD_INCLUDES
220 # define SG_HAVE_STREAMBUF
221 
222 # define STL_ALGORITHM <algorithm>
223 # define STL_FUNCTIONAL <functional>
224 # define STL_IOMANIP <iomanip>
225 # define STL_IOSTREAM <iostream>
226 # define STL_ITERATOR <iterator>
227 # define STL_FSTREAM <fstream>
228 # define STL_STDEXCEPT <stdexcept>
229 # define STL_STRING <string>
230 # define STL_STRSTREAM <strstream>
231 
232 # define isnan _isnan
233 # define snprintf _snprintf
234 
235 # pragma warning(disable: 4786) // identifier was truncated to '255' characters
236 # pragma warning(disable: 4244) // conversion from double to float
237 # pragma warning(disable: 4305) //
238 
239 # else
240 # error What version of MSVC++ is this?
241 # endif
242 
243 # define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
244 
245 #endif // _MSC_VER
246 
247 #ifdef __BORLANDC__
248 # if defined(HAVE_SGI_STL_PORT)
249 
250 // Use quotes around long file names to get around Borland's include hackery
251 
252 # define STL_ALGORITHM "algorithm"
253 # define STL_FUNCTIONAL "functional"
254 
255 # define SG_MATH_EXCEPTION_CLASH
256 
257 # else
258 
259 # define STL_ALGORITHM <algorithm>
260 # define STL_FUNCTIONAL <functional>
261 # define STL_IOMANIP <iomanip>
262 # define STL_STDEXCEPT <stdexcept>
263 # define STL_STRSTREAM <strstream>
264 
265 # define SG_INCOMPLETE_FUNCTIONAL
266 
267 # endif // HAVE_SGI_STL_PORT
268 
269 # define STL_IOSTREAM <iostream>
270 # define STL_ITERATOR <iterator>
271 # define STL_FSTREAM <fstream>
272 # define STL_STRING <string>
273 # define SG_NO_DEFAULT_TEMPLATE_ARGS
274 # define SG_NAMESPACES
275 // # define SG_HAVE_STD
276 
277 # define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
278 
279 #endif // __BORLANDC__
280 
281 //
282 // Native SGI compilers
283 //
284 
285 #if defined ( sgi ) && !defined( __GNUC__ )
286 # define SG_HAVE_NATIVE_SGI_COMPILERS
287 
288 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
289 # define SG_CLASS_PARTIAL_SPECIALIZATION
290 # define SG_NEED_AUTO_PTR
291 # define SG_MEMBER_TEMPLATES
292 # define SG_NAMESPACES
293 # define SG_HAVE_STD
294 # define SG_HAVE_STREAMBUF
295 # define SG_HAVE_TRAITS
296 # define SG_HAVE_STD_INCLUDES
297 
298 # define STL_ALGORITHM <algorithm>
299 # define STL_FUNCTIONAL <functional>
300 # define STL_IOMANIP <iomanip>
301 # define STL_IOSTREAM <iostream>
302 # define STL_ITERATOR <iterator>
303 # define STL_FSTREAM <fstream>
304 # define STL_STDEXCEPT <stdexcept>
305 #if (_COMPILER_VERSION < 740)
306 # define STL_STRING <irix_string>
307 #else
308 # define STL_STRING <string>
309 #endif
310 # define STL_STRSTREAM <strstream>
311 
312 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
313 #pragma set woff 1401,1460,1551,1552,1681
314 
315 #ifdef __cplusplus
316 #pragma set woff 1682,3303
317 #if (_COMPILER_VERSION >= 740)
318 # pragma set woff 3624
319 #endif
320 #endif
321 
322 # define SG_COMPILER_STR "SGI MipsPro compiler version " SG_STRINGIZE(_COMPILER_VERSION)
323 
324 #endif // Native SGI compilers
325 
326 
327 #if defined (__sun)
328 # include <strings.h>
329 # include <memory.h>
330 # if defined ( __cplusplus )
331  // typedef unsigned int size_t;
332  extern "C" {
333  extern void *memmove(void *, const void *, size_t);
334  }
335 # else
336  extern void *memmove(void *, const void *, size_t);
337 # endif // __cplusplus
338 
339 # if !defined( __GNUC__ )
340 # define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
341 # endif
342 
343 #endif // sun
344 
345 //
346 // Intel C++ Compiler
347 //
348 #if defined(__ICC) || defined (__ECC)
349 # define SG_NAMESPACES
350 # define SG_HAVE_STD
351 # define SG_HAVE_STREAMBUF
352 # define SG_HAVE_TRAITS
353 # define SG_HAVE_STD_INCLUDES
354 
355 # define STL_ALGORITHM <algorithm>
356 # define STL_FUNCTIONAL <functional>
357 # define STL_IOMANIP <iomanip>
358 # define STL_IOSTREAM <iostream>
359 # define STL_ITERATOR <iterator>
360 # define STL_FSTREAM <fstream>
361 # define STL_STDEXCEPT <stdexcept>
362 # define STL_STRING <string>
363 # define STL_STRSTREAM <strstream>
364 
365 # define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
366 
367 #endif // __ICC
368 
369 //
370 // Platform dependent gl.h and glut.h definitions
371 //
372 
373 #ifdef __APPLE__
374 # define SG_GL_H <OpenGL/gl.h>
375 # define SG_GLX_H <AGL/agl.h>
376 # define SG_GLU_H <OpenGL/glu.h>
377 # define SG_GLEXT_H <OpenGL/glext.h>
378 # define SG_GLUT_H <GLUT/glut.h>
379 
380 inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
381 #else
382 # define SG_GL_H <GL/gl.h>
383 # define SG_GLX_H <GL/glx.h>
384 # define SG_GLU_H <GL/glu.h>
385 # define SG_GLEXT_H <GL/glext.h>
386 # define SG_GLUT_H <GL/glut.h>
387 #endif
388 
389 
390 //
391 // No user modifiable definitions beyond here.
392 //
393 
394 #ifdef SG_NEED_EXPLICIT
395 # define explicit
396 #endif
397 
398 #ifdef SG_NEED_TYPENAME
399 # define typename
400 #endif
401 
402 #ifdef SG_NEED_MUTABLE
403 # define mutable
404 #endif
405 
406 #ifdef SG_NEED_BOOL
407  typedef int bool;
408 # define true 1
409 # define false 0
410 #endif
411 
412 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
413 # define SG_NULL_TMPL_ARGS <>
414 #else
415 # define SG_NULL_TMPL_ARGS
416 #endif
417 
418 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
419 # define SG_TEMPLATE_NULL template<>
420 #else
421 # define SG_TEMPLATE_NULL
422 #endif
423 
424 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
425 // without having to edit library headers.
426 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
427 # define SG_NAMESPACE(X) namespace X {
428 # define SG_NAMESPACE_END }
429 # define SG_USING_NAMESPACE(X) using namespace X
430 # else
431 # define SG_NAMESPACE(X)
432 # define SG_NAMESPACE_END
433 # define SG_USING_NAMESPACE(X)
434 #endif
435 
436 /** \def SG_USING_STD(x)
437  * Expands to using std::x if SG_HAVE_STD is defined
438  */
439 # ifdef SG_HAVE_STD
440 # define SG_USING_STD(X) using std::X
441 # define STD std
442 # else
443 # define SG_USING_STD(X)
444 # define STD
445 # endif
446 
447 // Additional <functional> implementation from SGI STL 3.11
448 // Adapter function objects: pointers to member functions
449 #ifdef SG_INCOMPLETE_FUNCTIONAL
450 
451 template <class _Ret, class _Tp>
452 class const_mem_fun_ref_t
453 #ifndef __BORLANDC__
454  : public unary_function<_Tp,_Ret>
455 #endif // __BORLANDC__
456 {
457 public:
458  explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
459  _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
460 private:
461  _Ret (_Tp::*_M_f)() const;
462 };
463 
464 template <class _Ret, class _Tp>
465 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
466  { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
467 
468 #endif // SG_INCOMPLETE_FUNCTIONAL
469 
470 #endif // _SG_COMPILER_H
471