]> git.mxchange.org Git - simgear.git/blob - simgear/compiler.h
Still tweaking output messages.
[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 #  define bcopy(from, to, n) memcpy(to, from, n)
131 #  define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
132
133 #  if _MSC_VER == 1200  // msvc++ 6.0
134 #    define FG_NAMESPACES
135 #    define FG_HAVE_STD
136 #    define FG_HAVE_STD_INCLUDES
137 #    define FG_HAVE_STREAMBUF
138
139 #    define STL_ALGORITHM  <algorithm>
140 #    define STL_FUNCTIONAL <functional>
141 #    define STL_IOMANIP    <iomanip>
142 #    define STL_IOSTREAM   <iostream>
143 #    define STL_FSTREAM    <fstream>
144 #    define STL_STDEXCEPT  <stdexcept>
145 #    define STL_STRING     <string>
146 #    define STL_STRSTREAM  <strstream>
147
148 #    pragma warning(disable: 4786) // identifier was truncated to '255' characters
149 #    pragma warning(disable: 4244) // conversion from double to float
150 #    pragma warning(disable: 4305) //
151
152 #  elif _MSC_VER == 1100 // msvc++ 5.0
153 #    define NEEDNAMESPACESTD
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 #  else
173 #    error What version of MSVC++ is this?
174 #  endif
175 #endif
176
177 #ifdef __BORLANDC__
178 # if defined(HAVE_SGI_STL_PORT)
179
180 // Use quotes around long file names to get around Borland's include hackery
181
182 #  define STL_ALGORITHM  "algorithm"
183 #  define STL_FUNCTIONAL "functional"
184
185 #  define FG_MATH_EXCEPTION_CLASH
186
187 # else
188
189 #  define STL_ALGORITHM  <algorithm>
190 #  define STL_FUNCTIONAL <functional>
191 #  define STL_IOMANIP    <iomanip>
192 #  define STL_STDEXCEPT  <stdexcept>
193 #  define STL_STRSTREAM  <strstream>
194
195 #  define FG_INCOMPLETE_FUNCTIONAL
196
197 # endif // HAVE_SGI_STL_PORT
198
199 #  define STL_IOSTREAM   <iostream>
200 #  define STL_FSTREAM    <fstream>
201 #  define STL_STRING     <string>
202 #  define FG_NO_DEFAULT_TEMPLATE_ARGS
203 #  define FG_NAMESPACES
204 // #  define FG_HAVE_STD
205
206 #endif // __BORLANDC__
207
208 //
209 // Native SGI compilers
210 //
211
212 #if defined ( sgi ) && !defined( __GNUC__ )
213 #  define FG_HAVE_NATIVE_SGI_COMPILERS
214
215 #  define FG_EXPLICIT_FUNCTION_TMPL_ARGS
216 #  define FG_NEED_AUTO_PTR
217 #  define FG_MEMBER_TEMPLATES
218 #  define FG_NAMESPACES
219 #  define FG_HAVE_STD
220 #  define FG_CLASS_PARTIAL_SPECIALIZATION
221
222 #  define STL_ALGORITHM  <algorithm>
223 #  define STL_FUNCTIONAL <functional>
224 #  define STL_IOMANIP    <iomanip.h>
225 #  define STL_IOSTREAM   <iostream.h>
226 #  define STL_FSTREAM    <fstream.h>
227 #  define STL_STDEXCEPT  <stdexcept>
228 #  define STL_STRING     <string>
229 #  define STL_STRSTREAM  <strstream>
230
231 #endif // Native SGI compilers
232
233
234 #if defined ( sun )
235 #  include <strings.h>
236 #  include <memory.h>
237 #  if defined ( __cplusplus )
238      // typedef unsigned int size_t;
239      extern "C" {
240        extern void *memmove(void *, const void *, size_t);
241      }
242 #  else
243      extern void *memmove(void *, const void *, size_t);
244 #  endif // __cplusplus
245 #endif // sun
246
247 //
248 // No user modifiable definitions beyond here.
249 //
250
251 #ifdef FG_NEED_EXPLICIT
252 #  define explicit
253 #endif
254
255 #ifdef FG_NEED_TYPENAME
256 #  define typename
257 #endif
258
259 #ifdef FG_NEED_MUTABLE
260 #  define mutable
261 #endif
262
263 #ifdef FG_NEED_BOOL
264    typedef int bool;
265 #  define true 1
266 #  define false 0
267 #endif
268
269 #ifdef FG_EXPLICIT_FUNCTION_TMPL_ARGS
270 #  define FG_NULL_TMPL_ARGS <>
271 #else
272 #  define FG_NULL_TMPL_ARGS
273 #endif
274
275 #ifdef FG_CLASS_PARTIAL_SPECIALIZATION
276 # define FG_TEMPLATE_NULL template<>
277 #else
278 # define FG_TEMPLATE_NULL
279 #endif
280
281 // FG_NO_NAMESPACES is a hook so that users can disable namespaces
282 // without having to edit library headers.
283 #if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
284 #   define FG_NAMESPACE(X) namespace X {
285 #   define FG_NAMESPACE_END }
286 #   define FG_USING_NAMESPACE(X) using namespace X
287 # else
288 #   define FG_NAMESPACE(X)
289 #   define FG_NAMESPACE_END
290 #   define FG_USING_NAMESPACE(X)
291 #endif
292
293 # ifdef FG_HAVE_STD
294 #  define FG_USING_STD(X) using std::X
295 #  define STD std
296 # else
297 #  define FG_USING_STD(X) 
298 #  define STD
299 # endif
300
301 // Additional <functional> implementation from SGI STL 3.11
302 // Adapter function objects: pointers to member functions
303 #ifdef FG_INCOMPLETE_FUNCTIONAL
304
305 template <class _Ret, class _Tp>
306 class const_mem_fun_ref_t
307 #ifndef __BORLANDC__
308     : public unary_function<_Tp,_Ret>
309 #endif // __BORLANDC__
310 {
311 public:
312   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
313   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
314 private:
315   _Ret (_Tp::*_M_f)() const;
316 };
317
318 template <class _Ret, class _Tp>
319 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
320   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
321
322 #endif // FG_INCOMPLETE_FUNCTIONAL
323
324 #endif // _COMPILER_H