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