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