Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_Types.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_Types.h
5 Content : Standard library defines and simple types
6 Created : September 19, 2012
7 Notes :
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 ************************************************************************************/
27 
28 #ifndef OVR_Types_H
29 #define OVR_Types_H
30 
31 //-----------------------------------------------------------------------------------
32 // ****** Operating System
33 //
34 // Type definitions exist for the following operating systems: (OVR_OS_x)
35 //
36 // WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
37 // DARWIN - Darwin OS (Mac OS X)
38 // LINUX - Linux
39 // ANDROID - Android
40 // IPHONE - iPhone
41 
42 #if (defined(__APPLE__) && (defined(__GNUC__) ||\
43  defined(__xlC__) || defined(__xlc__))) || defined(__MACOS__)
44 # if (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED))
45 # define OVR_OS_IPHONE
46 # else
47 # define OVR_OS_DARWIN
48 # define OVR_OS_MAC
49 # endif
50 #elif (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
51 # define OVR_OS_WIN32
52 #elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
53 # define OVR_OS_WIN32
54 #elif defined(__linux__) || defined(__linux)
55 # define OVR_OS_LINUX
56 #else
57 # define OVR_OS_OTHER
58 #endif
59 
60 #if defined(ANDROID)
61 # define OVR_OS_ANDROID
62 #endif
63 
64 
65 //-----------------------------------------------------------------------------------
66 // ***** CPU Architecture
67 //
68 // The following CPUs are defined: (OVR_CPU_x)
69 //
70 // X86 - x86 (IA-32)
71 // X86_64 - x86_64 (amd64)
72 // PPC - PowerPC
73 // PPC64 - PowerPC64
74 // MIPS - MIPS
75 // OTHER - CPU for which no special support is present or needed
76 
77 
78 #if defined(__x86_64__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
79 # define OVR_CPU_X86_64
80 # define OVR_64BIT_POINTERS
81 #elif defined(__i386__) || defined(OVR_OS_WIN32)
82 # define OVR_CPU_X86
83 #elif defined(__powerpc64__)
84 # define OVR_CPU_PPC64
85 #elif defined(__ppc__)
86 # define OVR_CPU_PPC
87 #elif defined(__mips__) || defined(__MIPSEL__)
88 # define OVR_CPU_MIPS
89 #elif defined(__arm__)
90 # define OVR_CPU_ARM
91 #else
92 # define OVR_CPU_OTHER
93 #endif
94 
95 //-----------------------------------------------------------------------------------
96 // ***** Co-Processor Architecture
97 //
98 // The following co-processors are defined: (OVR_CPU_x)
99 //
100 // SSE - Available on all modern x86 processors.
101 // Altivec - Available on all modern ppc processors.
102 // Neon - Available on some armv7+ processors.
104 #if defined(__SSE__) || defined(OVR_OS_WIN32)
105 # define OVR_CPU_SSE
106 #endif // __SSE__
107 
108 #if defined( __ALTIVEC__ )
109 # define OVR_CPU_ALTIVEC
110 #endif // __ALTIVEC__
112 #if defined(__ARM_NEON__)
113 # define OVR_CPU_ARM_NEON
114 #endif // __ARM_NEON__
115 
116 
117 //-----------------------------------------------------------------------------------
118 // ***** Compiler
119 //
120 // The following compilers are defined: (OVR_CC_x)
121 //
122 // MSVC - Microsoft Visual C/C++
123 // INTEL - Intel C++ for Linux / Windows
124 // GNU - GNU C++
125 // ARM - ARM C/C++
127 #if defined(__INTEL_COMPILER)
128 // Intel 4.0 = 400
129 // Intel 5.0 = 500
130 // Intel 6.0 = 600
131 // Intel 8.0 = 800
132 // Intel 9.0 = 900
133 # define OVR_CC_INTEL __INTEL_COMPILER
135 #elif defined(_MSC_VER)
136 // MSVC 5.0 = 1100
137 // MSVC 6.0 = 1200
138 // MSVC 7.0 (VC2002) = 1300
139 // MSVC 7.1 (VC2003) = 1310
140 // MSVC 8.0 (VC2005) = 1400
141 // MSVC 9.0 (VC2008) = 1500
142 // MSVC 10.0 (VC2010) = 1600
143 // MSVC 11.0 (VC2012) = 1700
144 // MSVC 12.0 (VC2013) = 1800
145 # define OVR_CC_MSVC _MSC_VER
147 #elif defined(__GNUC__)
148 # define OVR_CC_GNU
150 #elif defined(__CC_ARM)
151 # define OVR_CC_ARM
153 #else
154 # error "Oculus does not support this Compiler"
155 #endif
156 
158 //-----------------------------------------------------------------------------------
159 // ***** Compiler Warnings
160 
161 // Disable MSVC warnings
162 #if defined(OVR_CC_MSVC)
163 # pragma warning(disable : 4127) // Inconsistent dll linkage
164 # pragma warning(disable : 4530) // Exception handling
165 # if (OVR_CC_MSVC<1300)
166 # pragma warning(disable : 4514) // Unreferenced inline function has been removed
167 # pragma warning(disable : 4710) // Function not inlined
168 # pragma warning(disable : 4714) // _force_inline not inlined
169 # pragma warning(disable : 4786) // Debug variable name longer than 255 chars
170 # endif // (OVR_CC_MSVC<1300)
171 #endif // (OVR_CC_MSVC)
175 // *** Linux Unicode - must come before Standard Includes
176 
177 #ifdef OVR_OS_LINUX
178 // Use glibc unicode functions on linux.
179 # ifndef _GNU_SOURCE
180 # define _GNU_SOURCE
181 # endif
182 #endif
184 //-----------------------------------------------------------------------------------
185 // ***** Standard Includes
186 //
187 #include <stddef.h>
188 #include <limits.h>
189 #include <float.h>
190 
192 // MSVC Based Memory Leak checking - for now
193 #if defined(OVR_CC_MSVC) && defined(OVR_BUILD_DEBUG)
194 # define _CRTDBG_MAP_ALLOC
195 # include <stdlib.h>
196 # include <crtdbg.h>
197 
198 #if 0
199 // Uncomment this to help debug memory leaks under Visual Studio in OVR apps only.
200 // This shouldn't be defined in customer releases.
201 # ifndef OVR_DEFINE_NEW
202 # define OVR_DEFINE_NEW new(__FILE__, __LINE__)
203 # define new OVR_DEFINE_NEW
204 # endif
205 #endif
207 #endif
208 
209 
210 //-----------------------------------------------------------------------------------
211 // ***** Type definitions for Common Systems
213 namespace OVR {
214 
215 typedef char Char;
216 
217 // Pointer-sized integer
218 typedef size_t UPInt;
219 typedef ptrdiff_t SPInt;
220 
221 
222 #if defined(OVR_OS_WIN32)
223 
224 typedef char SByte; // 8 bit Integer (Byte)
225 typedef unsigned char UByte;
226 typedef short SInt16; // 16 bit Integer (Word)
227 typedef unsigned short UInt16;
228 typedef long SInt32; // 32 bit Integer
229 typedef unsigned long UInt32;
230 typedef __int64 SInt64; // 64 bit Integer (QWord)
231 typedef unsigned __int64 UInt64;
233 
234 #elif defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) || defined(OVR_CC_GNU)
235 
236 typedef int SByte __attribute__((__mode__ (__QI__)));
237 typedef unsigned int UByte __attribute__((__mode__ (__QI__)));
238 typedef int SInt16 __attribute__((__mode__ (__HI__)));
239 typedef unsigned int UInt16 __attribute__((__mode__ (__HI__)));
240 typedef int SInt32 __attribute__((__mode__ (__SI__)));
241 typedef unsigned int UInt32 __attribute__((__mode__ (__SI__)));
242 typedef int SInt64 __attribute__((__mode__ (__DI__)));
243 typedef unsigned int UInt64 __attribute__((__mode__ (__DI__)));
244 
245 #else
247 #include <sys/types.h>
248 typedef int8_t SByte;
249 typedef uint8_t UByte;
250 typedef int16_t SInt16;
251 typedef uint16_t UInt16;
252 typedef int32_t SInt32;
253 typedef uint32_t UInt32;
254 typedef int64_t SInt64;
255 typedef uint64_t UInt64;
256 
257 #endif
259 
260 // ***** BaseTypes Namespace
262 // BaseTypes namespace is explicitly declared to allow base types to be used
263 // by customers directly without other contents of OVR namespace.
264 //
265 // Its is expected that OVR samples will declare 'using namespace OVR::BaseTypes'
266 // to allow using these directly without polluting the target scope with other
267 // OVR declarations, such as Ptr<>, String or Mutex.
268 namespace BaseTypes
269 {
270  using OVR::UPInt;
271  using OVR::SPInt;
272  using OVR::UByte;
273  using OVR::SByte;
274  using OVR::UInt16;
275  using OVR::SInt16;
276  using OVR::UInt32;
277  using OVR::SInt32;
278  using OVR::UInt64;
279  using OVR::SInt64;
280 } // OVR::BaseTypes
282 } // OVR
283 
284 
285 //-----------------------------------------------------------------------------------
286 // ***** Macro Definitions
287 //
288 // We define the following:
289 //
290 // OVR_BYTE_ORDER - Defined to either OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN
291 // OVR_FORCE_INLINE - Forces inline expansion of function
292 // OVR_ASM - Assembly language prefix
293 // OVR_STR - Prefixes string with L"" if building unicode
294 //
295 // OVR_STDCALL - Use stdcall calling convention (Pascal arg order)
296 // OVR_CDECL - Use cdecl calling convention (C argument order)
297 // OVR_FASTCALL - Use fastcall calling convention (registers)
298 //
299 
300 // Byte order constants, OVR_BYTE_ORDER is defined to be one of these.
301 #define OVR_LITTLE_ENDIAN 1
302 #define OVR_BIG_ENDIAN 2
303 
304 
305 // Force inline substitute - goes before function declaration
306 #if defined(OVR_CC_MSVC)
307 # define OVR_FORCE_INLINE __forceinline
308 #elif defined(OVR_CC_GNU)
309 # define OVR_FORCE_INLINE __attribute__((always_inline)) inline
310 #else
311 # define OVR_FORCE_INLINE inline
312 #endif // OVR_CC_MSVC
313 
314 
315 #if defined(OVR_OS_WIN32)
316 
317  // ***** Win32
318 
319  // Byte order
320  #define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN
322  // Calling convention - goes after function return type but before function name
323  #ifdef __cplusplus_cli
324  # define OVR_FASTCALL __stdcall
325  #else
326  # define OVR_FASTCALL __fastcall
327  #endif
328 
329  #define OVR_STDCALL __stdcall
330  #define OVR_CDECL __cdecl
331 
332 
333  // Assembly macros
334  #if defined(OVR_CC_MSVC)
335  # define OVR_ASM _asm
336  #else
337  # define OVR_ASM asm
338  #endif // (OVR_CC_MSVC)
339 
340  #ifdef UNICODE
341  # define OVR_STR(str) L##str
342  #else
343  # define OVR_STR(str) str
344  #endif // UNICODE
345 
346 #else
347 
348  // **** Standard systems
349 
350  #if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))|| \
351  (defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN))
352  # define OVR_BYTE_ORDER OVR_BIG_ENDIAN
353  #elif (defined(__ARMEB__) || defined(OVR_CPU_PPC) || defined(OVR_CPU_PPC64))
354  # define OVR_BYTE_ORDER OVR_BIG_ENDIAN
355  #else
356  # define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN
357  #endif
358 
359  // Assembly macros
360  #define OVR_ASM __asm__
361  #define OVR_ASM_PROC(procname) OVR_ASM
362  #define OVR_ASM_END OVR_ASM
363 
364  // Calling convention - goes after function return type but before function name
365  #define OVR_FASTCALL
366  #define OVR_STDCALL
367  #define OVR_CDECL
369 #endif // defined(OVR_OS_WIN32)
370 
371 
372 
373 //-----------------------------------------------------------------------------------
374 // ***** OVR_DEBUG_BREAK, OVR_ASSERT
375 //
376 // If not in debug build, macros do nothing
377 #ifndef OVR_BUILD_DEBUG
378 
379 # define OVR_DEBUG_CODE(c) c
380 # define OVR_DEBUG_BREAK ((void)0)
381 # define OVR_ASSERT(p) ((void)0)
383 #else
384 
385 // Microsoft Win32 specific debugging support
386 #if defined(OVR_OS_WIN32)
387 # ifdef OVR_CPU_X86
388 # if defined(__cplusplus_cli)
389 # define OVR_DEBUG_BREAK do { __debugbreak(); } while(0)
390 # elif defined(OVR_CC_GNU)
391 # define OVR_DEBUG_BREAK do { OVR_ASM("int $3\n\t"); } while(0)
392 # else
393 # define OVR_DEBUG_BREAK do { OVR_ASM int 3 } while (0)
394 # endif
395 # else
396 # define OVR_DEBUG_BREAK do { __debugbreak(); } while(0)
397 # endif
398 // Unix specific debugging support
399 #elif defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)
400 # define OVR_DEBUG_BREAK do { OVR_ASM("int $3\n\t"); } while(0)
401 #else
402 # define OVR_DEBUG_BREAK do { *((int *) 0) = 1; } while(0)
403 #endif
404 
405 #define OVR_DEBUG_CODE(c)
406 
407 // This will cause compiler breakpoint
408 #define OVR_ASSERT(p) do { if (!(p)) { OVR_DEBUG_BREAK; } } while(0)
410 #endif // OVR_BUILD_DEBUG
412 
413 // Compile-time assert; produces compiler error if condition is false
414 #define OVR_COMPILER_ASSERT(x) { int zero = 0; switch(zero) {case 0: case x:;} }
415 
416 
417 
418 //-----------------------------------------------------------------------------------
419 // ***** OVR_UNUSED - Unused Argument handling
420 
421 // Macro to quiet compiler warnings about unused parameters/variables.
422 #if defined(OVR_CC_GNU)
423 # define OVR_UNUSED(a) do {__typeof__ (&a) __attribute__ ((unused)) __tmp = &a; } while(0)
424 #else
425 # define OVR_UNUSED(a) (a)
426 #endif
427 
428 #define OVR_UNUSED1(a1) OVR_UNUSED(a1)
429 #define OVR_UNUSED2(a1,a2) OVR_UNUSED(a1); OVR_UNUSED(a2)
430 #define OVR_UNUSED3(a1,a2,a3) OVR_UNUSED2(a1,a2); OVR_UNUSED(a3)
431 #define OVR_UNUSED4(a1,a2,a3,a4) OVR_UNUSED3(a1,a2,a3); OVR_UNUSED(a4)
432 #define OVR_UNUSED5(a1,a2,a3,a4,a5) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED(a5)
433 #define OVR_UNUSED6(a1,a2,a3,a4,a5,a6) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED2(a5,a6)
434 #define OVR_UNUSED7(a1,a2,a3,a4,a5,a6,a7) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED3(a5,a6,a7)
435 #define OVR_UNUSED8(a1,a2,a3,a4,a5,a6,a7,a8) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED4(a5,a6,a7,a8)
436 #define OVR_UNUSED9(a1,a2,a3,a4,a5,a6,a7,a8,a9) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED5(a5,a6,a7,a8,a9)
437 
438 
439 //-----------------------------------------------------------------------------------
440 // ***** Configuration Macros
441 
442 // SF Build type
443 #ifdef OVR_BUILD_DEBUG
444 # define OVR_BUILD_STRING "Debug"
445 #else
446 # define OVR_BUILD_STRING "Release"
447 #endif
448 
449 
451 //# define OVR_BUILD_DEBUG
452 
453 // OVR_DEBUG_STATEMENT injects a statement only in debug builds.
454 // OVR_DEBUG_SELECT injects first argument in debug builds, second argument otherwise.
455 #ifdef OVR_BUILD_DEBUG
456 #define OVR_DEBUG_STATEMENT(s) s
457 #define OVR_DEBUG_SELECT(d, nd) d
458 #else
459 #define OVR_DEBUG_STATEMENT(s)
460 #define OVR_DEBUG_SELECT(d, nd) nd
461 #endif
462 
463 
464 #define OVR_ENABLE_THREADS
465 //
466 // Prevents OVR from defining new within
467 // type macros, so developers can override
468 // new using the #define new new(...) trick
469 // - used with OVR_DEFINE_NEW macro
470 //# define OVR_BUILD_DEFINE_NEW
471 //
472 
473 
474 #endif // OVR_Types_h
uint64_t UInt64
Definition: OVR_Types.h:255
uint16_t UInt16
Definition: OVR_Types.h:251
char Char
Definition: OVR_Types.h:215
uint32_t UInt32
Definition: OVR_Types.h:253
size_t UPInt
Definition: OVR_Types.h:218
uint8_t UByte
Definition: OVR_Types.h:249
#define __attribute__(xyz)
Definition: OVR_Types.h:206
__END_DECLS typedef int8_t SByte
Definition: OVR_Types.h:248
int64_t SInt64
Definition: OVR_Types.h:254
int16_t SInt16
Definition: OVR_Types.h:250
int32_t SInt32
Definition: OVR_Types.h:252
ptrdiff_t SPInt
Definition: OVR_Types.h:219