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