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 
74 //---------------------------------------------------------------------------
75 //Unix (Linux, HP, Sun, BeOS...)
76 #if defined(UNIX) || defined(_UNIX) || defined(__UNIX__) \
77  || defined(__unix) || defined(__unix__) \
78  || defined(____SVR4____) || defined(__LINUX__) || defined(__sgi) \
79  || defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) \
80  || defined(__EMX__) || defined(__VMS) || defined(__BEOS__)
81  #ifndef UNIX
82  #define UNIX
83  #endif
84  #ifndef _UNIX
85  #define _UNIX
86  #endif
87  #ifndef __UNIX__
88  #define __UNIX__ 1
89  #endif
90 #endif
91 
92 //---------------------------------------------------------------------------
93 //MacOS Classic
94 #if defined(macintosh)
95  #ifndef MACOS
96  #define MACOS
97  #endif
98  #ifndef _MACOS
99  #define _MACOS
100  #endif
101  #ifndef __MACOS__
102  #define __MACOS__ 1
103  #endif
104 #endif
105 
106 //---------------------------------------------------------------------------
107 //MacOS X
108 #if defined(__APPLE__) && defined(__MACH__)
109  #ifndef MACOSX
110  #define MACOSX
111  #endif
112  #ifndef _MACOSX
113  #define _MACOSX
114  #endif
115  #ifndef __MACOSX__
116  #define __MACOSX__ 1
117  #endif
118 #endif
119 
120 //Test of targets
121 #if defined(WINDOWS) && defined(UNIX) && defined(MACOS) && defined(MACOSX)
122  #pragma message Multiple platforms???
123 #endif
124 
125 #if !defined(WIN32) && !defined(UNIX) && !defined(MACOS) && !defined(MACOSX)
126  #pragma message No known platforms, assume default
127 #endif
128 
129 //***************************************************************************
130 // Internationnal
131 //***************************************************************************
132 
133 //---------------------------------------------------------------------------
134 //Unicode
135 #if defined(_UNICODE) || defined(UNICODE) || defined(__UNICODE__)
136  #ifndef _UNICODE
137  #define _UNICODE
138  #endif
139  #ifndef UNICODE
140  #define UNICODE
141  #endif
142  #ifndef __UNICODE__
143  #define __UNICODE__ 1
144  #endif
145 #endif
146 
147 //---------------------------------------------------------------------------
148 //wchar_t stuff
149 #if defined(MACOS) || defined(MACOSX)
150  #include <wchar.h>
151 #endif
152 
153 //***************************************************************************
154 // Compiler bugs/unuseful warning
155 //***************************************************************************
156 
157 //MSVC6 : for(int t=0; t<10; ++t) { do something }; for(int t=0; t<10; ++t) { do something }
158 #if defined(_MSC_VER) && _MSC_VER <= 1200
159  #define for if(true)for
160  #pragma warning(disable:4786) // MSVC6 doesn't like typenames longer than 255 chars (which generates an enormous amount of warnings).
161 #endif
162 
163 //MSVC2005 : "deprecated" warning (replacement functions are not in MinGW32 or Borland!)
164 #if defined(_MSC_VER) && _MSC_VER >= 1400
165  #pragma warning(disable : 4996)
166 #endif
167 
168 //***************************************************************************
169 // (Without Namespace)
170 //***************************************************************************
171 
172 //---------------------------------------------------------------------------
173 #include <limits.h>
174 
175 //---------------------------------------------------------------------------
176 #if defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
177  #include "ZenLib/MemoryDebug.h"
178 #endif // defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
179 
180 //***************************************************************************
181 // Compiler helpers
182 //***************************************************************************
183 
184 //---------------------------------------------------------------------------
185 //Macro to cut down on compiler warnings
186 #ifndef UNUSED
187  #define UNUSED(Identifier)
188 #endif
189 //---------------------------------------------------------------------------
190 //If we need size_t specific integer conversion
191 #if !defined(SIZE_T_IS_LONG) && (defined(__LP64__) || defined(MACOSX))
192  #define SIZE_T_IS_LONG
193 #endif
194 
195 //---------------------------------------------------------------------------
196 //(-1) is known to be the MAX of an unsigned int but GCC complains about it
197 #include <new>
198 #include <cstring> //size_t
199 namespace ZenLib
200 {
201  const std::size_t Error=((std::size_t)(-1));
202  const std::size_t All=((std::size_t)(-1));
203  const std::size_t Unlimited=((std::size_t)(-1));
204 }
205 
206 //***************************************************************************
207 // (With namespace)
208 //***************************************************************************
209 
210 namespace ZenLib
211 {
212 
213 //***************************************************************************
214 // International
215 //***************************************************************************
216 
217 //---------------------------------------------------------------------------
218 //Char types
219 #undef _T
220 #define _T(__x) __T(__x)
221 #undef _TEXT
222 #define _TEXT(__x) __T(__x)
223 #undef __TEXT
224 #define __TEXT(__x) __T(__x)
225 #if defined(__UNICODE__)
226  #if defined (_MSC_VER) && !defined (_NATIVE_WCHAR_T_DEFINED)
227  #pragma message Native wchar_t is not defined, not tested, you should put /Zc:wchar_t in compiler options
228  #endif
229  typedef wchar_t Char;
230  #undef __T
231  #define __T(__x) L##__x
232 #else // defined(__UNICODE__)
233  typedef char Char;
234  #undef __T
235  #define __T(__x) __x
236 #endif // defined(__UNICODE__)
237 #ifdef wchar_t
238  typedef wchar_t wchar;
239 #endif // wchar_t
240 
241 //***************************************************************************
242 // Platform differences
243 //***************************************************************************
244 
245 //End of line
246 extern const Char* EOL;
247 extern const Char PathSeparator;
248 
249 //***************************************************************************
250 // Types
251 //***************************************************************************
252 
253 //---------------------------------------------------------------------------
254 //int
255 typedef signed int ints;
256 typedef unsigned int intu;
257 
258 //---------------------------------------------------------------------------
259 //8-bit int
260 #if UCHAR_MAX==0xff
261  #undef MAXTYPE_INT
262  #define MAXTYPE_INT 8
263  typedef signed char int8s;
264  typedef unsigned char int8u;
265 #else
266  #pragma message This machine has no 8-bit integertype?
267 #endif
268 
269 //---------------------------------------------------------------------------
270 //16-bit int
271 #if UINT_MAX == 0xffff
272  #undef MAXTYPE_INT
273  #define MAXTYPE_INT 16
274  typedef signed int int16s;
275  typedef unsigned int int16u;
276 #elif USHRT_MAX == 0xffff
277  #undef MAXTYPE_INT
278  #define MAXTYPE_INT 16
279  typedef signed short int16s;
280  typedef unsigned short int16u;
281 #else
282  #pragma message This machine has no 16-bit integertype?
283 #endif
284 
285 //---------------------------------------------------------------------------
286 //32-bit int
287 #if UINT_MAX == 0xfffffffful
288  #undef MAXTYPE_INT
289  #define MAXTYPE_INT 32
290  typedef signed int int32s;
291  typedef unsigned int int32u;
292 #elif ULONG_MAX == 0xfffffffful
293  #undef MAXTYPE_INT
294  #define MAXTYPE_INT 32
295  typedef signed long int32s;
296  typedef unsigned long int32u;
297 #elif USHRT_MAX == 0xfffffffful
298  #undef MAXTYPE_INT
299  #define MAXTYPE_INT 32
300  typedef signed short int32s;
301  typedef unsigned short int32u;
302 #else
303  #pragma message This machine has no 32-bit integer type?
304 #endif
305 
306 //---------------------------------------------------------------------------
307 //64-bit int
308 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
309  #undef MAXTYPE_INT
310  #define MAXTYPE_INT 64
311  typedef signed long long int64s;
312  typedef unsigned long long int64u;
313 #elif defined(__WIN32__)
314  #undef MAXTYPE_INT
315  #define MAXTYPE_INT 64
316  typedef signed __int64 int64s;
317  typedef unsigned __int64 int64u;
318 #else
319  #pragma message This machine has no 64-bit integer type?
320 #endif
321 
322 //---------------------------------------------------------------------------
323 //32-bit float
324 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
325  #undef MAXTYPE_FLOAT
326  #define MAXTYPE_FLOAT 32
327  typedef float float32;
328 #else
329  #pragma message This machine has no 32-bit float type?
330 #endif
331 
332 //---------------------------------------------------------------------------
333 //64-bit float
334 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
335  #undef MAXTYPE_FLOAT
336  #define MAXTYPE_FLOAT 64
337  typedef double float64;
338 #else
339  #pragma message This machine has no 64-bit float type?
340 #endif
341 
342 //---------------------------------------------------------------------------
343 //80-bit float
344 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
345  #undef MAXTYPE_FLOAT
346  #define MAXTYPE_FLOAT 80
347  typedef long double float80;
348 #else
349  #pragma message This machine has no 80-bit float type?
350 #endif
351 
352 //***************************************************************************
353 // Nested functions
354 //***************************************************************************
355 
356 //Unices
357 #if defined (UNIX)
358  #define snwprintf swprintf
359 #endif
360 
361 //Windows - MSVC
362 #if defined (_MSC_VER)
363  #define snprintf _snprintf
364  #define snwprintf _snwprintf
365 #endif
366 
367 } //namespace
368 #endif
369