ZenLib
Conf.h
Go to the documentation of this file.
1 // ZenLib::ZenTypes - To be independant of platform & compiler
2 // Copyright (C) 2002-2011 MediaArea.net SARL, Info@MediaArea.net
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgment in the product documentation would be
15 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
18 // 3. This notice may not be removed or altered from any source distribution.
19 //
20 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 
23 //---------------------------------------------------------------------------
24 #ifndef ZenConfH
25 #define ZenConfH
26 //---------------------------------------------------------------------------
27 
28 //***************************************************************************
29 // Platforms
30 //***************************************************************************
31 
32 //---------------------------------------------------------------------------
33 //Win32
34 #if defined(__NT__) || defined(_WIN32) || defined(WIN32)
35  #ifndef WIN32
36  #define WIN32
37  #endif
38  #ifndef _WIN32
39  #define _WIN32
40  #endif
41  #ifndef __WIN32__
42  #define __WIN32__ 1
43  #endif
44 #endif
45 
46 //---------------------------------------------------------------------------
47 //Win64
48 #if defined(_WIN64) || defined(WIN64)
49  #ifndef WIN64
50  #define WIN64
51  #endif
52  #ifndef _WIN64
53  #define _WIN64
54  #endif
55  #ifndef __WIN64__
56  #define __WIN64__ 1
57  #endif
58 #endif
59 
60 //---------------------------------------------------------------------------
61 //Windows
62 #if defined(WIN32) || defined(WIN64)
63  #ifndef WINDOWS
64  #define WINDOWS
65  #endif
66  #ifndef _WINDOWS
67  #define _WINDOWS
68  #endif
69  #ifndef __WINDOWS__
70  #define __WINDOWS__ 1
71  #endif
72 #endif
73 #if !defined(ZENLIB_NO_WIN9X_SUPPORT) && (defined(_M_X64) || defined(_M_IA64))
74  #define ZENLIB_NO_WIN9X_SUPPORT
75 #endif
76 
77 //---------------------------------------------------------------------------
78 //Unix (Linux, HP, Sun, BeOS...)
79 #if defined(UNIX) || defined(_UNIX) || defined(__UNIX__) \
80  || defined(__unix) || defined(__unix__) \
81  || defined(____SVR4____) || defined(__LINUX__) || defined(__sgi) \
82  || defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) \
83  || defined(__EMX__) || defined(__VMS) || defined(__BEOS__)
84  #ifndef UNIX
85  #define UNIX
86  #endif
87  #ifndef _UNIX
88  #define _UNIX
89  #endif
90  #ifndef __UNIX__
91  #define __UNIX__ 1
92  #endif
93 #endif
94 
95 //---------------------------------------------------------------------------
96 //MacOS Classic
97 #if defined(macintosh)
98  #ifndef MACOS
99  #define MACOS
100  #endif
101  #ifndef _MACOS
102  #define _MACOS
103  #endif
104  #ifndef __MACOS__
105  #define __MACOS__ 1
106  #endif
107 #endif
108 
109 //---------------------------------------------------------------------------
110 //MacOS X
111 #if defined(__APPLE__) && defined(__MACH__)
112  #ifndef MACOSX
113  #define MACOSX
114  #endif
115  #ifndef _MACOSX
116  #define _MACOSX
117  #endif
118  #ifndef __MACOSX__
119  #define __MACOSX__ 1
120  #endif
121 #endif
122 
123 //Test of targets
124 #if defined(WINDOWS) && defined(UNIX) && defined(MACOS) && defined(MACOSX)
125  #pragma message Multiple platforms???
126 #endif
127 
128 #if !defined(WIN32) && !defined(UNIX) && !defined(MACOS) && !defined(MACOSX)
129  #pragma message No known platforms, assume default
130 #endif
131 
132 //***************************************************************************
133 // Internationnal
134 //***************************************************************************
135 
136 //---------------------------------------------------------------------------
137 //Unicode
138 #if defined(_UNICODE) || defined(UNICODE) || defined(__UNICODE__)
139  #ifndef _UNICODE
140  #define _UNICODE
141  #endif
142  #ifndef UNICODE
143  #define UNICODE
144  #endif
145  #ifndef __UNICODE__
146  #define __UNICODE__ 1
147  #endif
148 #endif
149 
150 //---------------------------------------------------------------------------
151 //wchar_t stuff
152 #if defined(MACOS) || defined(MACOSX)
153  #include <wchar.h>
154 #endif
155 
156 //***************************************************************************
157 // Compiler bugs/unuseful warning
158 //***************************************************************************
159 
160 //MSVC6 : for(int t=0; t<10; ++t) { do something }; for(int t=0; t<10; ++t) { do something }
161 #if defined(_MSC_VER) && _MSC_VER <= 1200
162  #define for if(true)for
163  #pragma warning(disable:4786) // MSVC6 doesn't like typenames longer than 255 chars (which generates an enormous amount of warnings).
164 #endif
165 
166 //MSVC2005 : "deprecated" warning (replacement functions are not in MinGW32 or Borland!)
167 #if defined(_MSC_VER) && _MSC_VER >= 1400
168  #pragma warning(disable : 4996)
169 #endif
170 
171 //***************************************************************************
172 // (Without Namespace)
173 //***************************************************************************
174 
175 //---------------------------------------------------------------------------
176 #include <limits.h>
177 
178 //---------------------------------------------------------------------------
179 #if defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
180  #include "ZenLib/MemoryDebug.h"
181 #endif // defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
182 
183 //***************************************************************************
184 // Compiler helpers
185 //***************************************************************************
186 
187 //---------------------------------------------------------------------------
188 //Macro to cut down on compiler warnings
189 #ifndef UNUSED
190  #define UNUSED(Identifier)
191 #endif
192 //---------------------------------------------------------------------------
193 //If we need size_t specific integer conversion
194 #if !defined(SIZE_T_IS_LONG) && (defined(__LP64__) || defined(MACOSX))
195  #define SIZE_T_IS_LONG
196 #endif
197 
198 //---------------------------------------------------------------------------
199 //(-1) is known to be the MAX of an unsigned int but GCC complains about it
200 #include <new>
201 #include <cstring> //size_t
202 namespace ZenLib
203 {
204  const std::size_t Error=((std::size_t)(-1));
205  const std::size_t All=((std::size_t)(-1));
206  const std::size_t Unlimited=((std::size_t)(-1));
207 }
208 
209 //***************************************************************************
210 // (With namespace)
211 //***************************************************************************
212 
213 namespace ZenLib
214 {
215 
216 //***************************************************************************
217 // International
218 //***************************************************************************
219 
220 //---------------------------------------------------------------------------
221 //Char types
222 #undef _T
223 #define _T(__x) __T(__x)
224 #undef _TEXT
225 #define _TEXT(__x) __T(__x)
226 #undef __TEXT
227 #define __TEXT(__x) __T(__x)
228 #if defined(__UNICODE__)
229  #if defined (_MSC_VER) && !defined (_NATIVE_WCHAR_T_DEFINED)
230  #pragma message Native wchar_t is not defined, not tested, you should put /Zc:wchar_t in compiler options
231  #endif
232  typedef wchar_t Char;
233  #undef __T
234  #define __T(__x) L##__x
235 #else // defined(__UNICODE__)
236  typedef char Char;
237  #undef __T
238  #define __T(__x) __x
239 #endif // defined(__UNICODE__)
240 #ifdef wchar_t
241  typedef wchar_t wchar;
242 #endif // wchar_t
243 
244 //***************************************************************************
245 // Platform differences
246 //***************************************************************************
247 
248 //End of line
249 extern const Char* EOL;
250 extern const Char PathSeparator;
251 
252 //***************************************************************************
253 // Types
254 //***************************************************************************
255 
256 //---------------------------------------------------------------------------
257 //int
258 typedef signed int ints;
259 typedef unsigned int intu;
260 
261 //---------------------------------------------------------------------------
262 //8-bit int
263 #if UCHAR_MAX==0xff
264  #undef MAXTYPE_INT
265  #define MAXTYPE_INT 8
266  typedef signed char int8s;
267  typedef unsigned char int8u;
268 #else
269  #pragma message This machine has no 8-bit integertype?
270 #endif
271 
272 //---------------------------------------------------------------------------
273 //16-bit int
274 #if UINT_MAX == 0xffff
275  #undef MAXTYPE_INT
276  #define MAXTYPE_INT 16
277  typedef signed int int16s;
278  typedef unsigned int int16u;
279 #elif USHRT_MAX == 0xffff
280  #undef MAXTYPE_INT
281  #define MAXTYPE_INT 16
282  typedef signed short int16s;
283  typedef unsigned short int16u;
284 #else
285  #pragma message This machine has no 16-bit integertype?
286 #endif
287 
288 //---------------------------------------------------------------------------
289 //32-bit int
290 #if UINT_MAX == 0xfffffffful
291  #undef MAXTYPE_INT
292  #define MAXTYPE_INT 32
293  typedef signed int int32s;
294  typedef unsigned int int32u;
295 #elif ULONG_MAX == 0xfffffffful
296  #undef MAXTYPE_INT
297  #define MAXTYPE_INT 32
298  typedef signed long int32s;
299  typedef unsigned long int32u;
300 #elif USHRT_MAX == 0xfffffffful
301  #undef MAXTYPE_INT
302  #define MAXTYPE_INT 32
303  typedef signed short int32s;
304  typedef unsigned short int32u;
305 #else
306  #pragma message This machine has no 32-bit integer type?
307 #endif
308 
309 //---------------------------------------------------------------------------
310 //64-bit int
311 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
312  #undef MAXTYPE_INT
313  #define MAXTYPE_INT 64
314  typedef signed long long int64s;
315  typedef unsigned long long int64u;
316 #elif defined(__WIN32__)
317  #undef MAXTYPE_INT
318  #define MAXTYPE_INT 64
319  typedef signed __int64 int64s;
320  typedef unsigned __int64 int64u;
321 #else
322  #pragma message This machine has no 64-bit integer type?
323 #endif
324 
325 //---------------------------------------------------------------------------
326 //32-bit float
327 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
328  #undef MAXTYPE_FLOAT
329  #define MAXTYPE_FLOAT 32
330  typedef float float32;
331 #else
332  #pragma message This machine has no 32-bit float type?
333 #endif
334 
335 //---------------------------------------------------------------------------
336 //64-bit float
337 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
338  #undef MAXTYPE_FLOAT
339  #define MAXTYPE_FLOAT 64
340  typedef double float64;
341 #else
342  #pragma message This machine has no 64-bit float type?
343 #endif
344 
345 //---------------------------------------------------------------------------
346 //80-bit float
347 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
348  #undef MAXTYPE_FLOAT
349  #define MAXTYPE_FLOAT 80
350  typedef long double float80;
351 #else
352  #pragma message This machine has no 80-bit float type?
353 #endif
354 
355 //***************************************************************************
356 // Nested functions
357 //***************************************************************************
358 
359 //Unices
360 #if defined (UNIX)
361  #define snwprintf swprintf
362 #endif
363 
364 //Windows - MSVC
365 #if defined (_MSC_VER)
366  #define snprintf _snprintf
367  #define snwprintf _snwprintf
368 #endif
369 
370 } //namespace
371 #endif
372