OVR_Types.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 PublicHeader:   OVR.h
00004 Filename    :   OVR_Types.h
00005 Content     :   Standard library defines and simple types
00006 Created     :   September 19, 2012
00007 Notes       : 
00008 
00009 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00010 
00011 Use of this software is subject to the terms of the Oculus license
00012 agreement provided at the time of installation or download, or which
00013 otherwise accompanies this software in either electronic or hard copy form.
00014 
00015 ************************************************************************************/
00016 
00017 #ifndef OVR_Types_H
00018 #define OVR_Types_H
00019 
00020 //-----------------------------------------------------------------------------------
00021 // ****** Operating System
00022 //
00023 // Type definitions exist for the following operating systems: (OVR_OS_x)
00024 //
00025 //    WIN32    - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
00026 //    DARWIN   - Darwin OS (Mac OS X)
00027 //    LINUX    - Linux
00028 //    ANDROID  - Android
00029 //    IPHONE   - iPhone
00030 
00031 #if (defined(__APPLE__) && (defined(__GNUC__) ||\
00032      defined(__xlC__) || defined(__xlc__))) || defined(__MACOS__)
00033 #  if (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED))
00034 #    define OVR_OS_IPHONE
00035 #  else
00036 #    define OVR_OS_DARWIN
00037 #    define OVR_OS_MAC
00038 #  endif
00039 #elif (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
00040 #  define OVR_OS_WIN32
00041 #elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
00042 #  define OVR_OS_WIN32
00043 #elif defined(__linux__) || defined(__linux)
00044 #  define OVR_OS_LINUX
00045 #else
00046 #  define OVR_OS_OTHER
00047 #endif
00048 
00049 #if defined(ANDROID)
00050 #  define OVR_OS_ANDROID
00051 #endif
00052 
00053 
00054 //-----------------------------------------------------------------------------------
00055 // ***** CPU Architecture
00056 //
00057 // The following CPUs are defined: (OVR_CPU_x)
00058 //
00059 //    X86        - x86 (IA-32)
00060 //    X86_64     - x86_64 (amd64)
00061 //    PPC        - PowerPC
00062 //    PPC64      - PowerPC64
00063 //    MIPS       - MIPS
00064 //    OTHER      - CPU for which no special support is present or needed
00065 
00066 
00067 #if defined(__x86_64__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
00068 #  define OVR_CPU_X86_64
00069 #  define OVR_64BIT_POINTERS
00070 #elif defined(__i386__) || defined(OVR_OS_WIN32)
00071 #  define OVR_CPU_X86
00072 #elif defined(__powerpc64__)
00073 #  define OVR_CPU_PPC64
00074 #elif defined(__ppc__)
00075 #  define OVR_CPU_PPC
00076 #elif defined(__mips__) || defined(__MIPSEL__)
00077 #  define OVR_CPU_MIPS
00078 #elif defined(__arm__)
00079 #  define OVR_CPU_ARM
00080 #else
00081 #  define OVR_CPU_OTHER
00082 #endif
00083 
00084 //-----------------------------------------------------------------------------------
00085 // ***** Co-Processor Architecture
00086 //
00087 // The following co-processors are defined: (OVR_CPU_x)
00088 //
00089 //    SSE        - Available on all modern x86 processors.
00090 //    Altivec    - Available on all modern ppc processors.
00091 //    Neon       - Available on some armv7+ processors.
00092 
00093 #if defined(__SSE__) || defined(OVR_OS_WIN32)
00094 #  define  OVR_CPU_SSE
00095 #endif // __SSE__
00096 
00097 #if defined( __ALTIVEC__ )
00098 #  define OVR_CPU_ALTIVEC
00099 #endif // __ALTIVEC__
00100 
00101 #if defined(__ARM_NEON__)
00102 #  define OVR_CPU_ARM_NEON
00103 #endif // __ARM_NEON__
00104 
00105 
00106 //-----------------------------------------------------------------------------------
00107 // ***** Compiler
00108 //
00109 //  The following compilers are defined: (OVR_CC_x)
00110 //
00111 //     MSVC     - Microsoft Visual C/C++
00112 //     INTEL    - Intel C++ for Linux / Windows
00113 //     GNU      - GNU C++
00114 //     ARM      - ARM C/C++
00115 
00116 #if defined(__INTEL_COMPILER)
00117 // Intel 4.0                    = 400
00118 // Intel 5.0                    = 500
00119 // Intel 6.0                    = 600
00120 // Intel 8.0                    = 800
00121 // Intel 9.0                    = 900
00122 #  define OVR_CC_INTEL       __INTEL_COMPILER
00123 
00124 #elif defined(_MSC_VER)
00125 // MSVC 5.0                     = 1100
00126 // MSVC 6.0                     = 1200
00127 // MSVC 7.0 (VC2002)            = 1300
00128 // MSVC 7.1 (VC2003)            = 1310
00129 // MSVC 8.0 (VC2005)            = 1400
00130 // MSVC 9.0 (VC2008)            = 1500
00131 // MSVC 10.0 (VC2010)           = 1600
00132 #  define OVR_CC_MSVC        _MSC_VER
00133 
00134 #elif defined(__GNUC__)
00135 #  define OVR_CC_GNU
00136 
00137 #elif defined(__CC_ARM)
00138 #  define OVR_CC_ARM
00139 
00140 #else
00141 #  error "Oculus does not support this Compiler"
00142 #endif
00143 
00144 
00145 //-----------------------------------------------------------------------------------
00146 // ***** Compiler Warnings
00147 
00148 // Disable MSVC warnings
00149 #if defined(OVR_CC_MSVC)
00150 #  pragma warning(disable : 4127)    // Inconsistent dll linkage
00151 #  pragma warning(disable : 4530)    // Exception handling
00152 #  if (OVR_CC_MSVC<1300)
00153 #    pragma warning(disable : 4514)  // Unreferenced inline function has been removed
00154 #    pragma warning(disable : 4710)  // Function not inlined
00155 #    pragma warning(disable : 4714)  // _force_inline not inlined
00156 #    pragma warning(disable : 4786)  // Debug variable name longer than 255 chars
00157 #  endif // (OVR_CC_MSVC<1300)
00158 #endif // (OVR_CC_MSVC)
00159 
00160 
00161 
00162 // *** Linux Unicode - must come before Standard Includes
00163 
00164 #ifdef OVR_OS_LINUX
00165 // Use glibc unicode functions on linux.
00166 #  ifndef  _GNU_SOURCE
00167 #    define _GNU_SOURCE
00168 #  endif
00169 #endif
00170 
00171 //-----------------------------------------------------------------------------------
00172 // ***** Standard Includes
00173 //
00174 #include    <stddef.h>
00175 #include    <limits.h>
00176 #include    <float.h>
00177 
00178 
00179 // MSVC Based Memory Leak checking - for now
00180 #if defined(OVR_CC_MSVC) && defined(OVR_BUILD_DEBUG)
00181 #  define _CRTDBG_MAP_ALLOC
00182 #  include <stdlib.h>
00183 #  include <crtdbg.h>
00184 
00185 // Uncomment this to help debug memory leaks under Visual Studio in OVR apps only.
00186 // This shouldn't be defined in customer releases.
00187 #  ifndef OVR_DEFINE_NEW
00188 #    define OVR_DEFINE_NEW new(__FILE__, __LINE__)
00189 #    define new OVR_DEFINE_NEW
00190 #  endif
00191 
00192 #endif
00193 
00194 
00195 //-----------------------------------------------------------------------------------
00196 // ***** Type definitions for Common Systems
00197 
00198 namespace OVR {
00199 
00200 typedef char            Char;
00201 
00202 // Pointer-sized integer
00203 typedef size_t          UPInt;
00204 typedef ptrdiff_t       SPInt;
00205 
00206 
00207 #if defined(OVR_OS_WIN32)
00208 
00209 typedef char            SByte;  // 8 bit Integer (Byte)
00210 typedef unsigned char   UByte;
00211 typedef short           SInt16; // 16 bit Integer (Word)
00212 typedef unsigned short  UInt16;
00213 typedef long            SInt32; // 32 bit Integer
00214 typedef unsigned long   UInt32;
00215 typedef __int64         SInt64; // 64 bit Integer (QWord)
00216 typedef unsigned __int64 UInt64;
00217 
00218  
00219 #elif defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) || defined(OVR_CC_GNU)
00220 
00221 typedef int             SByte  __attribute__((__mode__ (__QI__)));
00222 typedef unsigned int    UByte  __attribute__((__mode__ (__QI__)));
00223 typedef int             SInt16 __attribute__((__mode__ (__HI__)));
00224 typedef unsigned int    UInt16 __attribute__((__mode__ (__HI__)));
00225 typedef int             SInt32 __attribute__((__mode__ (__SI__)));
00226 typedef unsigned int    UInt32 __attribute__((__mode__ (__SI__)));
00227 typedef int             SInt64 __attribute__((__mode__ (__DI__)));
00228 typedef unsigned int    UInt64 __attribute__((__mode__ (__DI__)));
00229 
00230 #else
00231 
00232 #include <sys/types.h>
00233 typedef int8_t          SByte;
00234 typedef uint8_t         UByte;
00235 typedef int16_t         SInt16;
00236 typedef uint16_t        UInt16;
00237 typedef int32_t         SInt32;
00238 typedef uint32_t        UInt32;
00239 typedef int64_t         SInt64;
00240 typedef uint64_t        UInt64;
00241 
00242 #endif
00243 
00244 
00245 // ***** BaseTypes Namespace
00246 
00247 // BaseTypes namespace is explicitly declared to allow base types to be used
00248 // by customers directly without other contents of OVR namespace.
00249 //
00250 // Its is expected that GFx samples will declare 'using namespace OVR::BaseTypes'
00251 // to allow using these directly without polluting the target scope with other
00252 // OVR declarations, such as Ptr<>, String or Mutex.
00253 namespace BaseTypes
00254 {
00255     using OVR::UPInt;
00256     using OVR::SPInt;
00257     using OVR::UByte;
00258     using OVR::SByte;
00259     using OVR::UInt16;
00260     using OVR::SInt16;
00261     using OVR::UInt32;
00262     using OVR::SInt32;
00263     using OVR::UInt64;
00264     using OVR::SInt64;
00265 } // OVR::BaseTypes
00266 
00267 } // OVR
00268 
00269 
00270 //-----------------------------------------------------------------------------------
00271 // ***** Macro Definitions
00272 //
00273 // We define the following:
00274 //
00275 //  OVR_BYTE_ORDER      - Defined to either OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN
00276 //  OVR_FORCE_INLINE    - Forces inline expansion of function
00277 //  OVR_ASM             - Assembly language prefix
00278 //  OVR_STR             - Prefixes string with L"" if building unicode
00279 // 
00280 //  OVR_STDCALL         - Use stdcall calling convention (Pascal arg order)
00281 //  OVR_CDECL           - Use cdecl calling convention (C argument order)
00282 //  OVR_FASTCALL        - Use fastcall calling convention (registers)
00283 //
00284 
00285 // Byte order constants, OVR_BYTE_ORDER is defined to be one of these.
00286 #define OVR_LITTLE_ENDIAN       1
00287 #define OVR_BIG_ENDIAN          2
00288 
00289 
00290 // Force inline substitute - goes before function declaration
00291 #if defined(OVR_CC_MSVC)
00292 #  define OVR_FORCE_INLINE  __forceinline
00293 #elif defined(OVR_CC_GNU)
00294 #  define OVR_FORCE_INLINE  __attribute__((always_inline))
00295 #else
00296 #  define OVR_FORCE_INLINE  inline
00297 #endif  // OVR_CC_MSVC
00298 
00299 
00300 #if defined(OVR_OS_WIN32)
00301     
00302     // ***** Win32
00303 
00304     // Byte order
00305     #define OVR_BYTE_ORDER    OVR_LITTLE_ENDIAN
00306 
00307     // Calling convention - goes after function return type but before function name
00308     #ifdef __cplusplus_cli
00309     #  define OVR_FASTCALL      __stdcall
00310     #else
00311     #  define OVR_FASTCALL      __fastcall
00312     #endif
00313 
00314     #define OVR_STDCALL         __stdcall
00315     #define OVR_CDECL           __cdecl
00316 
00317 
00318     // Assembly macros
00319     #if defined(OVR_CC_MSVC)
00320     #  define OVR_ASM           _asm
00321     #else
00322     #  define OVR_ASM           asm
00323     #endif // (OVR_CC_MSVC)
00324 
00325     #ifdef UNICODE
00326     #  define OVR_STR(str)      L##str
00327     #else
00328     #  define OVR_STR(str)      str
00329     #endif // UNICODE
00330 
00331 #else
00332 
00333     // **** Standard systems
00334 
00335     #if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))|| \
00336         (defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN))
00337     #  define OVR_BYTE_ORDER    OVR_BIG_ENDIAN
00338     #elif (defined(__ARMEB__) || defined(OVR_CPU_PPC) || defined(OVR_CPU_PPC64))
00339     #  define OVR_BYTE_ORDER    OVR_BIG_ENDIAN
00340     #else
00341     #  define OVR_BYTE_ORDER    OVR_LITTLE_ENDIAN
00342     #endif
00343     
00344     // Assembly macros
00345     #define OVR_ASM                  __asm__
00346     #define OVR_ASM_PROC(procname)   OVR_ASM
00347     #define OVR_ASM_END              OVR_ASM
00348     
00349     // Calling convention - goes after function return type but before function name
00350     #define OVR_FASTCALL
00351     #define OVR_STDCALL
00352     #define OVR_CDECL
00353 
00354 #endif // defined(OVR_OS_WIN32)
00355 
00356 
00357 
00358 //-----------------------------------------------------------------------------------
00359 // ***** OVR_DEBUG_BREAK, OVR_ASSERT
00360 //
00361 // If not in debug build, macros do nothing
00362 #ifndef OVR_BUILD_DEBUG
00363 
00364 #  define OVR_DEBUG_BREAK  ((void)0)
00365 #  define OVR_ASSERT(p)    ((void)0)
00366 
00367 #else 
00368 
00369 // Microsoft Win32 specific debugging support
00370 #if defined(OVR_OS_WIN32)
00371 #  ifdef OVR_CPU_X86
00372 #    if defined(__cplusplus_cli)
00373 #      define OVR_DEBUG_BREAK   do { __debugbreak(); } while(0)
00374 #    elif defined(OVR_CC_GNU)
00375 #      define OVR_DEBUG_BREAK   do { OVR_ASM("int $3\n\t"); } while(0)
00376 #    else
00377 #      define OVR_DEBUG_BREAK   do { OVR_ASM int 3 } while (0)
00378 #    endif
00379 #  else
00380 #    define OVR_DEBUG_BREAK     do { __debugbreak(); } while(0)
00381 #  endif
00382 // Unix specific debugging support
00383 #elif defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)
00384 #  define OVR_DEBUG_BREAK       do { OVR_ASM("int $3\n\t"); } while(0)
00385 #else
00386 #  define OVR_DEBUG_BREAK       do { *((int *) 0) = 1; } while(0)
00387 #endif
00388 
00389 // This will cause compiler breakpoint
00390 #define OVR_ASSERT(p)           do { if (!(p))  { OVR_DEBUG_BREAK; } } while(0)
00391 
00392 #endif // OVR_BUILD_DEBUG
00393 
00394 
00395 // Compile-time assert; produces compiler error if condition is false
00396 #define OVR_COMPILER_ASSERT(x)  { int zero = 0; switch(zero) {case 0: case x:;} }
00397 
00398 
00399 
00400 //-----------------------------------------------------------------------------------
00401 // ***** OVR_UNUSED - Unused Argument handling
00402 
00403 // Macro to quiet compiler warnings about unused parameters/variables.
00404 #if defined(OVR_CC_GNU)
00405 #  define   OVR_UNUSED(a)   do {__typeof__ (&a) __attribute__ ((unused)) __tmp = &a; } while(0)
00406 #else
00407 #  define   OVR_UNUSED(a)   (a)
00408 #endif
00409 
00410 #define     OVR_UNUSED1(a1) OVR_UNUSED(a1)
00411 #define     OVR_UNUSED2(a1,a2) OVR_UNUSED(a1); OVR_UNUSED(a2)
00412 #define     OVR_UNUSED3(a1,a2,a3) OVR_UNUSED2(a1,a2); OVR_UNUSED(a3)
00413 #define     OVR_UNUSED4(a1,a2,a3,a4) OVR_UNUSED3(a1,a2,a3); OVR_UNUSED(a4)
00414 #define     OVR_UNUSED5(a1,a2,a3,a4,a5) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED(a5)
00415 #define     OVR_UNUSED6(a1,a2,a3,a4,a5,a6) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED2(a5,a6)
00416 #define     OVR_UNUSED7(a1,a2,a3,a4,a5,a6,a7) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED3(a5,a6,a7)
00417 #define     OVR_UNUSED8(a1,a2,a3,a4,a5,a6,a7,a8) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED4(a5,a6,a7,a8)
00418 #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)
00419 
00420 
00421 //-----------------------------------------------------------------------------------
00422 // ***** Configuration Macros
00423 
00424 // SF Build type
00425 #ifdef OVR_BUILD_DEBUG
00426 #  define OVR_BUILD_STRING  "Debug"
00427 #else
00428 #  define OVR_BUILD_STRING  "Release"
00429 #endif
00430 
00431 
00433 //# define OVR_BUILD_DEBUG
00434 
00435 // OVR_DEBUG_STATEMENT injects a statement only in debug builds.
00436 // OVR_DEBUG_SELECT injects first argument in debug builds, second argument otherwise.
00437 #ifdef OVR_BUILD_DEBUG
00438 #define OVR_DEBUG_STATEMENT(s)   s
00439 #define OVR_DEBUG_SELECT(d, nd)  d
00440 #else
00441 #define OVR_DEBUG_STATEMENT(s)
00442 #define OVR_DEBUG_SELECT(d, nd)  nd
00443 #endif
00444 
00445 
00446 #define OVR_ENABLE_THREADS
00447 //
00448 // Prevents OVR from defining new within
00449 // type macros, so developers can override
00450 // new using the #define new new(...) trick
00451 // - used with OVR_DEFINE_NEW macro
00452 //# define OVR_BUILD_DEFINE_NEW
00453 //
00454 
00455 
00456 #endif  // OVR_Types_h


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19