]> git.lizzy.rs Git - irrlicht.git/blob - include/irrTypes.h
Merging r5975 through r6036 from trunk to ogl-es branch.
[irrlicht.git] / include / irrTypes.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __IRR_TYPES_H_INCLUDED__\r
6 #define __IRR_TYPES_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 \r
10 #if defined(__GNUC__)\r
11         #include <limits.h>     // for __WORDSIZE\r
12 #endif\r
13 \r
14 namespace irr\r
15 {\r
16 \r
17 //! 8 bit unsigned variable.\r
18 /** This is a typedef for unsigned char, it ensures portability of the engine. */\r
19 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
20 typedef unsigned __int8         u8;\r
21 #else\r
22 typedef unsigned char           u8;\r
23 #endif\r
24 \r
25 //! 8 bit signed variable.\r
26 /** This is a typedef for signed char, it ensures portability of the engine. */\r
27 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
28 typedef __int8                  s8;\r
29 #else\r
30 typedef signed char             s8;\r
31 #endif\r
32 \r
33 //! 8 bit character variable.\r
34 /** This is a typedef for char, it ensures portability of the engine. */\r
35 typedef char                    c8;\r
36 \r
37 \r
38 \r
39 //! 16 bit unsigned variable.\r
40 /** This is a typedef for unsigned short, it ensures portability of the engine. */\r
41 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
42 typedef unsigned __int16        u16;\r
43 #else\r
44 typedef unsigned short          u16;\r
45 #endif\r
46 \r
47 //! 16 bit signed variable.\r
48 /** This is a typedef for signed short, it ensures portability of the engine. */\r
49 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
50 typedef __int16                 s16;\r
51 #else\r
52 typedef signed short            s16;\r
53 #endif\r
54 \r
55 \r
56 \r
57 //! 32 bit unsigned variable.\r
58 /** This is a typedef for unsigned int, it ensures portability of the engine. */\r
59 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
60 typedef unsigned __int32        u32;\r
61 #else\r
62 typedef unsigned int            u32;\r
63 #endif\r
64 \r
65 //! 32 bit signed variable.\r
66 /** This is a typedef for signed int, it ensures portability of the engine. */\r
67 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
68 typedef __int32                 s32;\r
69 #else\r
70 typedef signed int              s32;\r
71 #endif\r
72 \r
73 \r
74 #ifdef __IRR_HAS_S64\r
75 //! 64 bit unsigned variable.\r
76 /** This is a typedef for 64bit uint, it ensures portability of the engine. */\r
77 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
78 typedef unsigned __int64                        u64;\r
79 #elif defined(__GNUC__)\r
80 #if defined(__WORDSIZE) && __WORDSIZE == 64\r
81 typedef unsigned long int                       u64;\r
82 #else\r
83 __extension__ typedef unsigned long long        u64;\r
84 #endif\r
85 #else\r
86 typedef unsigned long long                      u64;\r
87 #endif\r
88 \r
89 //! 64 bit signed variable.\r
90 /** This is a typedef for 64bit int, it ensures portability of the engine. */\r
91 #if defined(_MSC_VER) || ((__BORLANDC__ >= 0x530) && !defined(__STRICT_ANSI__))\r
92 typedef __int64                                 s64;\r
93 #elif defined(__GNUC__)\r
94 #if defined(__WORDSIZE) && __WORDSIZE == 64\r
95 typedef long int                                s64;\r
96 #else\r
97 __extension__ typedef long long                 s64;\r
98 #endif\r
99 #else\r
100 typedef long long                               s64;\r
101 #endif\r
102 #endif  // __IRR_HAS_S64\r
103 \r
104 \r
105 \r
106 //! 32 bit floating point variable.\r
107 /** This is a typedef for float, it ensures portability of the engine. */\r
108 typedef float                           f32;\r
109 \r
110 //! 64 bit floating point variable.\r
111 /** This is a typedef for double, it ensures portability of the engine. */\r
112 typedef double                          f64;\r
113 \r
114 \r
115 } // end namespace irr\r
116 \r
117 \r
118 #include <wchar.h>\r
119 #ifdef _IRR_WINDOWS_API_\r
120 //! Defines for s{w,n}printf_irr because s{w,n}printf methods do not match the ISO C\r
121 //! standard on Windows platforms.\r
122 //! We want int snprintf_irr(char *str, size_t size, const char *format, ...);\r
123 //! and int swprintf_irr(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);\r
124 #if defined(_MSC_VER) && _MSC_VER > 1310 && !defined (_WIN32_WCE)\r
125 #define swprintf_irr swprintf_s\r
126 #define snprintf_irr sprintf_s\r
127 #elif !defined(__CYGWIN__)\r
128 #define swprintf_irr _snwprintf\r
129 #define snprintf_irr _snprintf\r
130 #endif\r
131 \r
132 // define the wchar_t type if not already built in.\r
133 #ifdef _MSC_VER\r
134 #ifndef _WCHAR_T_DEFINED\r
135 //! A 16 bit wide character type.\r
136 /**\r
137         Defines the wchar_t-type.\r
138         In VS6, its not possible to tell\r
139         the standard compiler to treat wchar_t as a built-in type, and\r
140         sometimes we just don't want to include the huge stdlib.h or wchar.h,\r
141         so we'll use this.\r
142 */\r
143 typedef unsigned short wchar_t;\r
144 #define _WCHAR_T_DEFINED\r
145 #endif // wchar is not defined\r
146 #endif // microsoft compiler\r
147 #else\r
148 #define swprintf_irr swprintf\r
149 #define snprintf_irr snprintf\r
150 #endif // _IRR_WINDOWS_API_\r
151 \r
152 namespace irr\r
153 {\r
154 \r
155 //! Type name for character type used by the file system.\r
156 /** Should the wide character version of the FileSystem be used it is a\r
157 16 bit character variable. Used for Unicode Filesystem and Unicode strings.\r
158 Else it is a 8 bit character variable. Used for ansi Filesystem and non-unicode\r
159 strings\r
160 */\r
161 #if defined(_IRR_WCHAR_FILESYSTEM)\r
162         typedef wchar_t fschar_t;\r
163         #define _IRR_TEXT(X) L##X\r
164 #else\r
165         typedef char fschar_t;\r
166         #define _IRR_TEXT(X) X\r
167 #endif\r
168 \r
169 } // end namespace irr\r
170 \r
171 //! define a break macro for debugging.\r
172 #if defined(_DEBUG)\r
173 #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && !defined (_WIN32_WCE)\r
174 #if defined(WIN64) || defined(_WIN64) // using portable common solution for x64 configuration\r
175         #include <crtdbg.h>\r
176         #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_CrtDbgBreak();}\r
177 #else\r
178         #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_asm int 3}\r
179 #endif\r
180 #else\r
181         #include "assert.h"\r
182         #define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) assert( !(_CONDITION_) );\r
183 #endif\r
184 #else\r
185         #define _IRR_DEBUG_BREAK_IF( _CONDITION_ )\r
186 #endif\r
187 \r
188 //! Defines a deprecated macro which generates a warning at compile time\r
189 /** The usage is simple\r
190 For typedef:            typedef _IRR_DEPRECATED_ int test1;\r
191 For classes/structs:    class _IRR_DEPRECATED_ test2 { ... };\r
192 For methods:            class test3 { _IRR_DEPRECATED_ virtual void foo() {} };\r
193 For functions:          template<class T> _IRR_DEPRECATED_ void test4(void) {}\r
194 **/\r
195 #if defined(IGNORE_DEPRECATED_WARNING)\r
196 #define _IRR_DEPRECATED_\r
197 #elif _MSC_VER >= 1310 //vs 2003 or higher\r
198 #define _IRR_DEPRECATED_ __declspec(deprecated)\r
199 #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) // all versions above 3.0 should support this feature\r
200 #define _IRR_DEPRECATED_  __attribute__ ((deprecated))\r
201 #else\r
202 #define _IRR_DEPRECATED_\r
203 #endif\r
204 \r
205 //! Defines an override macro, to protect virtual functions from typos and other mismatches\r
206 /** Usage in a derived class:\r
207 virtual void somefunc() _IRR_OVERRIDE_;\r
208 */\r
209 #if ( ((__GNUC__ > 4 ) || ((__GNUC__ == 4 ) && (__GNUC_MINOR__ >= 7))) && (defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L) )\r
210 #define _IRR_OVERRIDE_ override\r
211 #elif (_MSC_VER >= 1600 ) /* supported since MSVC 2010 */\r
212 #define _IRR_OVERRIDE_ override\r
213 #elif (__clang_major__ >= 3 && __has_feature(cxx_override_control))\r
214 #define _IRR_OVERRIDE_ override\r
215 #else\r
216 #define _IRR_OVERRIDE_\r
217 #endif\r
218 \r
219 // memory debugging\r
220 #if defined(_DEBUG) && defined(IRRLICHT_EXPORTS) && defined(_MSC_VER) && \\r
221         (_MSC_VER > 1299) && !defined(_IRR_DONT_DO_MEMORY_DEBUGGING_HERE) && !defined(_WIN32_WCE)\r
222 \r
223         #define CRTDBG_MAP_ALLOC\r
224         #define _CRTDBG_MAP_ALLOC\r
225         #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)\r
226         #include <stdlib.h>\r
227         #include <crtdbg.h>\r
228         #define new DEBUG_CLIENTBLOCK\r
229 #endif\r
230 \r
231 //! ignore VC8 warning deprecated\r
232 /** The Microsoft compiler */\r
233 #if defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER >= 1400)\r
234         //#pragma warning( disable: 4996)\r
235         //#define _CRT_SECURE_NO_DEPRECATE 1\r
236         //#define _CRT_NONSTDC_NO_DEPRECATE 1\r
237 #endif\r
238 \r
239 \r
240 //! creates four CC codes used in Irrlicht for simple ids\r
241 /** some compilers can create those by directly writing the\r
242 code like 'code', but some generate warnings so we use this macro here */\r
243 #define MAKE_IRR_ID(c0, c1, c2, c3) \\r
244                 ((irr::u32)(irr::u8)(c0) | ((irr::u32)(irr::u8)(c1) << 8) | \\r
245                 ((irr::u32)(irr::u8)(c2) << 16) | ((irr::u32)(irr::u8)(c3) << 24 ))\r
246 \r
247 #endif // __IRR_TYPES_H_INCLUDED__\r