]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Added gdbm to SimGear. Many systems will already have gdbm installed so
[simgear.git] / simgear / compiler.h
1 /**************************************************************************
2  * compiler.h -- C++ Compiler Portability Macros
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * $Id$
19  **************************************************************************/
20
21 #ifndef _COMPILER_H
22 #define _COMPILER_H
23
24 // What this file does.
25 //  (1)  Defines macros for some STL includes which may be affected
26 //       by file name length limitations.
27 //  (2)  Defines macros for some features not supported by all C++ compilers.
28 //  (3)  Defines 'explicit' as a null macro if the compiler doesn't support
29 //       the explicit keyword.
30 //  (4)  Defines 'typename' as a null macro if the compiler doesn't support
31 //       the typename keyword.
32 //  (5)  Defines bool, true and false if the compiler doesn't do so.
33 //  (6)  Defines FG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
34 //       supports calling a function template by providing its template
35 //       arguments explicitly.
36 //  (7)  Defines FG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
37 //  (8)  Defines FG_NO_ARROW_OPERATOR if the compiler is unable
38 //       to support operator->() for iterators.
39 //  (9)  Defines FG_USE_EXCEPTIONS if the compiler supports exceptions.
40 //       Note: no FlightGear code uses exceptions.
41 //  (10) Define FG_NAMESPACES if the compiler supports namespaces.
42 //  (11) FG_MATH_FN_IN_NAMESPACE_STD -- not used??
43 //  (12) Define FG_HAVE_STD if std namespace is supported.
44 //  (13) Defines FG_CLASS_PARTIAL_SPECIALIZATION if the compiler 
45 //       supports partial specialization of class templates.
46 //  (14) Defines FG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
47 //  (15) Defines FG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
48 //  (16) Define FG_MATH_EXCEPTION_CLASH if math.h defines an exception class
49 //       that clashes with the one defined in <stdexcept>.
50
51 #ifdef __GNUC__
52 #  if __GNUC__ == 2 
53 #    if __GNUC_MINOR__ < 8
54
55        // g++-2.7.x
56 #      define STL_ALGORITHM  <algorithm>
57 #      define STL_FUNCTIONAL <functional>
58 #      define STL_IOMANIP    <iomanip.h>
59 #      define STL_IOSTREAM   <iostream.h>
60 #      define STL_FSTREAM    <fstream.h>
61 #      define STL_STDEXCEPT  <stdexcept>
62 #      define STL_STRING     <string>
63 #      define STL_STRSTREAM  <strstream.h>
64
65 #      define FG_NEED_AUTO_PTR
66 #      define FG_NO_DEFAULT_TEMPLATE_ARGS
67 #      define FG_INCOMPLETE_FUNCTIONAL
68 #      define FG_NO_ARROW_OPERATOR
69
70 #    elif __GNUC_MINOR__ >= 8
71
72        // g++-2.8.x and egcs-1.x
73 #      define FG_EXPLICIT_FUNCTION_TMPL_ARGS
74 #      define FG_NEED_AUTO_PTR
75 #      define FG_MEMBER_TEMPLATES
76 #      define FG_NAMESPACES
77 #      define FG_HAVE_STD
78 #      define FG_HAVE_STREAMBUF
79 #      define FG_CLASS_PARTIAL_SPECIALIZATION
80
81 #      define STL_ALGORITHM  <algorithm>
82 #      define STL_FUNCTIONAL <functional>
83 #      define STL_IOMANIP    <iomanip>
84 #      define STL_IOSTREAM   <iostream>
85 #      define STL_FSTREAM    <fstream>
86 #      define STL_STDEXCEPT  <stdexcept>
87 #      define STL_STRING     <string>
88 #      define STL_STRSTREAM  <strstream>
89
90 #    endif
91 #  else
92 #    error Time to upgrade. GNU compilers < 2.7 not supported
93 #  endif
94 #endif
95
96 //
97 // Metrowerks 
98 //
99 #if defined(__MWERKS__)
100 /*
101   CodeWarrior compiler from Metrowerks, Inc.
102 */
103 #  define FG_HAVE_TRAITS
104 #  define FG_HAVE_STD_INCLUDES
105 #  define FG_HAVE_STD
106 #  define FG_NAMESPACES
107
108 #  define STL_ALGORITHM  <algorithm>
109 #  define STL_FUNCTIONAL <functional>
110 #  define STL_IOMANIP    <iomanip>
111 #  define STL_IOSTREAM   <iostream>
112 #  define STL_FSTREAM    <fstream>
113 #  define STL_STDEXCEPT  <stdexcept>
114 #  define STL_STRING     <string>
115
116 // Temp:
117 #  define bcopy(from, to, n) memcpy(to, from, n)
118
119 // -rp- please use FG_MEM_COPY everywhere !
120 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
121
122 // -dw- currently used glut has no game mode stuff
123 #  define GLUT_WRONG_VERSION
124 #endif
125
126 //
127 // Microsoft compilers.
128 //
129 #ifdef _MSC_VER
130 #  if _MSC_VER == 1200 // msvc++ 6.0
131 #    define FG_NAMESPACES
132 #    define FG_HAVE_STD
133 #    define FG_HAVE_STD_INCLUDES
134 #    define FG_HAVE_STREAMBUF
135
136 #    define STL_ALGORITHM  <algorithm>
137 #    define STL_FUNCTIONAL <functional>
138 #    define STL_IOMANIP    <iomanip>
139 #    define STL_IOSTREAM   <iostream>
140 #    define STL_FSTREAM    <fstream>
141 #    define STL_STDEXCEPT  <stdexcept>
142 #    define STL_STRING     <string>
143 #    define STL_STRSTREAM  <strstream>
144
145 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
146 #    pragma warning(disable: 4244) // conversion from double to float
147 #    pragma warning(disable: 4305) //
148
149 #  elif _MSC_VER == 1100 // msvc++ 5.0
150 #    error MSVC++ 5.0 still to be supported...
151 #  else
152 #    error What version of MSVC++ is this?
153 #  endif
154 #endif
155
156 #ifdef __BORLANDC__
157 # if defined(HAVE_SGI_STL_PORT)
158
159 // Use quotes around long file names to get around Borland's include hackery
160
161 #  define STL_ALGORITHM  "algorithm"
162 #  define STL_FUNCTIONAL "functional"
163
164 #  define FG_MATH_EXCEPTION_CLASH
165
166 # else
167
168 #  define STL_ALGORITHM  <algorithm>
169 #  define STL_FUNCTIONAL <functional>
170 #  define STL_IOMANIP    <iomanip>
171 #  define STL_STDEXCEPT  <stdexcept>
172 #  define STL_STRSTREAM  <strstream>
173
174 #  define FG_INCOMPLETE_FUNCTIONAL
175
176 # endif // HAVE_SGI_STL_PORT
177
178 #  define STL_IOSTREAM   <iostream>
179 #  define STL_FSTREAM    <fstream>
180 #  define STL_STRING     <string>
181 #  define FG_NO_DEFAULT_TEMPLATE_ARGS
182 #  define FG_NAMESPACES
183 // #  define FG_HAVE_STD
184
185 #endif // __BORLANDC__
186
187 //
188 // Native SGI compilers
189 //
190
191 #if defined ( sgi ) && !defined( __GNUC__ )
192 #  define FG_HAVE_NATIVE_SGI_COMPILERS
193
194 #  define FG_EXPLICIT_FUNCTION_TMPL_ARGS
195 #  define FG_NEED_AUTO_PTR
196 #  define FG_MEMBER_TEMPLATES
197 #  define FG_NAMESPACES
198 #  define FG_HAVE_STD
199 #  define FG_CLASS_PARTIAL_SPECIALIZATION
200
201 #  define STL_ALGORITHM  <algorithm>
202 #  define STL_FUNCTIONAL <functional>
203 #  define STL_IOMANIP    <iomanip.h>
204 #  define STL_IOSTREAM   <iostream.h>
205 #  define STL_FSTREAM    <fstream.h>
206 #  define STL_STDEXCEPT  <stdexcept>
207 #  define STL_STRING     <string>
208 #  define STL_STRSTREAM  <strstream>
209
210 #endif // Native SGI compilers
211
212
213 #if defined ( sun )
214 #  include <strings.h>
215 #  include <memory.h>
216 #  if defined ( __cplusplus )
217      // typedef unsigned int size_t;
218      extern "C" {
219        extern void *memmove(void *, const void *, size_t);
220      }
221 #  else
222      extern void *memmove(void *, const void *, size_t);
223 #  endif // __cplusplus
224 #endif // sun
225
226 //
227 // No user modifiable definitions beyond here.
228 //
229
230 #ifdef FG_NEED_EXPLICIT
231 #  define explicit
232 #endif
233
234 #ifdef FG_NEED_TYPENAME
235 #  define typename
236 #endif
237
238 #ifdef FG_NEED_MUTABLE
239 #  define mutable
240 #endif
241
242 #ifdef FG_NEED_BOOL
243    typedef int bool;
244 #  define true 1
245 #  define false 0
246 #endif
247
248 #ifdef FG_EXPLICIT_FUNCTION_TMPL_ARGS
249 #  define FG_NULL_TMPL_ARGS <>
250 #else
251 #  define FG_NULL_TMPL_ARGS
252 #endif
253
254 #ifdef FG_CLASS_PARTIAL_SPECIALIZATION
255 # define FG_TEMPLATE_NULL template<>
256 #else
257 # define FG_TEMPLATE_NULL
258 #endif
259
260 // FG_NO_NAMESPACES is a hook so that users can disable namespaces
261 // without having to edit library headers.
262 #if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
263 #   define FG_NAMESPACE(X) namespace X {
264 #   define FG_NAMESPACE_END }
265 #   define FG_USING_NAMESPACE(X) using namespace X
266 # else
267 #   define FG_NAMESPACE(X)
268 #   define FG_NAMESPACE_END
269 #   define FG_USING_NAMESPACE(X)
270 #endif
271
272 # ifdef FG_HAVE_STD
273 #  define FG_USING_STD(X) using std::X
274 #  define STD std
275 # else
276 #  define FG_USING_STD(X) 
277 #  define STD
278 # endif
279
280 // Additional <functional> implementation from SGI STL 3.11
281 // Adapter function objects: pointers to member functions
282 #ifdef FG_INCOMPLETE_FUNCTIONAL
283
284 template <class _Ret, class _Tp>
285 class const_mem_fun_ref_t
286 #ifndef __BORLANDC__
287     : public unary_function<_Tp,_Ret>
288 #endif // __BORLANDC__
289 {
290 public:
291   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
292   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
293 private:
294   _Ret (_Tp::*_M_f)() const;
295 };
296
297 template <class _Ret, class _Tp>
298 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
299   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
300
301 #endif // FG_INCOMPLETE_FUNCTIONAL
302
303 #endif // _COMPILER_H