]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
eb6c162857d50e71c5ff32c89f7155b71819913e
[simgear.git] / simgear / compiler.h
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$
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
145 # ifdef WIN32
146        // keep windows.h from #defining min() max() macros
147 #      define NOMINMAX
148 #endif
149
150 #  else
151 #    error Time to upgrade. GNU compilers < 2.7 not supported
152 #  endif
153
154 #  define SG_COMPILER_STR "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
155
156 #endif // __GNUC__
157
158 #if defined( __MINGW32__ )
159 #  define bcopy(from, to, n) memcpy(to, from, n)
160 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
161 #  define snprintf _snprintf
162 #endif
163
164 /* KAI C++ */
165 #if defined(__KCC)
166
167 #  define SG_NAMESPACES
168 #  define SG_HAVE_STD
169 #  define SG_HAVE_STREAMBUF
170 #  define SG_HAVE_TRAITS
171 #  define SG_HAVE_STD_INCLUDES
172
173 #  define STL_ALGORITHM  <algorithm>
174 #  define STL_FUNCTIONAL <functional>
175 #  define STL_IOMANIP    <iomanip>
176 #  define STL_IOSTREAM   <iostream>
177 #  define STL_ITERATOR   <iterator>
178 #  define STL_FSTREAM    <fstream>
179 #  define STL_STDEXCEPT  <stdexcept>
180 #  define STL_STRING     <string>
181 #  define STL_STRSTREAM  <strstream>
182
183 #  define SG_COMPILER_STR "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
184
185 #endif // __KCC
186
187 //
188 // Metrowerks 
189 //
190 #if defined(__MWERKS__)
191 /*
192   CodeWarrior compiler from Metrowerks, Inc.
193 */
194 #  define SG_HAVE_TRAITS
195 #  define SG_HAVE_STD_INCLUDES
196 #  define SG_HAVE_STD
197 #  define SG_NAMESPACES
198
199 #  define STL_ALGORITHM  <algorithm>
200 #  define STL_FUNCTIONAL <functional>
201 #  define STL_IOMANIP    <iomanip>
202 #  define STL_IOSTREAM   <iostream>
203 #  define STL_ITERATOR   <iterator>
204 #  define STL_FSTREAM    <fstream>
205 #  define STL_STDEXCEPT  <stdexcept>
206 #  define STL_STRING     <string>
207
208 // Temp:
209 #  define bcopy(from, to, n) memcpy(to, from, n)
210
211 // -rp- please use FG_MEM_COPY everywhere !
212 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
213
214 // -dw- currently used glut has no game mode stuff
215 #  define GLUT_WRONG_VERSION
216
217 #  define SG_COMPILER_STR "Metrowerks CodeWarrior C++ version " SG_STRINGIZE(__MWERKS__)
218
219 #endif // __MWERKS__
220
221 //
222 // Microsoft compilers.
223 //
224 #ifdef _MSC_VER
225 #  define bcopy(from, to, n) memcpy(to, from, n)
226 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
227
228 #  if _MSC_VER == 1200  // msvc++ 6.0
229 #    define SG_NAMESPACES
230 #    define SG_HAVE_STD
231 #    define SG_HAVE_STD_INCLUDES
232 #    define SG_HAVE_STREAMBUF
233
234 #    define STL_ALGORITHM  <algorithm>
235 #    define STL_FUNCTIONAL <functional>
236 #    define STL_IOMANIP    <iomanip>
237 #    define STL_IOSTREAM   <iostream>
238 #    define STL_ITERATOR   <iterator>
239 #    define STL_FSTREAM    <fstream>
240 #    define STL_STDEXCEPT  <stdexcept>
241 #    define STL_STRING     <string>
242 #    define STL_STRSTREAM  <strstream>
243
244 #    define snprintf _snprintf
245
246 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
247 #    pragma warning(disable: 4244) // conversion from double to float
248 #    pragma warning(disable: 4305) //
249
250 #  else
251 #    error What version of MSVC++ is this?
252 #  endif
253
254 #    define SG_COMPILER_STR "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
255
256 #endif // _MSC_VER
257
258 #ifdef __BORLANDC__
259 # if defined(HAVE_SGI_STL_PORT)
260
261 // Use quotes around long file names to get around Borland's include hackery
262
263 #  define STL_ALGORITHM  "algorithm"
264 #  define STL_FUNCTIONAL "functional"
265
266 #  define SG_MATH_EXCEPTION_CLASH
267
268 # else
269
270 #  define STL_ALGORITHM  <algorithm>
271 #  define STL_FUNCTIONAL <functional>
272 #  define STL_IOMANIP    <iomanip>
273 #  define STL_STDEXCEPT  <stdexcept>
274 #  define STL_STRSTREAM  <strstream>
275
276 #  define SG_INCOMPLETE_FUNCTIONAL
277
278 # endif // HAVE_SGI_STL_PORT
279
280 #  define STL_IOSTREAM   <iostream>
281 #  define STL_ITERATOR   <iterator>
282 #  define STL_FSTREAM    <fstream>
283 #  define STL_STRING     <string>
284 #  define SG_NO_DEFAULT_TEMPLATE_ARGS
285 #  define SG_NAMESPACES
286 // #  define SG_HAVE_STD
287
288 #  define SG_COMPILER_STR "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
289
290 #endif // __BORLANDC__
291
292 //
293 // Native SGI compilers
294 //
295
296 #if defined ( sgi ) && !defined( __GNUC__ )
297 #  define SG_HAVE_NATIVE_SGI_COMPILERS
298
299 #  define SG_EXPLICIT_FUNCTION_TMPL_ARGS
300 #  define SG_NEED_AUTO_PTR
301 #  define SG_MEMBER_TEMPLATES
302 #  define SG_NAMESPACES
303 #  define SG_HAVE_STD
304 #  define SG_CLASS_PARTIAL_SPECIALIZATION
305 #  define SG_HAVE_TRAITS
306
307 #  define STL_ALGORITHM  <algorithm>
308 #  define STL_FUNCTIONAL <functional>
309 #  define STL_IOMANIP    <iomanip.h>
310 #  define STL_IOSTREAM   <iostream.h>
311 #  define STL_ITERATOR   <iterator.h>
312 #  define STL_FSTREAM    <fstream.h>
313 #  define STL_STDEXCEPT  <stdexcept>
314 #  define STL_STRING     <string>
315 #  define STL_STRSTREAM  <strstream.h>
316
317 // #  define __STL_FUNCTION_TMPL_PARTIAL_ORDER
318 // typedef void PFNGLPOINTPARAMETERFEXTPROC
319
320 #define glPointParameterfEXT    glPointParameterfSGIS
321 #define glPointParameterfvEXT   glPointParameterfvSGIS
322
323 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
324 #pragma set woff 1401,1460,1551,1552,1681
325
326 #ifdef __cplusplus
327 #pragma set woff 1682,3303
328 #endif
329
330 #  define SG_COMPILER_STR "SGI Irix compiler version " SG_STRINGIZE(_COMPILER_VERSION)
331
332 #endif // Native SGI compilers
333
334
335 #if defined ( sun )
336 #  include <strings.h>
337 #  include <memory.h>
338 #  if defined ( __cplusplus )
339      // typedef unsigned int size_t;
340      extern "C" {
341        extern void *memmove(void *, const void *, size_t);
342      }
343 #  else
344      extern void *memmove(void *, const void *, size_t);
345 #  endif // __cplusplus
346
347 #  define SG_COMPILER_STR "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
348
349 #endif // sun
350
351 //
352 // Intel C++ Compiler
353 //
354 #if defined(__ICC) || defined (__ECC)
355 #  define SG_NAMESPACES
356 #  define SG_HAVE_STD
357 #  define SG_HAVE_STREAMBUF
358 #  define SG_HAVE_TRAITS
359 #  define SG_HAVE_STD_INCLUDES
360
361 #  define STL_ALGORITHM  <algorithm>
362 #  define STL_FUNCTIONAL <functional>
363 #  define STL_IOMANIP    <iomanip>
364 #  define STL_IOSTREAM   <iostream>
365 #  define STL_ITERATOR   <iterator>
366 #  define STL_FSTREAM    <fstream>
367 #  define STL_STDEXCEPT  <stdexcept>
368 #  define STL_STRING     <string>
369 #  define STL_STRSTREAM  <strstream>
370
371 #  define SG_COMPILER_STR "Intel C++ version " SG_STRINGIZE(__ICC)
372
373 #endif // __ICC
374
375 //
376 // No user modifiable definitions beyond here.
377 //
378
379 #ifdef SG_NEED_EXPLICIT
380 #  define explicit
381 #endif
382
383 #ifdef SG_NEED_TYPENAME
384 #  define typename
385 #endif
386
387 #ifdef SG_NEED_MUTABLE
388 #  define mutable
389 #endif
390
391 #ifdef SG_NEED_BOOL
392    typedef int bool;
393 #  define true 1
394 #  define false 0
395 #endif
396
397 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
398 #  define SG_NULL_TMPL_ARGS <>
399 #else
400 #  define SG_NULL_TMPL_ARGS
401 #endif
402
403 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
404 # define SG_TEMPLATE_NULL template<>
405 #else
406 # define SG_TEMPLATE_NULL
407 #endif
408
409 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
410 // without having to edit library headers.
411 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
412 #   define SG_NAMESPACE(X) namespace X {
413 #   define SG_NAMESPACE_END }
414 #   define SG_USING_NAMESPACE(X) using namespace X
415 # else
416 #   define SG_NAMESPACE(X)
417 #   define SG_NAMESPACE_END
418 #   define SG_USING_NAMESPACE(X)
419 #endif
420
421 /** \def SG_USING_STD(x)
422  *  Expands to using std::x if SG_HAVE_STD is defined 
423  */
424 # ifdef SG_HAVE_STD
425 #  define SG_USING_STD(X) using std::X
426 #  define STD std
427 # else
428 #  define SG_USING_STD(X) 
429 #  define STD
430 # endif
431
432 // Additional <functional> implementation from SGI STL 3.11
433 // Adapter function objects: pointers to member functions
434 #ifdef SG_INCOMPLETE_FUNCTIONAL
435
436 template <class _Ret, class _Tp>
437 class const_mem_fun_ref_t
438 #ifndef __BORLANDC__
439     : public unary_function<_Tp,_Ret>
440 #endif // __BORLANDC__
441 {
442 public:
443   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
444   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
445 private:
446   _Ret (_Tp::*_M_f)() const;
447 };
448
449 template <class _Ret, class _Tp>
450 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
451   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
452
453 #endif // SG_INCOMPLETE_FUNCTIONAL
454
455 #endif // _SG_COMPILER_H