ZenLib
Conf.h
Go to the documentation of this file.
00001 // ZenLib::ZenTypes - To be independant of platform & compiler
00002 // Copyright (C) 2002-2011 MediaArea.net SARL, Info@MediaArea.net
00003 //
00004 // This software is provided 'as-is', without any express or implied
00005 // warranty.  In no event will the authors be held liable for any damages
00006 // arising from the use of this software.
00007 //
00008 // Permission is granted to anyone to use this software for any purpose,
00009 // including commercial applications, and to alter it and redistribute it
00010 // freely, subject to the following restrictions:
00011 //
00012 // 1. The origin of this software must not be misrepresented; you must not
00013 //    claim that you wrote the original software. If you use this software
00014 //    in a product, an acknowledgment in the product documentation would be
00015 //    appreciated but is not required.
00016 // 2. Altered source versions must be plainly marked as such, and must not be
00017 //    misrepresented as being the original software.
00018 // 3. This notice may not be removed or altered from any source distribution.
00019 //
00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00021 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 
00023 //---------------------------------------------------------------------------
00024 #ifndef ZenConfH
00025 #define ZenConfH
00026 //---------------------------------------------------------------------------
00027 
00028 #include <stddef.h>
00029 
00030 //***************************************************************************
00031 // Platforms
00032 //***************************************************************************
00033 
00034 //---------------------------------------------------------------------------
00035 //Win32
00036 #if defined(__NT__) || defined(_WIN32) || defined(WIN32)
00037     #ifndef WIN32
00038         #define WIN32
00039     #endif
00040     #ifndef _WIN32
00041         #define _WIN32
00042     #endif
00043     #ifndef __WIN32__
00044         #define __WIN32__ 1
00045     #endif
00046 #endif
00047 
00048 //---------------------------------------------------------------------------
00049 //Win64
00050 #if defined(_WIN64) || defined(WIN64)
00051     #ifndef WIN64
00052         #define WIN64
00053     #endif
00054     #ifndef _WIN64
00055         #define _WIN64
00056     #endif
00057     #ifndef __WIN64__
00058         #define __WIN64__ 1
00059     #endif
00060 #endif
00061 
00062 //---------------------------------------------------------------------------
00063 //Windows
00064 #if defined(WIN32) || defined(WIN64)
00065     #ifndef WINDOWS
00066         #define WINDOWS
00067     #endif
00068     #ifndef _WINDOWS
00069         #define _WINDOWS
00070     #endif
00071     #ifndef __WINDOWS__
00072         #define __WINDOWS__ 1
00073     #endif
00074 #endif
00075 
00076 //---------------------------------------------------------------------------
00077 //Unix (Linux, HP, Sun, BeOS...)
00078 #if defined(UNIX) || defined(_UNIX) || defined(__UNIX__) \
00079     || defined(__unix) || defined(__unix__) \
00080     || defined(____SVR4____) || defined(__LINUX__) || defined(__sgi) \
00081     || defined(__hpux) || defined(sun) || defined(__SUN__) || defined(_AIX) \
00082     || defined(__EMX__) || defined(__VMS) || defined(__BEOS__)
00083     #ifndef UNIX
00084         #define UNIX
00085     #endif
00086     #ifndef _UNIX
00087         #define _UNIX
00088     #endif
00089     #ifndef __UNIX__
00090         #define __UNIX__ 1
00091     #endif
00092 #endif
00093 
00094 //---------------------------------------------------------------------------
00095 //MacOS Classic
00096 #if defined(macintosh)
00097     #ifndef MACOS
00098         #define MACOS
00099     #endif
00100     #ifndef _MACOS
00101         #define _MACOS
00102     #endif
00103     #ifndef __MACOS__
00104         #define __MACOS__ 1
00105     #endif
00106 #endif
00107 
00108 //---------------------------------------------------------------------------
00109 //MacOS X
00110 #if defined(__APPLE__) && defined(__MACH__)
00111     #ifndef MACOSX
00112         #define MACOSX
00113     #endif
00114     #ifndef _MACOSX
00115         #define _MACOSX
00116     #endif
00117     #ifndef __MACOSX__
00118         #define __MACOSX__ 1
00119     #endif
00120 #endif
00121 
00122 //Test of targets
00123 #if defined(WINDOWS) && defined(UNIX) && defined(MACOS) && defined(MACOSX)
00124     #pragma message Multiple platforms???
00125 #endif
00126 
00127 #if !defined(WIN32) && !defined(UNIX) && !defined(MACOS) && !defined(MACOSX)
00128     #pragma message No known platforms, assume default
00129 #endif
00130 
00131 //***************************************************************************
00132 // Internationnal
00133 //***************************************************************************
00134 
00135 //---------------------------------------------------------------------------
00136 //Unicode
00137 #if defined(_UNICODE) || defined(UNICODE) || defined(__UNICODE__)
00138     #ifndef _UNICODE
00139         #define _UNICODE
00140     #endif
00141     #ifndef UNICODE
00142         #define UNICODE
00143     #endif
00144     #ifndef __UNICODE__
00145         #define __UNICODE__ 1
00146     #endif
00147 #endif
00148 
00149 //---------------------------------------------------------------------------
00150 //wchar_t stuff
00151 #if defined(MACOS) || defined(MACOSX)
00152     #include <wchar.h>
00153 #endif
00154 
00155 //***************************************************************************
00156 // Compiler bugs/unuseful warning
00157 //***************************************************************************
00158 
00159 //MSVC6 : for(int t=0; t<10; ++t) { do something }; for(int t=0; t<10; ++t) { do something }
00160 #if defined(_MSC_VER) && _MSC_VER <= 1200
00161     #define for if(true)for
00162     #pragma warning(disable:4786) // MSVC6 doesn't like typenames longer than 255 chars (which generates an enormous amount of warnings).
00163 #endif
00164 
00165 //MSVC2005 : "deprecated" warning (replacement functions are not in MinGW32 or Borland!)
00166 #if defined(_MSC_VER) && _MSC_VER >= 1400
00167     #pragma warning(disable : 4996)
00168 #endif
00169 
00170 //***************************************************************************
00171 // (Without Namespace)
00172 //***************************************************************************
00173 
00174 //---------------------------------------------------------------------------
00175 #include <limits.h>
00176 
00177 //---------------------------------------------------------------------------
00178 #if defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
00179     #include "ZenLib/MemoryDebug.h"
00180 #endif // defined(ZENLIB_DEBUG) && (defined(DEBUG) || defined(_DEBUG))
00181 
00182 //***************************************************************************
00183 // Compiler helpers
00184 //***************************************************************************
00185 
00186 //---------------------------------------------------------------------------
00187 //Macro to cut down on compiler warnings
00188 #ifndef UNUSED
00189     #define UNUSED(Identifier)
00190 #endif
00191 //---------------------------------------------------------------------------
00192 //If we need size_t specific integer conversion
00193 #if defined(__LP64__) || defined(MACOSX)
00194     #define NEED_SIZET
00195 #endif
00196 
00197 //---------------------------------------------------------------------------
00198 //(-1) is known to be the MAX of an unsigned int but GCC complains about it
00199 #include <new>
00200 #include <cstring> //size_t
00201 namespace ZenLib
00202 {
00203     const std::size_t Error=((std::size_t)(-1));
00204     const std::size_t All=((std::size_t)(-1));
00205     const std::size_t Unlimited=((std::size_t)(-1));
00206 }
00207 
00208 //***************************************************************************
00209 // (With namespace)
00210 //***************************************************************************
00211 
00212 namespace ZenLib
00213 {
00214 
00215 //***************************************************************************
00216 // International
00217 //***************************************************************************
00218 
00219 //---------------------------------------------------------------------------
00220 //Char types
00221 #undef  _T
00222 #define _T(__x)     __T(__x)
00223 #undef  _TEXT
00224 #define _TEXT(__x)  __T(__x)
00225 #undef  __TEXT
00226 #define __TEXT(__x) __T(__x)
00227 #if defined(__UNICODE__)
00228     #if defined (_MSC_VER) && !defined (_NATIVE_WCHAR_T_DEFINED)
00229         #pragma message Native wchar_t is not defined, not tested, you should put /Zc:wchar_t in compiler options
00230     #endif
00231     typedef wchar_t Char;
00232     #undef  __T
00233     #define __T(__x) L##__x
00234 #else // defined(__UNICODE__)
00235     typedef char Char;
00236     #undef  __T
00237     #define __T(__x) __x
00238 #endif // defined(__UNICODE__)
00239 #ifdef wchar_t
00240     typedef wchar_t wchar;
00241 #endif // wchar_t
00242 
00243 //***************************************************************************
00244 // Platform differences
00245 //***************************************************************************
00246 
00247 //End of line
00248 extern const Char* EOL;
00249 extern const Char  PathSeparator;
00250 
00251 //***************************************************************************
00252 // Types
00253 //***************************************************************************
00254 
00255 //---------------------------------------------------------------------------
00256 //int
00257 typedef signed   int            ints;
00258 typedef unsigned int            intu;
00259 
00260 //---------------------------------------------------------------------------
00261 //8-bit int
00262 #if UCHAR_MAX==0xff
00263     #undef  MAXTYPE_INT
00264     #define MAXTYPE_INT 8
00265     typedef signed   char       int8s;
00266     typedef unsigned char       int8u;
00267 #else
00268     #pragma message This machine has no 8-bit integertype?
00269 #endif
00270 
00271 //---------------------------------------------------------------------------
00272 //16-bit int
00273 #if UINT_MAX == 0xffff
00274     #undef  MAXTYPE_INT
00275     #define MAXTYPE_INT 16
00276     typedef signed   int        int16s;
00277     typedef unsigned int        int16u;
00278 #elif USHRT_MAX == 0xffff
00279     #undef  MAXTYPE_INT
00280     #define MAXTYPE_INT 16
00281     typedef signed   short      int16s;
00282     typedef unsigned short      int16u;
00283 #else
00284     #pragma message This machine has no 16-bit integertype?
00285 #endif
00286 
00287 //---------------------------------------------------------------------------
00288 //32-bit int
00289 #if UINT_MAX == 0xfffffffful
00290     #undef  MAXTYPE_INT
00291     #define MAXTYPE_INT 32
00292     typedef signed   int        int32s;
00293     typedef unsigned int        int32u;
00294 #elif ULONG_MAX == 0xfffffffful
00295     #undef  MAXTYPE_INT
00296     #define MAXTYPE_INT 32
00297     typedef signed   long       int32s;
00298     typedef unsigned long       int32u;
00299 #elif USHRT_MAX == 0xfffffffful
00300     #undef  MAXTYPE_INT
00301     #define MAXTYPE_INT 32
00302     typedef signed   short      int32s;
00303     typedef unsigned short      int32u;
00304 #else
00305     #pragma message This machine has no 32-bit integer type?
00306 #endif
00307 
00308 //---------------------------------------------------------------------------
00309 //64-bit int
00310 #if defined(__MINGW32__) || defined(__CYGWIN32__) || defined(__UNIX__) || defined(__MACOSX__)
00311     #undef  MAXTYPE_INT
00312     #define MAXTYPE_INT 64
00313     typedef signed   long long  int64s;
00314     typedef unsigned long long  int64u;
00315 #elif defined(__WIN32__)
00316     #undef  MAXTYPE_INT
00317     #define MAXTYPE_INT 64
00318     typedef signed   __int64    int64s;
00319     typedef unsigned __int64    int64u;
00320 #else
00321     #pragma message This machine has no 64-bit integer type?
00322 #endif
00323 
00324 //---------------------------------------------------------------------------
00325 //32-bit float
00326 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
00327     #undef  MAXTYPE_FLOAT
00328     #define MAXTYPE_FLOAT 32
00329     typedef float                float32;
00330 #else
00331     #pragma message This machine has no 32-bit float type?
00332 #endif
00333 
00334 //---------------------------------------------------------------------------
00335 //64-bit float
00336 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
00337     #undef  MAXTYPE_FLOAT
00338     #define MAXTYPE_FLOAT 64
00339     typedef double                float64;
00340 #else
00341     #pragma message This machine has no 64-bit float type?
00342 #endif
00343 
00344 //---------------------------------------------------------------------------
00345 //80-bit float
00346 #if defined(WINDOWS) || defined(UNIX) || defined(MACOSX)
00347     #undef  MAXTYPE_FLOAT
00348     #define MAXTYPE_FLOAT 80
00349     typedef long double           float80;
00350 #else
00351     #pragma message This machine has no 80-bit float type?
00352 #endif
00353 
00354 //***************************************************************************
00355 // Nested functions
00356 //***************************************************************************
00357 
00358 //Unices
00359 #if defined (UNIX)
00360     #define snwprintf swprintf
00361 #endif
00362 
00363 //Windows - MSVC
00364 #if defined (_MSC_VER)
00365     #define snprintf _snprintf
00366     #define snwprintf _snwprintf
00367 #endif
00368 
00369 } //namespace
00370 #endif
00371