]> git.mxchange.org Git - flightgear.git/blob - src/Include/compiler.h
Removed extra square array of indirection indices between what's visible
[flightgear.git] / src / Include / 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_STDEXCEPT  <stdexcept>
61 #      define STL_STRING     <string>
62 #      define STL_STRSTREAM  <strstream.h>
63
64 #      define FG_NEED_AUTO_PTR
65 #      define FG_NO_DEFAULT_TEMPLATE_ARGS
66 #      define FG_INCOMPLETE_FUNCTIONAL
67 #      define FG_NO_ARROW_OPERATOR
68
69 #    elif __GNUC_MINOR__ >= 8
70
71        // g++-2.8.x and egcs-1.x
72 #      define FG_EXPLICIT_FUNCTION_TMPL_ARGS
73 #      define FG_NEED_AUTO_PTR
74 #      define FG_MEMBER_TEMPLATES
75 #      define FG_NAMESPACES
76 #      define FG_HAVE_STD
77 #      define FG_HAVE_STREAMBUF
78 #      define FG_CLASS_PARTIAL_SPECIALIZATION
79
80 #      define STL_ALGORITHM  <algorithm>
81 #      define STL_FUNCTIONAL <functional>
82 #      define STL_IOMANIP    <iomanip>
83 #      define STL_IOSTREAM   <iostream>
84 #      define STL_STDEXCEPT  <stdexcept>
85 #      define STL_STRING     <string>
86 #      define STL_STRSTREAM  <strstream>
87
88 #    endif
89 #  else
90 #    error Time to upgrade. GNU compilers < 2.7 not supported
91 #  endif
92 #endif
93
94 //
95 // Metrowerks 
96 //
97 #if defined(__MWERKS__)
98 /*
99   CodeWarrior compiler from Metrowerks, Inc.
100 */
101 #  define FG_HAVE_TRAITS
102 #  define FG_HAVE_STD_INCLUDES
103 #  define FG_HAVE_STD
104 #  define FG_NAMESPACES
105
106 #  define STL_ALGORITHM  <algorithm>
107 #  define STL_FUNCTIONAL <functional>
108 #  define STL_IOMANIP    <iomanip>
109 #  define STL_IOSTREAM   <iostream>
110 #  define STL_STDEXCEPT  <stdexcept>
111 #  define STL_STRING     <string>
112
113 // Temp:
114 #  define bcopy(from, to, n) memcpy(to, from, n)
115
116 // -rp- please use FG_MEM_COPY everywhere !
117 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
118
119 // -dw- currently used glut has no game mode stuff
120 #  define GLUT_WRONG_VERSION
121 #endif
122
123 //
124 // Microsoft compilers.
125 //
126 #ifdef _MSC_VER
127 #  if _MSC_VER == 1200 // msvc++ 6.0
128 #    define FG_NAMESPACES
129 #    define FG_HAVE_STD
130 #    define FG_HAVE_STD_INCLUDES
131 #    define FG_HAVE_STREAMBUF
132
133 #    define STL_ALGORITHM  <algorithm>
134 #    define STL_FUNCTIONAL <functional>
135 #    define STL_IOMANIP    <iomanip>
136 #    define STL_IOSTREAM   <iostream>
137 #    define STL_STDEXCEPT  <stdexcept>
138 #    define STL_STRING     <string>
139 #    define STL_STRSTREAM  <strstream>
140
141 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
142 #    pragma warning(disable: 4244) // conversion from double to float
143 #    pragma warning(disable: 4305) //
144
145 #  elif _MSC_VER == 1100 // msvc++ 5.0
146 #    error MSVC++ 5.0 still to be supported...
147 #  else
148 #    error What version of MSVC++ is this?
149 #  endif
150 #endif
151
152 #ifdef __BORLANDC__
153 # if defined(HAVE_SGI_STL_PORT)
154
155 // Use quotes around long file names to get around Borland's include hackery
156
157 #  define STL_ALGORITHM  "algorithm"
158 #  define STL_FUNCTIONAL "functional"
159
160 #  define FG_MATH_EXCEPTION_CLASH
161
162 # else
163
164 #  define STL_ALGORITHM  <algorithm>
165 #  define STL_FUNCTIONAL <functional>
166 #  define STL_IOMANIP    <iomanip>
167 #  define STL_STDEXCEPT  <stdexcept>
168 #  define STL_STRSTREAM  <strstream>
169
170 #  define FG_INCOMPLETE_FUNCTIONAL
171
172 # endif // HAVE_SGI_STL_PORT
173
174 #  define STL_IOSTREAM   <iostream>
175 #  define STL_STRING     <string>
176 #  define FG_NO_DEFAULT_TEMPLATE_ARGS
177 #  define FG_NAMESPACES
178 // #  define FG_HAVE_STD
179
180 #endif // __BORLANDC__
181
182 //
183 // Native SGI compilers
184 //
185
186 #if defined ( sgi ) && !defined( __GNUC__ )
187 #  define FG_HAVE_NATIVE_SGI_COMPILERS
188
189 #  define FG_EXPLICIT_FUNCTION_TMPL_ARGS
190 #  define FG_NEED_AUTO_PTR
191 #  define FG_MEMBER_TEMPLATES
192 #  define FG_NAMESPACES
193 #  define FG_HAVE_STD
194 #  define FG_CLASS_PARTIAL_SPECIALIZATION
195
196 #  define STL_ALGORITHM  <algorithm>
197 #  define STL_FUNCTIONAL <functional>
198 #  define STL_IOMANIP    <iomanip>
199 #  define STL_IOSTREAM   <iostream.h>
200 #  define STL_STDEXCEPT  <stdexcept>
201 #  define STL_STRING     <string>
202 #  define STL_STRSTREAM  <strstream>
203
204 #endif // Native SGI compilers
205
206
207 #if defined ( sun )
208 #  include <memory.h>
209 #  if defined ( __cplusplus )
210      // typedef unsigned int size_t;
211      extern "C" {
212        extern void *memmove(void *, const void *, size_t);
213      }
214 #  else
215      extern void *memmove(void *, const void *, size_t);
216 #  endif // __cplusplus
217 #endif // sun
218
219 //
220 // No user modifiable definitions beyond here.
221 //
222
223 #ifdef FG_NEED_EXPLICIT
224 #  define explicit
225 #endif
226
227 #ifdef FG_NEED_TYPENAME
228 #  define typename
229 #endif
230
231 #ifdef FG_NEED_MUTABLE
232 #  define mutable
233 #endif
234
235 #ifdef FG_NEED_BOOL
236    typedef int bool;
237 #  define true 1
238 #  define false 0
239 #endif
240
241 #ifdef FG_EXPLICIT_FUNCTION_TMPL_ARGS
242 #  define FG_NULL_TMPL_ARGS <>
243 #else
244 #  define FG_NULL_TMPL_ARGS
245 #endif
246
247 #ifdef FG_CLASS_PARTIAL_SPECIALIZATION
248 # define FG_TEMPLATE_NULL template<>
249 #else
250 # define FG_TEMPLATE_NULL
251 #endif
252
253 // FG_NO_NAMESPACES is a hook so that users can disable namespaces
254 // without having to edit library headers.
255 #if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
256 #   define FG_NAMESPACE(X) namespace X {
257 #   define FG_NAMESPACE_END }
258 #   define FG_USING_NAMESPACE(X) using namespace X
259 # else
260 #   define FG_NAMESPACE(X)
261 #   define FG_NAMESPACE_END
262 #   define FG_USING_NAMESPACE(X)
263 #endif
264
265 # ifdef FG_HAVE_STD
266 #  define FG_USING_STD(X) using std::X
267 #  define STD std
268 # else
269 #  define FG_USING_STD(X) 
270 #  define STD
271 # endif
272
273 // Additional <functional> implementation from SGI STL 3.11
274 // Adapter function objects: pointers to member functions
275 #ifdef FG_INCOMPLETE_FUNCTIONAL
276
277 template <class _Ret, class _Tp>
278 class const_mem_fun_ref_t
279 #ifndef __BORLANDC__
280     : public unary_function<_Tp,_Ret>
281 #endif // __BORLANDC__
282 {
283 public:
284   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
285   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
286 private:
287   _Ret (_Tp::*_M_f)() const;
288 };
289
290 template <class _Ret, class _Tp>
291 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
292   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
293
294 #endif // FG_INCOMPLETE_FUNCTIONAL
295
296 #endif // _COMPILER_H