Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef STDAFX_H
00013 #define STDAFX_H
00014
00015 #if defined(__APPLE__)
00016 #include "os/macosx/osx_stdafx.h"
00017 #endif
00018
00019 #if defined(__BEOS__) || defined(__HAIKU__)
00020 #include <SupportDefs.h>
00021 #include <unistd.h>
00022 #define _GNU_SOURCE
00023 #define TROUBLED_INTS
00024 #elif defined(__NDS__)
00025 #include <nds/jtypes.h>
00026 #define TROUBLED_INTS
00027 #endif
00028
00029
00030
00031
00032
00033 #if defined(__APPLE__)
00034
00035 #elif !defined(_MSC_VER) && !defined( __MORPHOS__) && !defined(_STDINT_H_)
00036 #if defined(SUNOS)
00037
00038
00039 #include <inttypes.h>
00040 # else
00041 #define __STDC_LIMIT_MACROS
00042 #include <stdint.h>
00043 #endif
00044 #else
00045 #define UINT64_MAX (18446744073709551615ULL)
00046 #define INT64_MAX (9223372036854775807LL)
00047 #define INT64_MIN (-INT64_MAX - 1)
00048 #define UINT32_MAX (4294967295U)
00049 #define INT32_MAX (2147483647)
00050 #define INT32_MIN (-INT32_MAX - 1)
00051 #define UINT16_MAX (65535U)
00052 #define INT16_MAX (32767)
00053 #define INT16_MIN (-INT16_MAX - 1)
00054 #define UINT8_MAX (255)
00055 #define INT8_MAX (127)
00056 #define INT8_MIN (-INT8_MAX - 1)
00057 #endif
00058
00059 #include <cstdio>
00060 #include <cstddef>
00061 #include <cstring>
00062 #include <cstdlib>
00063 #include <climits>
00064 #include <cassert>
00065
00066 #ifndef SIZE_MAX
00067 #define SIZE_MAX ((size_t)-1)
00068 #endif
00069
00070 #if defined(UNIX) || defined(__MINGW32__)
00071 #include <sys/types.h>
00072 #endif
00073
00074 #if defined(__OS2__)
00075 #include <types.h>
00076 #define strcasecmp stricmp
00077 #endif
00078
00079 #if defined(PSP)
00080 #include <psptypes.h>
00081 #include <pspdebug.h>
00082 #include <pspthreadman.h>
00083 #endif
00084
00085 #if defined(SUNOS) || defined(HPUX)
00086 #include <alloca.h>
00087 #endif
00088
00089 #if defined(__MORPHOS__)
00090
00091
00092
00093 #if defined(amigaos)
00094 #undef amigaos
00095 #endif
00096 #if defined(__amigaos__)
00097 #undef __amigaos__
00098 # endif
00099 #if defined(__AMIGA__)
00100 #undef __AMIGA__
00101 #endif
00102 #if defined(AMIGA)
00103 #undef AMIGA
00104 #endif
00105 #if defined(amiga)
00106 #undef amiga
00107 #endif
00108
00109
00110 #define CLIB_USERGROUP_PROTOS_H
00111 #endif
00112
00113 #if defined(PSP)
00114
00115
00116
00117 #define LIMITED_FDS 8
00118 #define printf pspDebugScreenPrintf
00119 #endif
00120
00121
00122 #if defined(__GNUC__)
00123 #define NORETURN __attribute__ ((noreturn))
00124 #define FORCEINLINE inline
00125 #define CDECL
00126 #define __int64 long long
00127 #define GCC_PACK __attribute__((packed))
00128
00129
00130 #define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
00131 #endif
00132
00133 #if defined(__WATCOMC__)
00134 #define NORETURN
00135 #define FORCEINLINE inline
00136 #define CDECL
00137 #define GCC_PACK
00138 #define WARN_FORMAT(string, args)
00139 #include <malloc.h>
00140 #endif
00141
00142 #if defined(__MINGW32__) || defined(__CYGWIN__)
00143 #include <malloc.h>
00144 #endif
00145
00146 #if defined(WIN32)
00147 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
00148 #endif
00149
00150
00151 #if defined(_MSC_VER)
00152 #pragma once
00153
00154
00155 #define NTDDI_VERSION NTDDI_WIN2K // Windows 2000
00156 #define _WIN32_WINNT 0x0500 // Windows 2000
00157 #define _WIN32_WINDOWS 0x400 // Windows 95
00158 #if !defined(WINCE)
00159 #define WINVER 0x0400 // Windows NT 4.0 / Windows 95
00160 #endif
00161 #define _WIN32_IE_ 0x0401 // 4.01 (win98 and NT4SP5+)
00162
00163 #pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data
00164 #pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied
00165 #pragma warning(disable: 4200) // nonstandard extension used : zero-sized array in struct/union
00166
00167 #if (_MSC_VER < 1400) // MSVC 2005 safety checks
00168 #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not! Upgrade your compiler."
00169 #endif
00170 #pragma warning(disable: 4291) // no matching operator delete found; memory will not be freed if initialization throws an exception (reason: our overloaded functions never throw an exception)
00171 #pragma warning(disable: 4996) // 'function': was declared deprecated
00172 #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
00173 #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked
00174 #pragma warning(disable: 6011) // code analyzer: Dereferencing NULL pointer 'pfGetAddrInfo': Lines: 995, 996, 998, 999, 1001
00175 #pragma warning(disable: 6326) // code analyzer: potential comparison of a constant with another constant
00176 #pragma warning(disable: 6031) // code analyzer: Return value ignored: 'ReadFile'
00177 #pragma warning(disable: 6255) // code analyzer: _alloca indicates failure by raising a stack overflow exception. Consider using _malloca instead
00178 #pragma warning(disable: 6246) // code analyzer: Local declaration of 'statspec' hides declaration of the same name in outer scope. For additional information, see previous declaration at ...
00179 #define WARN_FORMAT(string, args)
00180
00181 #include <malloc.h>
00182 #define NORETURN __declspec(noreturn)
00183 #define FORCEINLINE __forceinline
00184 #define inline _inline
00185
00186 #if !defined(WINCE)
00187 #define CDECL _cdecl
00188 #endif
00189
00190 #define GCC_PACK
00191
00192 int CDECL snprintf(char *str, size_t size, const char *format, ...) WARN_FORMAT(3, 4);
00193 #if defined(WINCE)
00194 int CDECL vsnprintf(char *str, size_t size, const char *format, va_list ap);
00195 #endif
00196
00197 #if defined(WIN32) && !defined(_WIN64) && !defined(WIN64)
00198 #if !defined(_W64)
00199 #define _W64
00200 #endif
00201
00202 typedef _W64 int INT_PTR, *PINT_PTR;
00203 typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
00204 #endif
00205
00206 #if defined(_WIN64) || defined(WIN64)
00207 #define fseek _fseeki64
00208 #endif
00209
00210
00211 #if defined(WITH_ZLIB) || defined(WITH_PNG)
00212 #if !defined(ZLIB_WINAPI)
00213 #define ZLIB_WINAPI
00214 #endif
00215 #endif
00216
00217 #if defined(WINCE)
00218 #define strcasecmp _stricmp
00219 #define strncasecmp _strnicmp
00220 #undef DEBUG
00221 #else
00222 #define strcasecmp stricmp
00223 #define strncasecmp strnicmp
00224 #endif
00225
00226
00227 #define S_ISDIR(mode) (mode & S_IFDIR)
00228 #define S_ISREG(mode) (mode & S_IFREG)
00229
00230 #endif
00231
00232 #if defined(DOS)
00233
00234 #define strsignal(sig) ""
00235
00236
00237
00238 #define SIGBUS SIGNOFP
00239 #endif
00240
00241 #if defined(WINCE)
00242 #define strdup _strdup
00243 #endif
00244
00245
00246
00247 #if !defined(STRGEN) && !defined(SETTINGSGEN)
00248 #if defined(WIN32) || defined(WIN64)
00249 char *getcwd(char *buf, size_t size);
00250 #include <tchar.h>
00251 #include <io.h>
00252
00253
00254 #if !defined(WINCE)
00255 namespace std { using ::_tfopen; }
00256 #define fopen(file, mode) _tfopen(OTTD2FS(file), _T(mode))
00257 #define unlink(file) _tunlink(OTTD2FS(file))
00258 #endif
00259
00260 const char *FS2OTTD(const TCHAR *name);
00261 const TCHAR *OTTD2FS(const char *name);
00262 #define SQ2OTTD(name) FS2OTTD(name)
00263 #define OTTD2SQ(name) OTTD2FS(name)
00264 #else
00265 #define fopen(file, mode) fopen(OTTD2FS(file), mode)
00266 const char *FS2OTTD(const char *name);
00267 const char *OTTD2FS(const char *name);
00268 #define SQ2OTTD(name) (name)
00269 #define OTTD2SQ(name) (name)
00270 #endif
00271 #endif
00272
00273 #if defined(WIN32) || defined(WIN64) || defined(__OS2__) && !defined(__INNOTEK_LIBC__)
00274 #define PATHSEP "\\"
00275 #define PATHSEPCHAR '\\'
00276 #else
00277 #define PATHSEP "/"
00278 #define PATHSEPCHAR '/'
00279 #endif
00280
00281
00282 #if defined(_MSC_VER) || defined(__MINGW32__)
00283 #define OTTD_PRINTF64 "%I64d"
00284 #define OTTD_PRINTFHEX64 "%I64x"
00285 #define PRINTF_SIZE "%Iu"
00286 #else
00287 #define OTTD_PRINTF64 "%lld"
00288 #define OTTD_PRINTFHEX64 "%llx"
00289 #define PRINTF_SIZE "%zu"
00290 #endif
00291
00292 typedef unsigned char byte;
00293
00294
00295 #if (!defined(UNIX) && !defined(__CYGWIN__) && !defined(__BEOS__) && !defined(__HAIKU__) && !defined(__MORPHOS__)) || defined(__QNXNTO__)
00296 typedef unsigned int uint;
00297 #endif
00298
00299 #if defined(TROUBLED_INTS)
00300
00301
00302 #define uint32 uint32_ugly_hack
00303 #define int32 int32_ugly_hack
00304 typedef unsigned int uint32_ugly_hack;
00305 typedef signed int int32_ugly_hack;
00306 #else
00307 typedef unsigned char uint8;
00308 typedef signed char int8;
00309 typedef unsigned short uint16;
00310 typedef signed short int16;
00311 typedef unsigned int uint32;
00312 typedef signed int int32;
00313 typedef unsigned __int64 uint64;
00314 typedef signed __int64 int64;
00315 #endif
00316
00317 #if !defined(WITH_PERSONAL_DIR)
00318 #define PERSONAL_DIR ""
00319 #endif
00320
00321
00322
00323
00324 #if defined(__STDCXX_VERSION__) || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__) || defined(static_assert)
00325
00326 #define assert_compile(expr) static_assert(expr, #expr )
00327 #define assert_tcompile(expr) assert_compile(expr)
00328 #elif defined(__OS2__)
00329
00330 #define assert_compile(expr)
00331 #define assert_tcompile(expr) assert_compile(expr)
00332 #else
00333 #define assert_compile(expr) typedef int __ct_assert__[1 - 2 * !(expr)]
00334 #define assert_tcompile(expr) assert(expr)
00335 #endif
00336
00337
00338 assert_compile(sizeof(uint64) == 8);
00339 assert_compile(sizeof(uint32) == 4);
00340 assert_compile(sizeof(uint16) == 2);
00341 assert_compile(sizeof(uint8) == 1);
00342 assert_compile(SIZE_MAX >= UINT32_MAX);
00343
00344 #ifndef M_PI_2
00345 #define M_PI_2 1.57079632679489661923
00346 #define M_PI 3.14159265358979323846
00347 #endif
00348
00357 #define lengthof(x) (sizeof(x) / sizeof(x[0]))
00358
00365 #define endof(x) (&x[lengthof(x)])
00366
00373 #define lastof(x) (&x[lengthof(x) - 1])
00374
00375 #define cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8)
00376 #if !defined(offsetof)
00377 #define offsetof(s, m) cpp_offsetof(s, m)
00378 #endif
00379
00386 #define cpp_sizeof(base, variable) (sizeof(((base*)8)->variable))
00387
00394 #define cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0]))
00395
00396
00397
00398 #if defined(__APPLE__)
00399 #define GetString OTTD_GetString
00400 #define DrawString OTTD_DrawString
00401 #define CloseConnection OTTD_CloseConnection
00402 #endif
00403
00404 void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
00405 void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
00406 #define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
00407
00408
00409
00410
00411
00412 #if (defined(_MSC_VER) && defined(NDEBUG) && defined(WITH_ASSERT)) || (!defined(_MSC_VER) && !defined(NDEBUG) && !defined(_DEBUG))
00413 #undef assert
00414 #define assert(expression) if (!(expression)) error("Assertion failed at line %i of %s: %s", __LINE__, __FILE__, #expression);
00415 #endif
00416
00417
00418 #if !defined(NDEBUG) || (defined(_MSC_VER) && defined(WITH_ASSERT))
00419 #define OTTD_ASSERT
00420 #endif
00421
00422 #if defined(MORPHOS) || defined(__NDS__) || defined(__DJGPP__)
00423
00424 #define _stricmp stricmp
00425 #elif defined(OPENBSD)
00426
00427 #define _stricmp strcasecmp
00428 #endif
00429
00430 #if defined(MAX_PATH)
00431
00432 #elif defined(PATH_MAX) && PATH_MAX > 0
00433
00434 #define MAX_PATH PATH_MAX
00435 #else
00436
00437 #define MAX_PATH 260
00438 #endif
00439
00444 static FORCEINLINE void free(const void *ptr)
00445 {
00446 free(const_cast<void *>(ptr));
00447 }
00448
00453 #define MAX_UVALUE(type) ((type)~(type)0)
00454
00455 #endif