]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Various mingwin patches contributed by Norman Vine.
[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 #ifdef __GNUC__
75 #  if __GNUC__ == 2 
76 #    if __GNUC_MINOR__ < 8
77
78        // g++-2.7.x
79 #      define STL_ALGORITHM  <algorithm>
80 #      define STL_FUNCTIONAL <functional>
81 #      define STL_IOMANIP    <iomanip.h>
82 #      define STL_IOSTREAM   <iostream.h>
83 #      define STL_ITERATOR   <iterator.h>
84 #      define STL_FSTREAM    <fstream.h>
85 #      define STL_STDEXCEPT  <stdexcept>
86 #      define STL_STRING     <string>
87 #      define STL_STRSTREAM  <strstream.h>
88
89 #      define SG_NEED_AUTO_PTR
90 #      define SG_NO_DEFAULT_TEMPLATE_ARGS
91 #      define SG_INCOMPLETE_FUNCTIONAL
92 #      define SG_NO_ARROW_OPERATOR
93
94 #    elif __GNUC_MINOR__ >= 8
95
96        // g++-2.8.x and egcs-1.x
97 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
98 #      define SG_NEED_AUTO_PTR
99 #      define SG_MEMBER_TEMPLATES
100 #      define SG_NAMESPACES
101 #      define SG_HAVE_STD
102 #      define SG_HAVE_STREAMBUF
103 #      define SG_CLASS_PARTIAL_SPECIALIZATION
104
105 #      define STL_ALGORITHM  <algorithm>
106 #      define STL_FUNCTIONAL <functional>
107 #      define STL_IOMANIP    <iomanip>
108 #      define STL_IOSTREAM   <iostream>
109 #      define STL_ITERATOR   <iterator>
110 #      define STL_FSTREAM    <fstream>
111 #      define STL_STDEXCEPT  <stdexcept>
112 #      define STL_STRING     <string>
113 #      define STL_STRSTREAM  <strstream>
114
115 #    endif
116 #  elif __GNUC__ == 3
117        // g++-3.0.x
118 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
119 #      define SG_NEED_AUTO_PTR
120 #      define SG_MEMBER_TEMPLATES
121 #      define SG_NAMESPACES
122 #      define SG_HAVE_STD
123 #      define SG_HAVE_STREAMBUF
124 #      define SG_CLASS_PARTIAL_SPECIALIZATION
125 #      define SG_HAVE_STD_INCLUDES
126
127 #      define STL_ALGORITHM  <algorithm>
128 #      define STL_FUNCTIONAL <functional>
129 #      define STL_IOMANIP    <iomanip>
130 #      define STL_IOSTREAM   <iostream>
131 #      define STL_ITERATOR   <iterator>
132 #      define STL_FSTREAM    <fstream>
133 #      define STL_STDEXCEPT  <stdexcept>
134 #      define STL_STRING     <string>
135 #      define STL_STRSTREAM  <strstream>
136
137 #  else
138 #    error Time to upgrade. GNU compilers < 2.7 not supported
139 #  endif
140 #endif
141
142 #if defined( __MINGW32__ )
143 #  define bcopy(from, to, n) memcpy(to, from, n)
144 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
145 #endif
146
147 /* KAI C++ */
148 #if defined(__KCC)
149
150 #  define SG_NAMESPACES
151 #  define SG_HAVE_STD
152 #  define SG_HAVE_STREAMBUF
153 #  define SG_HAVE_TRAITS
154 #  define SG_HAVE_STD_INCLUDES
155
156 #  define STL_ALGORITHM  <algorithm>
157 #  define STL_FUNCTIONAL <functional>
158 #  define STL_IOMANIP    <iomanip>
159 #  define STL_IOSTREAM   <iostream>
160 #  define STL_ITERATOR   <iterator>
161 #  define STL_FSTREAM    <fstream>
162 #  define STL_STDEXCEPT  <stdexcept>
163 #  define STL_STRING     <string>
164 #  define STL_STRSTREAM  <strstream>
165 #endif
166
167 //
168 // Metrowerks 
169 //
170 #if defined(__MWERKS__)
171 /*
172   CodeWarrior compiler from Metrowerks, Inc.
173 */
174 #  define SG_HAVE_TRAITS
175 #  define SG_HAVE_STD_INCLUDES
176 #  define SG_HAVE_STD
177 #  define SG_NAMESPACES
178
179 #  define STL_ALGORITHM  <algorithm>
180 #  define STL_FUNCTIONAL <functional>
181 #  define STL_IOMANIP    <iomanip>
182 #  define STL_IOSTREAM   <iostream>
183 #  define STL_ITERATOR   <iterator>
184 #  define STL_FSTREAM    <fstream>
185 #  define STL_STDEXCEPT  <stdexcept>
186 #  define STL_STRING     <string>
187
188 // Temp:
189 #  define bcopy(from, to, n) memcpy(to, from, n)
190
191 // -rp- please use FG_MEM_COPY everywhere !
192 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
193
194 // -dw- currently used glut has no game mode stuff
195 #  define GLUT_WRONG_VERSION
196 #endif
197
198 //
199 // Microsoft compilers.
200 //
201 #ifdef _MSC_VER
202 #  define bcopy(from, to, n) memcpy(to, from, n)
203 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
204
205 #  if _MSC_VER == 1200  // msvc++ 6.0
206 #    define SG_NAMESPACES
207 #    define SG_HAVE_STD
208 #    define SG_HAVE_STD_INCLUDES
209 #    define SG_HAVE_STREAMBUF
210
211 #    define STL_ALGORITHM  <algorithm>
212 #    define STL_FUNCTIONAL <functional>
213 #    define STL_IOMANIP    <iomanip>
214 #    define STL_IOSTREAM   <iostream>
215 #    define STL_ITERATOR   <iterator>
216 #    define STL_FSTREAM    <fstream>
217 #    define STL_STDEXCEPT  <stdexcept>
218 #    define STL_STRING     <string>
219 #    define STL_STRSTREAM  <strstream>
220
221 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
222 #    pragma warning(disable: 4244) // conversion from double to float
223 #    pragma warning(disable: 4305) //
224 #  else
225 #    error What version of MSVC++ is this?
226 #  endif
227 #endif
228
229 #ifdef __BORLANDC__
230 # if defined(HAVE_SGI_STL_PORT)
231
232 // Use quotes around long file names to get around Borland's include hackery
233
234 #  define STL_ALGORITHM  "algorithm"
235 #  define STL_FUNCTIONAL "functional"
236
237 #  define SG_MATH_EXCEPTION_CLASH
238
239 # else
240
241 #  define STL_ALGORITHM  <algorithm>
242 #  define STL_FUNCTIONAL <functional>
243 #  define STL_IOMANIP    <iomanip>
244 #  define STL_STDEXCEPT  <stdexcept>
245 #  define STL_STRSTREAM  <strstream>
246
247 #  define SG_INCOMPLETE_FUNCTIONAL
248
249 # endif // HAVE_SGI_STL_PORT
250
251 #  define STL_IOSTREAM   <iostream>
252 #  define STL_ITERATOR   <iterator>
253 #  define STL_FSTREAM    <fstream>
254 #  define STL_STRING     <string>
255 #  define SG_NO_DEFAULT_TEMPLATE_ARGS
256 #  define SG_NAMESPACES
257 // #  define SG_HAVE_STD
258
259 #endif // __BORLANDC__
260
261 //
262 // Native SGI compilers
263 //
264
265 #if defined ( sgi ) && !defined( __GNUC__ )
266 #  define SG_HAVE_NATIVE_SGI_COMPILERS
267
268 #  define SG_EXPLICIT_FUNCTION_TMPL_ARGS
269 #  define SG_NEED_AUTO_PTR
270 #  define SG_MEMBER_TEMPLATES
271 #  define SG_NAMESPACES
272 #  define SG_HAVE_STD
273 #  define SG_CLASS_PARTIAL_SPECIALIZATION
274 #  define SG_HAVE_TRAITS
275
276 #  define STL_ALGORITHM  <algorithm>
277 #  define STL_FUNCTIONAL <functional>
278 #  define STL_IOMANIP    <iomanip.h>
279 #  define STL_IOSTREAM   <iostream.h>
280 #  define STL_ITERATOR   <iterator.h>
281 #  define STL_FSTREAM    <fstream.h>
282 #  define STL_STDEXCEPT  <stdexcept>
283 #  define STL_STRING     <string>
284 #  define STL_STRSTREAM  <strstream.h>
285
286 // #  define __STL_FUNCTION_TMPL_PARTIAL_ORDER
287 // typedef void PFNGLPOINTPARAMETERFEXTPROC
288
289 #define glPointParameterfEXT    glPointParameterfSGIS
290 #define glPointParameterfvEXT   glPointParameterfvSGIS
291
292 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
293 #pragma set woff 1401,1460,1551,1552,1681
294
295 #ifdef __cplusplus
296 #pragma set woff 1682,3303
297 #endif
298
299 #endif // Native SGI compilers
300
301
302 #if defined ( sun )
303 #  include <strings.h>
304 #  include <memory.h>
305 #  if defined ( __cplusplus )
306      // typedef unsigned int size_t;
307      extern "C" {
308        extern void *memmove(void *, const void *, size_t);
309      }
310 #  else
311      extern void *memmove(void *, const void *, size_t);
312 #  endif // __cplusplus
313 #endif // sun
314
315 //
316 // Intel C++ Compiler
317 //
318 #if defined(__ICC)
319 #  define SG_NAMESPACES
320 #  define SG_HAVE_STD
321 #  define SG_HAVE_STREAMBUF
322 #  define SG_HAVE_TRAITS
323 #  define SG_HAVE_STD_INCLUDES
324
325 #  define STL_ALGORITHM  <algorithm>
326 #  define STL_FUNCTIONAL <functional>
327 #  define STL_IOMANIP    <iomanip>
328 #  define STL_IOSTREAM   <iostream>
329 #  define STL_ITERATOR   <iterator>
330 #  define STL_FSTREAM    <fstream>
331 #  define STL_STDEXCEPT  <stdexcept>
332 #  define STL_STRING     <string>
333 #  define STL_STRSTREAM  <strstream>
334 #endif // __ICC
335
336 //
337 // No user modifiable definitions beyond here.
338 //
339
340 #ifdef SG_NEED_EXPLICIT
341 #  define explicit
342 #endif
343
344 #ifdef SG_NEED_TYPENAME
345 #  define typename
346 #endif
347
348 #ifdef SG_NEED_MUTABLE
349 #  define mutable
350 #endif
351
352 #ifdef SG_NEED_BOOL
353    typedef int bool;
354 #  define true 1
355 #  define false 0
356 #endif
357
358 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
359 #  define SG_NULL_TMPL_ARGS <>
360 #else
361 #  define SG_NULL_TMPL_ARGS
362 #endif
363
364 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
365 # define SG_TEMPLATE_NULL template<>
366 #else
367 # define SG_TEMPLATE_NULL
368 #endif
369
370 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
371 // without having to edit library headers.
372 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
373 #   define SG_NAMESPACE(X) namespace X {
374 #   define SG_NAMESPACE_END }
375 #   define SG_USING_NAMESPACE(X) using namespace X
376 # else
377 #   define SG_NAMESPACE(X)
378 #   define SG_NAMESPACE_END
379 #   define SG_USING_NAMESPACE(X)
380 #endif
381
382 /** \def SG_USING_STD(x)
383  *  Expands to using std::x if SG_HAVE_STD is defined 
384  */
385 # ifdef SG_HAVE_STD
386 #  define SG_USING_STD(X) using std::X
387 #  define STD std
388 # else
389 #  define SG_USING_STD(X) 
390 #  define STD
391 # endif
392
393 // Additional <functional> implementation from SGI STL 3.11
394 // Adapter function objects: pointers to member functions
395 #ifdef SG_INCOMPLETE_FUNCTIONAL
396
397 template <class _Ret, class _Tp>
398 class const_mem_fun_ref_t
399 #ifndef __BORLANDC__
400     : public unary_function<_Tp,_Ret>
401 #endif // __BORLANDC__
402 {
403 public:
404   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
405   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
406 private:
407   _Ret (_Tp::*_M_f)() const;
408 };
409
410 template <class _Ret, class _Tp>
411 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
412   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
413
414 #endif // SG_INCOMPLETE_FUNCTIONAL
415
416 #endif // _SG_COMPILER_H