Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / platform.h
blob2803cbd50312b056a4b62133f1c0c76df9588e5a
1 //
2 // Copyright (C) 2007 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file platform.h
22 * Header file for platform dependent macros and constants.
25 #pragma once
28 * Little/big endianism
31 #ifdef IS_BIG_ENDIAN
33 # include "types.h"
35 # if (IS_BIG_ENDIAN == 1)
36 # define PLATFORM_BIG_ENDIAN
38 // platform conversion functions
39 inline uint16 ToLittleEndian(uint16 v)
41 return (0x00FF & v) << 8 |
42 (0xFF00 & v) >> 8;
45 inline uint32 ToLittleEndian(uint32 v)
47 return (0x000000FF & v) << 24 |
48 (0x0000FF00 & v) << 8 |
49 (0x00FF0000 & v) >> 8 |
50 (0xFF000000 & v) >> 24;
53 inline uint16 ToBigEndian(uint16 v)
55 return v;
58 inline uint32 ToBigEndian(uint32 v)
60 return v;
63 # else /* (IS_BIG_ENDIAN == 1) */
64 # define PLATFORM_LITTLE_ENDIAN
66 // platform conversion functions
67 inline uint16 ToLittleEndian(uint16 v)
69 return v;
72 inline uint32 ToLittleEndian(uint32 v)
74 return v;
77 inline uint16 ToBigEndian(uint16 v)
79 return (0x00FF & v) << 8 |
80 (0xFF00 & v) >> 8;
83 inline uint32 ToBigEndian(uint32 v)
85 return (0x000000FF & v) << 24 |
86 (0x0000FF00 & v) << 8 |
87 (0x00FF0000 & v) >> 8 |
88 (0xFF000000 & v) >> 24;
91 # endif /* (IS_BIG_ENDIAN == 1) */
92 #endif /* IS_BIG_ENDIAN */
95 * Platform/compiler detection
98 #ifdef _MSC_VER
99 # define PLATFORM_MSVC
100 #else
101 # ifdef __GNUC__
102 # define PLATFORM_GCC
103 # ifdef linux
104 # define PLATFORM_GCC_LINUX
105 # else
106 # define PLATFORM_GCC_WIN
107 # endif /* linux */
108 # else
109 # error Unknown compiler!
110 # endif /* __GNUC__ */
111 #endif /* _MSC_VER */
113 #if defined(_DEBUG) && !defined(DEBUG)
114 # define DEBUG
115 #endif
118 * Platform dependent macros
120 #ifdef PLATFORM_MSVC
122 # define lseek _lseek
123 # define read _read
124 # define write _write
126 # define snprintf _snprintf
127 # define strcasecmp _stricmp
129 // to get clearer compiler output
130 # pragma warning( disable : 4290 )
131 # pragma warning( disable : 4996 )
133 // conversion from 'x' to 'y', possible loss of data
134 # pragma warning( disable : 4244 )
136 # pragma warning( disable : 4345 )
138 #endif /* PLATFORM_MSVC */
140 #ifdef PLATFORM_GCC
142 #define __FUNCTION__ __PRETTY_FUNCTION__
144 #endif /* PLATFORM_GCC */
147 * Build name - for creating project dependent logfiles, etc.
149 extern const char * gBuildName;