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 * Please refer to the source code for full documentation on this file.
27 * Here is a summary of what this file does.
29 * (1) Defines macros for some STL includes which may be affected
30 * by file name length limitations.
32 * (2) Defines macros for some features not supported by all C++ compilers.
34 * (3) Defines 'explicit' as a null macro if the compiler doesn't support
35 * the explicit keyword.
37 * (4) Defines 'typename' as a null macro if the compiler doesn't support
38 * the typename keyword.
40 * (5) Defines bool, true and false if the compiler doesn't do so.
42 * (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
43 * supports calling a function template by providing its template
44 * arguments explicitly.
46 * (7) Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
48 * (8) Defines SG_NO_ARROW_OPERATOR if the compiler is unable
49 * to support operator->() for iterators.
51 * (9) Defines SG_USE_EXCEPTIONS if the compiler supports exceptions.
52 * Note: no FlightGear code uses exceptions.
54 * (10) Define SG_NAMESPACES if the compiler supports namespaces.
56 * (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used??
58 * (12) Define SG_HAVE_STD if std namespace is supported.
60 * (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler
61 * supports partial specialization of class templates.
63 * (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
65 * (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
67 * (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception class
68 * that clashes with the one defined in <stdexcept>.
71 #ifndef _SG_COMPILER_H
72 #define _SG_COMPILER_H
76 # if __GNUC_MINOR__ < 8
79 # define STL_ALGORITHM <algorithm>
80 # define STL_FUNCTIONAL <functional>
81 # define STL_IOMANIP <iomanip.h>
82 # define STL_IOSTREAM <iostream.h>
83 # define STL_ITERATOR <iterator.h>
84 # define STL_FSTREAM <fstream.h>
85 # define STL_STDEXCEPT <stdexcept>
86 # define STL_STRING <string>
87 # define STL_STRSTREAM <strstream.h>
89 # define SG_NEED_AUTO_PTR
90 # define SG_NO_DEFAULT_TEMPLATE_ARGS
91 # define SG_INCOMPLETE_FUNCTIONAL
92 # define SG_NO_ARROW_OPERATOR
94 # elif __GNUC_MINOR__ >= 8
96 // g++-2.8.x and egcs-1.x
97 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
98 # define SG_NEED_AUTO_PTR
99 # define SG_MEMBER_TEMPLATES
100 # define SG_NAMESPACES
102 # define SG_HAVE_STREAMBUF
103 # define SG_CLASS_PARTIAL_SPECIALIZATION
105 # define STL_ALGORITHM <algorithm>
106 # define STL_FUNCTIONAL <functional>
107 # define STL_IOMANIP <iomanip>
108 # define STL_IOSTREAM <iostream>
109 # define STL_ITERATOR <iterator>
110 # define STL_FSTREAM <fstream>
111 # define STL_STDEXCEPT <stdexcept>
112 # define STL_STRING <string>
113 # define STL_STRSTREAM <strstream>
118 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
119 # define SG_NEED_AUTO_PTR
120 # define SG_MEMBER_TEMPLATES
121 # define SG_NAMESPACES
123 # define SG_HAVE_STREAMBUF
124 # define SG_CLASS_PARTIAL_SPECIALIZATION
125 # define SG_HAVE_STD_INCLUDES
127 # define STL_ALGORITHM <algorithm>
128 # define STL_FUNCTIONAL <functional>
129 # define STL_IOMANIP <iomanip>
130 # define STL_IOSTREAM <iostream>
131 # define STL_ITERATOR <iterator>
132 # define STL_FSTREAM <fstream>
133 # define STL_STDEXCEPT <stdexcept>
134 # define STL_STRING <string>
135 # define STL_STRSTREAM <strstream>
138 # error Time to upgrade. GNU compilers < 2.7 not supported
145 # define SG_NAMESPACES
147 # define SG_HAVE_STREAMBUF
148 # define SG_HAVE_TRAITS
149 # define SG_HAVE_STD_INCLUDES
151 # define STL_ALGORITHM <algorithm>
152 # define STL_FUNCTIONAL <functional>
153 # define STL_IOMANIP <iomanip>
154 # define STL_IOSTREAM <iostream>
155 # define STL_ITERATOR <iterator>
156 # define STL_FSTREAM <fstream>
157 # define STL_STDEXCEPT <stdexcept>
158 # define STL_STRING <string>
159 # define STL_STRSTREAM <strstream>
165 #if defined(__MWERKS__)
167 CodeWarrior compiler from Metrowerks, Inc.
169 # define SG_HAVE_TRAITS
170 # define SG_HAVE_STD_INCLUDES
172 # define SG_NAMESPACES
174 # define STL_ALGORITHM <algorithm>
175 # define STL_FUNCTIONAL <functional>
176 # define STL_IOMANIP <iomanip>
177 # define STL_IOSTREAM <iostream>
178 # define STL_ITERATOR <iterator>
179 # define STL_FSTREAM <fstream>
180 # define STL_STDEXCEPT <stdexcept>
181 # define STL_STRING <string>
184 # define bcopy(from, to, n) memcpy(to, from, n)
186 // -rp- please use FG_MEM_COPY everywhere !
187 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
189 // -dw- currently used glut has no game mode stuff
190 # define GLUT_WRONG_VERSION
194 // Microsoft compilers.
197 # define bcopy(from, to, n) memcpy(to, from, n)
198 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
200 # if _MSC_VER == 1200 // msvc++ 6.0
201 # define SG_NAMESPACES
203 # define SG_HAVE_STD_INCLUDES
204 # define SG_HAVE_STREAMBUF
206 # define STL_ALGORITHM <algorithm>
207 # define STL_FUNCTIONAL <functional>
208 # define STL_IOMANIP <iomanip>
209 # define STL_IOSTREAM <iostream>
210 # define STL_ITERATOR <iterator>
211 # define STL_FSTREAM <fstream>
212 # define STL_STDEXCEPT <stdexcept>
213 # define STL_STRING <string>
214 # define STL_STRSTREAM <strstream>
216 # pragma warning(disable: 4786) // identifier was truncated to '255' characters
217 # pragma warning(disable: 4244) // conversion from double to float
218 # pragma warning(disable: 4305) //
220 # error What version of MSVC++ is this?
225 # if defined(HAVE_SGI_STL_PORT)
227 // Use quotes around long file names to get around Borland's include hackery
229 # define STL_ALGORITHM "algorithm"
230 # define STL_FUNCTIONAL "functional"
232 # define SG_MATH_EXCEPTION_CLASH
236 # define STL_ALGORITHM <algorithm>
237 # define STL_FUNCTIONAL <functional>
238 # define STL_IOMANIP <iomanip>
239 # define STL_STDEXCEPT <stdexcept>
240 # define STL_STRSTREAM <strstream>
242 # define SG_INCOMPLETE_FUNCTIONAL
244 # endif // HAVE_SGI_STL_PORT
246 # define STL_IOSTREAM <iostream>
247 # define STL_ITERATOR <iterator>
248 # define STL_FSTREAM <fstream>
249 # define STL_STRING <string>
250 # define SG_NO_DEFAULT_TEMPLATE_ARGS
251 # define SG_NAMESPACES
252 // # define SG_HAVE_STD
254 #endif // __BORLANDC__
257 // Native SGI compilers
260 #if defined ( sgi ) && !defined( __GNUC__ )
261 # define SG_HAVE_NATIVE_SGI_COMPILERS
263 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
264 # define SG_NEED_AUTO_PTR
265 # define SG_MEMBER_TEMPLATES
266 # define SG_NAMESPACES
268 # define SG_CLASS_PARTIAL_SPECIALIZATION
269 # define SG_HAVE_TRAITS
271 # define STL_ALGORITHM <algorithm>
272 # define STL_FUNCTIONAL <functional>
273 # define STL_IOMANIP <iomanip.h>
274 # define STL_IOSTREAM <iostream.h>
275 # define STL_ITERATOR <iterator.h>
276 # define STL_FSTREAM <fstream.h>
277 # define STL_STDEXCEPT <stdexcept>
278 # define STL_STRING <string>
279 # define STL_STRSTREAM <strstream.h>
281 #endif // Native SGI compilers
285 # include <strings.h>
287 # if defined ( __cplusplus )
288 // typedef unsigned int size_t;
290 extern void *memmove(void *, const void *, size_t);
293 extern void *memmove(void *, const void *, size_t);
294 # endif // __cplusplus
298 // No user modifiable definitions beyond here.
301 #ifdef SG_NEED_EXPLICIT
305 #ifdef SG_NEED_TYPENAME
309 #ifdef SG_NEED_MUTABLE
319 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
320 # define SG_NULL_TMPL_ARGS <>
322 # define SG_NULL_TMPL_ARGS
325 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
326 # define SG_TEMPLATE_NULL template<>
328 # define SG_TEMPLATE_NULL
331 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
332 // without having to edit library headers.
333 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
334 # define SG_NAMESPACE(X) namespace X {
335 # define SG_NAMESPACE_END }
336 # define SG_USING_NAMESPACE(X) using namespace X
338 # define SG_NAMESPACE(X)
339 # define SG_NAMESPACE_END
340 # define SG_USING_NAMESPACE(X)
343 /** \def SG_USING_STD(x)
344 * Expands to using std::x if SG_HAVE_STD is defined
347 # define SG_USING_STD(X) using std::X
350 # define SG_USING_STD(X)
354 // Additional <functional> implementation from SGI STL 3.11
355 // Adapter function objects: pointers to member functions
356 #ifdef SG_INCOMPLETE_FUNCTIONAL
358 template <class _Ret, class _Tp>
359 class const_mem_fun_ref_t
361 : public unary_function<_Tp,_Ret>
362 #endif // __BORLANDC__
365 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
366 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
368 _Ret (_Tp::*_M_f)() const;
371 template <class _Ret, class _Tp>
372 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
373 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
375 #endif // SG_INCOMPLETE_FUNCTIONAL
377 #endif // _SG_COMPILER_H