1 /**************************************************************************
2 * compiler.h -- C++ Compiler Portability Macros
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.
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.
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.
21 **************************************************************************/
24 * A set of defines to encapsulate compiler and platform differences.
25 * What this file does.
27 * (1) Defines macros for some STL includes which may be affected
28 * by file name length limitations.
30 * (2) Defines macros for some features not supported by all C++ compilers.
32 * (3) Defines 'explicit' as a null macro if the compiler doesn't support
33 * the explicit keyword.
35 * (4) Defines 'typename' as a null macro if the compiler doesn't support
36 * the typename keyword.
38 * (5) Defines bool, true and false if the compiler doesn't do so.
40 * (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
41 * supports calling a function template by providing its template
42 * arguments explicitly.
44 * (7) Defines FG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
46 * (8) Defines FG_NO_ARROW_OPERATOR if the compiler is unable
47 * to support operator->() for iterators.
49 * (9) Defines FG_USE_EXCEPTIONS if the compiler supports exceptions.
50 * Note: no FlightGear code uses exceptions.
52 * (10) Define FG_NAMESPACES if the compiler supports namespaces.
54 * (11) FG_MATH_FN_IN_NAMESPACE_STD -- not used??
56 * (12) Define FG_HAVE_STD if std namespace is supported.
58 * (13) Defines FG_CLASS_PARTIAL_SPECIALIZATION if the compiler
59 * supports partial specialization of class templates.
61 * (14) Defines FG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
63 * (15) Defines FG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
65 * (16) Define FG_MATH_EXCEPTION_CLASH if math.h defines an exception class
66 * that clashes with the one defined in <stdexcept>.
69 #ifndef _SG_COMPILER_H
70 #define _SG_COMPILER_H
74 # if __GNUC_MINOR__ < 8
77 # define STL_ALGORITHM <algorithm>
78 # define STL_FUNCTIONAL <functional>
79 # define STL_IOMANIP <iomanip.h>
80 # define STL_IOSTREAM <iostream.h>
81 # define STL_FSTREAM <fstream.h>
82 # define STL_STDEXCEPT <stdexcept>
83 # define STL_STRING <string>
84 # define STL_STRSTREAM <strstream.h>
86 # define FG_NEED_AUTO_PTR
87 # define FG_NO_DEFAULT_TEMPLATE_ARGS
88 # define FG_INCOMPLETE_FUNCTIONAL
89 # define FG_NO_ARROW_OPERATOR
91 # elif __GNUC_MINOR__ >= 8
93 // g++-2.8.x and egcs-1.x
94 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
95 # define FG_NEED_AUTO_PTR
96 # define FG_MEMBER_TEMPLATES
97 # define FG_NAMESPACES
99 # define FG_HAVE_STREAMBUF
100 # define FG_CLASS_PARTIAL_SPECIALIZATION
102 # define STL_ALGORITHM <algorithm>
103 # define STL_FUNCTIONAL <functional>
104 # define STL_IOMANIP <iomanip>
105 # define STL_IOSTREAM <iostream>
106 # define STL_FSTREAM <fstream>
107 # define STL_STDEXCEPT <stdexcept>
108 # define STL_STRING <string>
109 # define STL_STRSTREAM <strstream>
113 # error Time to upgrade. GNU compilers < 2.7 not supported
120 # define FG_NAMESPACES
122 # define FG_HAVE_STREAMBUF
123 # define FG_HAVE_TRAITS
124 # define FG_HAVE_STD_INCLUDES
126 # define STL_ALGORITHM <algorithm>
127 # define STL_FUNCTIONAL <functional>
128 # define STL_IOMANIP <iomanip>
129 # define STL_IOSTREAM <iostream>
130 # define STL_FSTREAM <fstream>
131 # define STL_STDEXCEPT <stdexcept>
132 # define STL_STRING <string>
133 # define STL_STRSTREAM <strstream>
139 #if defined(__MWERKS__)
141 CodeWarrior compiler from Metrowerks, Inc.
143 # define FG_HAVE_TRAITS
144 # define FG_HAVE_STD_INCLUDES
146 # define FG_NAMESPACES
148 # define STL_ALGORITHM <algorithm>
149 # define STL_FUNCTIONAL <functional>
150 # define STL_IOMANIP <iomanip>
151 # define STL_IOSTREAM <iostream>
152 # define STL_FSTREAM <fstream>
153 # define STL_STDEXCEPT <stdexcept>
154 # define STL_STRING <string>
157 # define bcopy(from, to, n) memcpy(to, from, n)
159 // -rp- please use FG_MEM_COPY everywhere !
160 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
162 // -dw- currently used glut has no game mode stuff
163 # define GLUT_WRONG_VERSION
167 // Microsoft compilers.
170 # define bcopy(from, to, n) memcpy(to, from, n)
171 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
173 # if _MSC_VER == 1200 // msvc++ 6.0
174 # define FG_NAMESPACES
176 # define FG_HAVE_STD_INCLUDES
177 # define FG_HAVE_STREAMBUF
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>
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) //
192 # elif _MSC_VER == 1100 // msvc++ 5.0
193 # define NEEDNAMESPACESTD
194 # define FG_NAMESPACES
196 # define FG_HAVE_STD_INCLUDES
197 # define FG_HAVE_STREAMBUF
199 # define STL_ALGORITHM <algorithm>
200 # define STL_FUNCTIONAL <functional>
201 # define STL_IOMANIP <iomanip>
202 # define STL_IOSTREAM <iostream>
203 # define STL_FSTREAM <fstream>
204 # define STL_STDEXCEPT <stdexcept>
205 # define STL_STRING <string>
206 # define STL_STRSTREAM <strstream>
208 # pragma warning(disable: 4786) // identifier was truncated to '255' characters
209 # pragma warning(disable: 4244) // conversion from double to float
210 # pragma warning(disable: 4305) //
213 # error What version of MSVC++ is this?
218 # if defined(HAVE_SGI_STL_PORT)
220 // Use quotes around long file names to get around Borland's include hackery
222 # define STL_ALGORITHM "algorithm"
223 # define STL_FUNCTIONAL "functional"
225 # define FG_MATH_EXCEPTION_CLASH
229 # define STL_ALGORITHM <algorithm>
230 # define STL_FUNCTIONAL <functional>
231 # define STL_IOMANIP <iomanip>
232 # define STL_STDEXCEPT <stdexcept>
233 # define STL_STRSTREAM <strstream>
235 # define FG_INCOMPLETE_FUNCTIONAL
237 # endif // HAVE_SGI_STL_PORT
239 # define STL_IOSTREAM <iostream>
240 # define STL_FSTREAM <fstream>
241 # define STL_STRING <string>
242 # define FG_NO_DEFAULT_TEMPLATE_ARGS
243 # define FG_NAMESPACES
244 // # define FG_HAVE_STD
246 #endif // __BORLANDC__
249 // Native SGI compilers
252 #if defined ( sgi ) && !defined( __GNUC__ )
253 # define FG_HAVE_NATIVE_SGI_COMPILERS
255 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
256 # define FG_NEED_AUTO_PTR
257 # define FG_MEMBER_TEMPLATES
258 # define FG_NAMESPACES
260 # define FG_CLASS_PARTIAL_SPECIALIZATION
261 # define FG_HAVE_TRAITS
263 # define STL_ALGORITHM <algorithm>
264 # define STL_FUNCTIONAL <functional>
265 # define STL_IOMANIP <iomanip.h>
266 # define STL_IOSTREAM <iostream.h>
267 # define STL_FSTREAM <fstream.h>
268 # define STL_STDEXCEPT <stdexcept>
269 # define STL_STRING <string>
270 # define STL_STRSTREAM <strstream>
272 #endif // Native SGI compilers
276 # include <strings.h>
278 # if defined ( __cplusplus )
279 // typedef unsigned int size_t;
281 extern void *memmove(void *, const void *, size_t);
284 extern void *memmove(void *, const void *, size_t);
285 # endif // __cplusplus
289 // No user modifiable definitions beyond here.
292 #ifdef FG_NEED_EXPLICIT
296 #ifdef FG_NEED_TYPENAME
300 #ifdef FG_NEED_MUTABLE
310 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
311 # define FG_NULL_TMPL_ARGS <>
313 # define FG_NULL_TMPL_ARGS
316 #ifdef FG_CLASS_PARTIAL_SPECIALIZATION
317 # define FG_TEMPLATE_NULL template<>
319 # define FG_TEMPLATE_NULL
322 // FG_NO_NAMESPACES is a hook so that users can disable namespaces
323 // without having to edit library headers.
324 #if defined(FG_NAMESPACES) && !defined(FG_NO_NAMESPACES)
325 # define FG_NAMESPACE(X) namespace X {
326 # define FG_NAMESPACE_END }
327 # define FG_USING_NAMESPACE(X) using namespace X
329 # define FG_NAMESPACE(X)
330 # define FG_NAMESPACE_END
331 # define FG_USING_NAMESPACE(X)
335 # define FG_USING_STD(X) using std::X
338 # define FG_USING_STD(X)
342 // Additional <functional> implementation from SGI STL 3.11
343 // Adapter function objects: pointers to member functions
344 #ifdef FG_INCOMPLETE_FUNCTIONAL
346 template <class _Ret, class _Tp>
347 class const_mem_fun_ref_t
349 : public unary_function<_Tp,_Ret>
350 #endif // __BORLANDC__
353 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
354 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
356 _Ret (_Tp::*_M_f)() const;
359 template <class _Ret, class _Tp>
360 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
361 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
363 #endif // FG_INCOMPLETE_FUNCTIONAL
365 #endif // _SG_COMPILER_H