/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/external/stlplus/include/stlplus/os_fixes.hpp Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/external/stlplus/include/stlplus/os_fixes.hpp Source File
Ratpac-two
os_fixes.hpp
1 #ifndef OS_FIXES_HPP
2 #define OS_FIXES_HPP
3 /*------------------------------------------------------------------------------
4 
5  Author: Andy Rushton
6  Copyright: (c) Andy Rushton, 2004
7  License: BSD License, see ../docs/license.html
8 
9  Contains work arounds for OS or Compiler specific problems to try to make
10  them look more alike
11 
12  It is strongly recommended that this header be included as the first
13  #include in every source file
14 
15  ------------------------------------------------------------------------------*/
16 
18 // Problems with unnecessary or unfixable compiler warnings
20 
21 #if defined(_MSC_VER)
22 // Microsoft Visual Studio
23 // shut up the following irritating warnings
24 // 4275 - VC6, exported class was derived from a class that was not exported
25 // 4786 - VC6, identifier string exceeded maximum allowable length and was truncated (only affects debugger)
26 // 4305 - VC6, identifier type was converted to a smaller type
27 // 4503 - VC6, decorated name was longer than the maximum the compiler allows (only affects debugger)
28 // 4309 - VC6, type conversion operation caused a constant to exceeded the space allocated for it
29 // 4290 - VC6, C++ exception specification ignored
30 // 4800 - VC6, forcing value to bool 'true' or 'false' (performance warning)
31 // 4675 - VC7.1, "change" in function overload resolution _might_ have altered program
32 #pragma warning(disable : 4275 4786 4305 4503 4309 4290 4800 4675)
33 #endif
34 
35 #if defined(__BORLANDC__)
36 // Borland
37 // Shut up the following irritating warnings
38 // 8022 - A virtual function in a base class is usually overridden by a
39 // declaration in a derived class.
40 // In this case, a declaration with the same name but different
41 // argument types makes the virtual functions inaccessible to further
42 // derived classes
43 // 8008 - Condition is always true.
44 // Whenever the compiler encounters a constant comparison that (due to
45 // the nature of the value being compared) is always true or false, it
46 // issues this warning and evaluates the condition at compile time.
47 // 8060 - Possibly incorrect assignment.
48 // This warning is generated when the compiler encounters an assignment
49 // operator as the main operator of a conditional expression (part of
50 // an if, while, or do-while statement). This is usually a
51 // typographical error for the equality operator.
52 // 8066 - Unreachable code.
53 // A break, continue, goto, or return statement was not followed by a
54 // label or the end of a loop or function. The compiler checks while,
55 // do, and for loops with a constant test condition, and attempts to
56 // recognize loops that can't fall through.
57 #pragma warn - 8022
58 #pragma warn - 8008
59 #pragma warn - 8060
60 #pragma warn - 8066
61 #endif
62 
64 // Problems with redefinition of min/max in various different versions of library headers
66 
67 // The Windoze headers define macros called max/min which conflict with the templates std::max and std::min.
68 // So, to avoid conflicts, MS removed the std::max/min rather than fixing the problem!
69 // From Visual Studio .NET (SV7, compiler version 13.00) the STL templates have been added correctly.
70 // This fix switches off the macros and reinstates the STL templates for earlier versions (SV6).
71 // Note that this could break MFC applications that rely on the macros (try it and see).
72 
73 // For MFC compatibility, only undef min and max in non-MFC programs - some bits of MFC
74 // use macro min/max in headers. For VC7 both the macros and template functions exist
75 // so there is no real need for the undefs but to it anyway for consistency. So, if
76 // using VC6 and MFC then template functions will not exist
77 
78 // I've created extra template function definitions minimum/maximum that avoid all the problems above
79 
80 #if defined(_MSC_VER) && !defined(_MFC_VER)
81 #define NOMINMAX
82 #undef max
83 #undef min
84 // replace missing template definitions in VC6
85 #if defined(_MSC_VER) && (_MSC_VER < 1300)
86 namespace std {
87 template <typename T>
88 const T& max(const T& l, const T& r) {
89  return l > r ? l : r;
90 }
91 template <typename T>
92 const T& min(const T& l, const T& r) {
93  return l < r ? l : r;
94 }
95 } // namespace std
96 #endif
97 #endif
98 
99 template <typename T>
100 const T& maximum(const T& l, const T& r) {
101  return l > r ? l : r;
102 }
103 template <typename T>
104 const T& minimum(const T& l, const T& r) {
105  return l < r ? l : r;
106 }
107 
109 // Problem with missing __FUNCTION__ macro
111 // this macro is used in debugging but was missing in Visual Studio prior to version 7
112 // it also has a different name in Borland
113 
114 #if defined(_MSC_VER) && (_MSC_VER < 1300)
115 #define __FUNCTION__ 0
116 #endif
117 
118 #if defined(__BORLANDC__)
119 #define __FUNCTION__ __FUNC__
120 #endif
121 
122 #ifndef __FUNCTION__
123 #define __FUNCTION__ 0
124 #endif
125 
127 // Problems with differences between namespaces
129 
130 // problem in gcc pre-v3 where the sub-namespaces in std aren't present
131 
132 // I've done a fix here that creates an empty namespace for this case, but I
133 // do *not* try to move the contents of std::rel_ops into namespace std
134 
135 #if defined(__GNUC__)
136 namespace std {
137 namespace rel_ops {}
138 } // namespace std
139 #endif
140 
142 // Problems with the typename keyword
144 
145 // There are problems with using the 'typename' keyword. Technically, if you
146 // use a typedef member of a template class, you need to tell the compiler
147 // that it is a type name. This is because the compiler cannot work out
148 // whether a member is a type, a method or a data field at compile time.
149 // However, support for the typename keyword has traditionally been incomplete
150 // in both gcc and Visual Studio. I have used macros to try to resolve this
151 // issue. The macros add the keyword for compiler versions that require it and
152 // omit it for compiler versions that do not support it
153 
154 // Typedefs:
155 // GCC pre-version 3 didn't handle typename in typedefs
156 // after version 3, typename is required for a typedef in a template function
157 // Visual Studio
158 // these cases are handled by the definition of the TYPEDEF_TYPENAME macro
159 
160 // Function Parameters:
161 // Visual Studio version 7.1 requires a typename in a parameter specification in similarly obscure situations
162 // this appears to be specific to VC7.1 (.NET 2003) and after and is not compatible with any gcc version
163 // this case is handled by the definition of the PARAMETER_TYPENAME macro
164 
165 // Template Instantiation Parameters:
166 // Visual studio cannot hack typename within a template instantiation parameter list
167 // this is required by gcc v3.4 and optional before that
168 // this case is handled by the definition of the TEMPLATE_TYPENAME macro
169 
170 #if defined(__GNUC__)
171 
172 // gcc compiler variants
173 #if __GNUC__ >= 3
174 // gcc v3.0 onwards
175 #define TYPEDEF_TYPENAME typename
176 #define PARAMETER_TYPENAME typename
177 #define TEMPLATE_TYPENAME typename
178 #else
179 // gcc prior to v3
180 #define TYPEDEF_TYPENAME
181 #define PARAMETER_TYPENAME
182 #define TEMPLATE_TYPENAME
183 #endif
184 
185 #else
186 #if defined(_MSC_VER)
187 
188 // Microsoft Visual Studio variants
189 #define TYPEDEF_TYPENAME
190 #if _MSC_VER >= 1300
191 // Visual Studio .NET
192 #define PARAMETER_TYPENAME typename
193 #else
194 // Visual Studio version 6
195 #define PARAMETER_TYPENAME
196 #endif
197 #define TEMPLATE_TYPENAME
198 
199 #endif
200 #define TEMPLATE_TYPENAME typename
201 #endif
202 
203 #ifdef __GNUC__
204 #define SUN_TYPENAME_HACK typename
205 #else
206 #define SUN_TYPENAME_HACK
207 #endif
208 
210 // problems with missing functions
212 
213 #if defined(_MSC_VER) || defined(__BORLANDC__)
214 unsigned sleep(unsigned seconds);
215 #else
216 #include <unistd.h>
217 #endif
218 
220 // Function for establishing endian-ness
222 // Different machine architectures store data using different byte orders.
223 // This is referred to as Big- and Little-Endian Byte Ordering.
224 //
225 // The issue is: where does a pointer to an integer type actually point?
226 //
227 // In both conventions, the address points to the left of the word but:
228 // Big-Endian - The most significant byte is on the left end of a word
229 // Little-Endian - The least significant byte is on the left end of a word
230 //
231 // Bytes are addressed left to right, so in big-endian order byte 0 is the
232 // msB, whereas in little-endian order byte 0 is the lsB. For example,
233 // Intel-based machines store data in little-endian byte order so byte 0 is
234 // the lsB.
235 //
236 // This function establishes byte order at run-time
237 
238 bool little_endian(void);
239 
241 #endif