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 #if defined(__UNICODE__)
223  #if defined (_MSC_VER) && !defined (_NATIVE_WCHAR_T_DEFINED)
224  #pragma message Native wchar_t is not defined, not tested, you should put /Zc:wchar_t in compiler options
225  #endif
226  typedef wchar_t Char;
227  #undef __T
228  #define __T(__x) L ## __x
229 #else // defined(__UNICODE__)
230  typedef char Char;
231  #undef __T
232  #define __T(__x) __x
233 #endif // defined(__UNICODE__)
234 #ifdef wchar_t
235  typedef wchar_t wchar;
236 #endif // wchar_t
237 
238 //***************************************************************************
239 // Platform differences
240 //***************************************************************************
241 
242 //End of line
243 extern const Char* EOL;
244 extern const Char PathSeparator;
245 
246 //***************************************************************************
247 // Types
248 //***************************************************************************
249 
250 //---------------------------------------------------------------------------
251 //int
252 typedef signed int ints;
253 typedef unsigned int intu;
254 
255 //---------------------------------------------------------------------------
256 //8-bit int
257 #if UCHAR_MAX==0xff
258  #undef MAXTYPE_INT
259  #define MAXTYPE_INT 8
260  typedef signed char int8s;
261  typedef unsigned char int8u;
262 #else
263  #pragma message This machine has no 8-bit integertype?
264 #endif
265 
266 //---------------------------------------------------------------------------
267 //16-bit int
268 #if UINT_MAX == 0xffff
269  #undef MAXTYPE_INT
270  #define MAXTYPE_INT 16
271  typedef signed int int16s;
272  typedef unsigned int int16u;
273 #elif USHRT_MAX == 0xffff
274  #undef MAXTYPE_INT
275  #define MAXTYPE_INT 16
276  typedef signed short int16s;
277  typedef unsigned short int16u;
278 #else
279  #pragma message This machine has no 16-bit integertype?
280 #endif
281 
282 //---------------------------------------------------------------------------
283 //32-bit int
284 #if UINT_MAX == 0xfffffffful
285  #undef MAXTYPE_INT
286  #define MAXTYPE_INT 32
287  typedef signed int int32s;
288  typedef unsigned int int32u;
289 #elif ULONG_MAX == 0xfffffffful
290  #undef MAXTYPE_INT
291  #define MAXTYPE_INT 32
292  typedef signed long int32s;
293  typedef unsigned long int32u;
294 #elif USHRT_MAX == 0xfffffffful
295  #undef MAXTYPE_INT
296  #define MAXTYPE_INT 32
297  typedef signed short int32s;
298  typedef unsigned short int32u;
299 #else
300  #pragma message This machine has no 32-bit integer type?
301 #endif
302 
303 //---------------------------------------------------------------------------
304 //64-bit int
305 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
306  #undef MAXTYPE_INT
307  #define MAXTYPE_INT 64
308  typedef signed long long int64s;
309  typedef unsigned long long int64u;
310 #elif defined(__WIN32__)
311  #undef MAXTYPE_INT
312  #define MAXTYPE_INT 64
313  typedef signed __int64 int64s;
314  typedef unsigned __int64 int64u;
315 #else
316  #pragma message This machine has no 64-bit integer type?
317 #endif
318 
319 //---------------------------------------------------------------------------
320 //32-bit float
321 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
322  #undef MAXTYPE_FLOAT
323  #define MAXTYPE_FLOAT 32
324  typedef float float32;
325 #else
326  #pragma message This machine has no 32-bit float type?
327 #endif
328 
329 //---------------------------------------------------------------------------
330 //64-bit float
331 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
332  #undef MAXTYPE_FLOAT
333  #define MAXTYPE_FLOAT 64
334  typedef double float64;
335 #else
336  #pragma message This machine has no 64-bit float type?
337 #endif
338 
339 //---------------------------------------------------------------------------
340 //80-bit float
341 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
342  #undef MAXTYPE_FLOAT
343  #define MAXTYPE_FLOAT 80
344  typedef long double float80;
345 #else
346  #pragma message This machine has no 80-bit float type?
347 #endif
348 
349 //***************************************************************************
350 // Nested functions
351 //***************************************************************************
352 
353 //Unices
354 #if defined (UNIX)
355  #define snwprintf swprintf
356 #endif
357 
358 //Windows - MSVC
359 #if defined (_MSC_VER)
360  #define snprintf _snprintf
361  #define snwprintf _snwprintf
362 #endif
363 
364 } //namespace
365 #endif
366