]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Name space tweaks.
[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  * What this file does.
26  *
27  *  (1)  Defines macros for some STL includes which may be affected
28  *       by file name length limitations.
29  *
30  *  (2)  Defines macros for some features not supported by all C++ compilers.
31  *
32  *  (3)  Defines 'explicit' as a null macro if the compiler doesn't support
33  *       the explicit keyword.
34  *
35  *  (4)  Defines 'typename' as a null macro if the compiler doesn't support
36  *       the typename keyword.
37  *
38  *  (5)  Defines bool, true and false if the compiler doesn't do so.
39  *
40  *  (6)  Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
41  *       supports calling a function template by providing its template
42  *       arguments explicitly.
43  *
44  *  (7)  Defines FG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
45  *
46  *  (8)  Defines FG_NO_ARROW_OPERATOR if the compiler is unable
47  *       to support operator->() for iterators.
48  *
49  *  (9)  Defines FG_USE_EXCEPTIONS if the compiler supports exceptions.
50  *       Note: no FlightGear code uses exceptions.
51  *
52  *  (10) Define FG_NAMESPACES if the compiler supports namespaces.
53  *
54  *  (11) FG_MATH_FN_IN_NAMESPACE_STD -- not used??
55  *
56  *  (12) Define FG_HAVE_STD if std namespace is supported.
57  *
58  *  (13) Defines FG_CLASS_PARTIAL_SPECIALIZATION if the compiler 
59  *       supports partial specialization of class templates.
60  *
61  *  (14) Defines FG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
62  *
63  *  (15) Defines FG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
64  *
65  *  (16) Define FG_MATH_EXCEPTION_CLASH if math.h defines an exception class
66  *       that clashes with the one defined in <stdexcept>.
67  */
68
69 #ifndef _SG_COMPILER_H
70 #define _SG_COMPILER_H
71
72 #ifdef __GNUC__
73 #  if __GNUC__ == 2 
74 #    if __GNUC_MINOR__ < 8
75
76        // g++-2.7.x
77 #      define STL_ALGORITHM  <algorithm>
78 #      define STL_FUNCTIONAL <functional>
79 #      define STL_IOMANIP    <iomanip.h>
80 #      define STL_IOSTREAM   <iostream.h>
81 #      define STL_FSTREAM    <fstream.h>
82 #      define STL_STDEXCEPT  <stdexcept>
83 #      define STL_STRING     <string>
84 #      define STL_STRSTREAM  <strstream.h>
85
86 #      define FG_NEED_AUTO_PTR
87 #      define FG_NO_DEFAULT_TEMPLATE_ARGS
88 #      define FG_INCOMPLETE_FUNCTIONAL
89 #      define FG_NO_ARROW_OPERATOR
90
91 #    elif __GNUC_MINOR__ >= 8
92
93        // g++-2.8.x and egcs-1.x
94 #      define SG_EXPLICIT_FUNCTION_TMPL_ARGS
95 #      define FG_NEED_AUTO_PTR
96 #      define FG_MEMBER_TEMPLATES
97 #      define FG_NAMESPACES
98 #      define FG_HAVE_STD
99 #      define FG_HAVE_STREAMBUF
100 #      define FG_CLASS_PARTIAL_SPECIALIZATION
101
102 #      define STL_ALGORITHM  <algorithm>
103 #      define STL_FUNCTIONAL <functional>
104 #      define STL_IOMANIP    <iomanip>
105 #      define STL_IOSTREAM   <iostream>
106 #      define STL_FSTREAM    <fstream>
107 #      define STL_STDEXCEPT  <stdexcept>
108 #      define STL_STRING     <string>
109 #      define STL_STRSTREAM  <strstream>
110
111 #    endif
112 #  else
113 #    error Time to upgrade. GNU compilers < 2.7 not supported
114 #  endif
115 #endif
116
117 /* KAI C++ */
118 #if defined(__KCC)
119
120 #  define FG_NAMESPACES
121 #  define FG_HAVE_STD
122 #  define FG_HAVE_STREAMBUF
123 #  define FG_HAVE_TRAITS
124 #  define FG_HAVE_STD_INCLUDES
125
126 #  define STL_ALGORITHM  <algorithm>
127 #  define STL_FUNCTIONAL <functional>
128 #  define STL_IOMANIP    <iomanip>
129 #  define STL_IOSTREAM   <iostream>
130 #  define STL_FSTREAM    <fstream>
131 #  define STL_STDEXCEPT  <stdexcept>
132 #  define STL_STRING     <string>
133 #  define STL_STRSTREAM  <strstream>
134 #endif
135
136 //
137 // Metrowerks 
138 //
139 #if defined(__MWERKS__)
140 /*
141   CodeWarrior compiler from Metrowerks, Inc.
142 */
143 #  define FG_HAVE_TRAITS
144 #  define FG_HAVE_STD_INCLUDES
145 #  define FG_HAVE_STD
146 #  define FG_NAMESPACES
147
148 #  define STL_ALGORITHM  <algorithm>
149 #  define STL_FUNCTIONAL <functional>
150 #  define STL_IOMANIP    <iomanip>
151 #  define STL_IOSTREAM   <iostream>
152 #  define STL_FSTREAM    <fstream>
153 #  define STL_STDEXCEPT  <stdexcept>
154 #  define STL_STRING     <string>
155
156 // Temp:
157 #  define bcopy(from, to, n) memcpy(to, from, n)
158
159 // -rp- please use FG_MEM_COPY everywhere !
160 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
161
162 // -dw- currently used glut has no game mode stuff
163 #  define GLUT_WRONG_VERSION
164 #endif
165
166 //
167 // Microsoft compilers.
168 //
169 #ifdef _MSC_VER
170 #  define bcopy(from, to, n) memcpy(to, from, n)
171 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
172
173 #  if _MSC_VER == 1200  // msvc++ 6.0
174 #    define FG_NAMESPACES
175 #    define FG_HAVE_STD
176 #    define FG_HAVE_STD_INCLUDES
177 #    define FG_HAVE_STREAMBUF
178
179 #    define STL_ALGORITHM  <algorithm>
180 #    define STL_FUNCTIONAL <functional>
181 #    define STL_IOMANIP    <iomanip>
182 #    define STL_IOSTREAM   <iostream>
183 #    define STL_FSTREAM    <fstream>
184 #    define STL_STDEXCEPT  <stdexcept>
185 #    define STL_STRING     <string>
186 #    define STL_STRSTREAM  <strstream>
187
188 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
189 #    pragma warning(disable: 4244) // conversion from double to float
190 #    pragma warning(disable: 4305) //
191
192 #  elif _MSC_VER == 1100 // msvc++ 5.0
193 #    define NEEDNAMESPACESTD
194 #    define FG_NAMESPACES
195 #    define FG_HAVE_STD
196 #    define FG_HAVE_STD_INCLUDES
197 #    define FG_HAVE_STREAMBUF
198
199 #    define STL_ALGORITHM  <algorithm>
200 #    define STL_FUNCTIONAL <functional>
201 #    define STL_IOMANIP    <iomanip>
202 #    define STL_IOSTREAM   <iostream>
203 #    define STL_FSTREAM    <fstream>
204 #    define STL_STDEXCEPT  <stdexcept>
205 #    define STL_STRING     <string>
206 #    define STL_STRSTREAM  <strstream>
207
208 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
209 #    pragma warning(disable: 4244) // conversion from double to float
210 #    pragma warning(disable: 4305) //
211
212 #  else
213 #    error What version of MSVC++ is this?
214 #  endif
215 #endif
216
217 #ifdef __BORLANDC__
218 # if defined(HAVE_SGI_STL_PORT)
219
220 // Use quotes around long file names to get around Borland's include hackery
221
222 #  define STL_ALGORITHM  "algorithm"
223 #  define STL_FUNCTIONAL "functional"
224
225 #  define FG_MATH_EXCEPTION_CLASH
226
227 # else
228
229 #  define STL_ALGORITHM  <algorithm>
230 #  define STL_FUNCTIONAL <functional>
231 #  define STL_IOMANIP    <iomanip>
232 #  define STL_STDEXCEPT  <stdexcept>
233 #  define STL_STRSTREAM  <strstream>
234
235 #  define FG_INCOMPLETE_FUNCTIONAL
236
237 # endif // HAVE_SGI_STL_PORT
238
239 #  define STL_IOSTREAM   <iostream>
240 #  define STL_FSTREAM    <fstream>
241 #  define STL_STRING     <string>
242 #  define FG_NO_DEFAULT_TEMPLATE_ARGS
243 #  define FG_NAMESPACES
244 // #  define FG_HAVE_STD
245
246 #endif // __BORLANDC__
247
248 //
249 // Native SGI compilers
250 //
251
252 #if defined ( sgi ) && !defined( __GNUC__ )
253 #  define FG_HAVE_NATIVE_SGI_COMPILERS
254
255 #  define SG_EXPLICIT_FUNCTION_TMPL_ARGS
256 #  define FG_NEED_AUTO_PTR
257 #  define FG_MEMBER_TEMPLATES
258 #  define FG_NAMESPACES
259 #  define FG_HAVE_STD
260 #  define FG_CLASS_PARTIAL_SPECIALIZATION
261 #  define FG_HAVE_TRAITS
262
263 #  define STL_ALGORITHM  <algorithm>
264 #  define STL_FUNCTIONAL <functional>
265 #  define STL_IOMANIP    <iomanip.h>
266 #  define STL_IOSTREAM   <iostream.h>
267 #  define STL_FSTREAM    <fstream.h>
268 #  define STL_STDEXCEPT  <stdexcept>
269 #  define STL_STRING     <string>
270 #  define STL_STRSTREAM  <strstream>
271
272 #endif // Native SGI compilers
273
274
275 #if defined ( sun )
276 #  include <strings.h>
277 #  include <memory.h>
278 #  if defined ( __cplusplus )
279      // typedef unsigned int size_t;
280      extern "C" {
281        extern void *memmove(void *, const void *, size_t);
282      }
283 #  else
284      extern void *memmove(void *, const void *, size_t);
285 #  endif // __cplusplus
286 #endif // sun
287
288 //
289 // No user modifiable definitions beyond here.
290 //
291
292 #ifdef FG_NEED_EXPLICIT
293 #  define explicit
294 #endif
295
296 #ifdef FG_NEED_TYPENAME
297 #  define typename
298 #endif
299
300 #ifdef FG_NEED_MUTABLE
301 #  define mutable
302 #endif
303
304 #ifdef FG_NEED_BOOL
305    typedef int bool;
306 #  define true 1
307 #  define false 0
308 #endif
309
310 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
311 #  define FG_NULL_TMPL_ARGS <>
312 #else
313 #  define FG_NULL_TMPL_ARGS
314 #endif
315
316 #ifdef FG_CLASS_PARTIAL_SPECIALIZATION
317 # define FG_TEMPLATE_NULL template<>
318 #else
319 # define FG_TEMPLATE_NULL
320 #endif
321
322 // FG_NO_NAMESPACES is a hook so that users can disable namespaces
323 // without having to edit library headers.
324 #if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
325 #   define FG_NAMESPACE(X) namespace X {
326 #   define FG_NAMESPACE_END }
327 #   define FG_USING_NAMESPACE(X) using namespace X
328 # else
329 #   define FG_NAMESPACE(X)
330 #   define FG_NAMESPACE_END
331 #   define FG_USING_NAMESPACE(X)
332 #endif
333
334 # ifdef FG_HAVE_STD
335 #  define FG_USING_STD(X) using std::X
336 #  define STD std
337 # else
338 #  define FG_USING_STD(X) 
339 #  define STD
340 # endif
341
342 // Additional <functional> implementation from SGI STL 3.11
343 // Adapter function objects: pointers to member functions
344 #ifdef FG_INCOMPLETE_FUNCTIONAL
345
346 template <class _Ret, class _Tp>
347 class const_mem_fun_ref_t
348 #ifndef __BORLANDC__
349     : public unary_function<_Tp,_Ret>
350 #endif // __BORLANDC__
351 {
352 public:
353   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
354   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
355 private:
356   _Ret (_Tp::*_M_f)() const;
357 };
358
359 template <class _Ret, class _Tp>
360 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
361   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
362
363 #endif // FG_INCOMPLETE_FUNCTIONAL
364
365 #endif // _SG_COMPILER_H