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