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