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