All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Types.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "EegeoPlatformMacros.h"
6 
7 #include "AssertHandler.h"
8 #include "FatalErrorHandler.h"
9 #include "TtyHandler.h"
10 
11 #include <stddef.h>
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <stdarg.h>
15 
16 
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wlong-long"
19 
20 
21 #if defined (EEGEO_WIN)
22 typedef unsigned int uint;
23 #endif
24 typedef unsigned long long UInt64;
25 typedef long long unsigned int u64;
26 typedef unsigned int u32;
27 typedef unsigned short u16;
28 typedef unsigned char u8;
29 typedef long long signed int s64;
30 typedef signed int s32;
31 typedef signed short s16;
32 typedef signed char s8;
33 
34 #pragma clang diagnostic pop
35 
36 #if defined (EEGEO_DROID) || defined (EEGEO_WIN)
37 typedef unsigned char Byte;
38 #elif defined EEGEO_IOS
39 #include "MacTypes.h"
40 #elif defined OVR_OS_MAC
41 typedef unsigned char Byte;
42 #elif defined EEGEO_OSX
43 #include "MacTypes.h"
44 #elif defined EMSCRIPTEN
45 typedef unsigned char Byte;
46 typedef unsigned int uint;
47 #endif
48 
49 #if defined (EEGEO_WIN)
50 #include "EegeoWindowsGuard.h"
51 #endif
52 
53 #pragma clang diagnostic push
54 #pragma clang diagnostic ignored "-Wvariadic-macros"
55 #pragma clang diagnostic ignored "-Wgnu"
56 
57 #define EEGEO_CLICKABLE_DEBUG_OUTPUT_ON_WINDOWS
58 
59 #if defined(EEGEO_WIN) && defined(EEGEO_CLICKABLE_DEBUG_OUTPUT_ON_WINDOWS)
60 #define Eegeo_TTY(...) Eegeo::TtyHandler::HandleClickableTty(__FILE__, __LINE__, __VA_ARGS__)
61 #define Eegeo_ERROR(...) Eegeo::TtyHandler::HandleClickableTty(__FILE__, __LINE__, __VA_ARGS__)
62 #else
63 #define Eegeo_TTY(...) Eegeo::TtyHandler::HandleTty(__VA_ARGS__)
64 #define Eegeo_ERROR(...) Eegeo::TtyHandler::HandleTty(__VA_ARGS__)
65 #endif
66 #define ENABLE_ASSERT
67 
68 #if defined(EEGEO_UNITY)
69 #define Eegeo_GRAPHICS_ASSERT(...)
70 #else
71 #define Eegeo_GRAPHICS_ASSERT Eegeo_ASSERT
72 #endif
73 
74 #if defined (ENABLE_ASSERT)
75 #define Eegeo_ASSERT(x, ...) if(!(x)) { Eegeo::Assert(__FILE__, __LINE__, ##__VA_ARGS__); }
76 #else
77 #define Eegeo_ASSERT(x, ...)
78 #endif
79 
80 #if defined (DEBUG)
81 #define Eegeo_ASSERT_SLOW Eegeo_ASSERT
82 #else
83 #define Eegeo_ASSERT_SLOW(x, ...)
84 #endif
85 #pragma clang diagnostic pop
86 
87 #if defined (EEGEO_WIN)
88 #define Eegeo_STATIC_ASSERT( condition, name )
89 #else
90 // Compile time verification. We cannot use static_assert, as it's a C++11 feature.
91 // http://stackoverflow.com/questions/6765770/compile-time-assertion
92 #define Eegeo_STATIC_ASSERT( condition, name ) typedef char assert_failed_ ## name [ (condition) ? 1 : -1 ] __attribute__((unused));
93 #endif
94 
95 #define Eegeo_TRACE() Eegeo_TTY("Trace %s(%d)", __FILE__, __LINE__);
96 
97 #define Eegeo_EXIT(x) Eegeo::FatalError(x)
98 
99 //#define Eegeo_NOISY_NEW_ALL
100 //#define Eegeo_NOISY_NEW_MAIN_THREAD
101 //#define Eegeo_MEMORY_TRACKING_NEW
102 
103 #if defined(Eegeo_NOISY_NEW_ALL)
104  #include "DebugValues.h"
105  #define Eegeo_LOG_ALLOCATIONS Eegeo::Debug::DebugValues::loggingAllocations
106  #define Eegeo_NEW(type) (!Eegeo_LOG_ALLOCATIONS ? 0 : Eegeo_TTY("Scalar new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type
107  #define Eegeo_DELETE if(Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Scalar delete at %s :: %d\n", __FILE__, __LINE__);} delete
108  #define Eegeo_ARRAY_NEW(type, num) (!Eegeo_LOG_ALLOCATIONS ? 0 : Eegeo_TTY("Array new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type[num]
109  #define Eegeo_ARRAY_DELETE if(Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Array delete at %s :: %d\n", __FILE__, __LINE__);} delete[]
110 #elif defined(Eegeo_NOISY_NEW_MAIN_THREAD)
111  #include "DebugValues.h"
112  #define Eegeo_LOG_ALLOCATIONS Eegeo::Debug::DebugValues::loggingAllocations
113  #include "ThreadHelpers.h"
114  #define Eegeo_MAIN_THREAD Eegeo::Helpers::ThreadHelpers::IsMainThread()
115  #define Eegeo_NEW(type) ((!Eegeo_MAIN_THREAD || !Eegeo_LOG_ALLOCATIONS) ? 0 : Eegeo_TTY("Scalar new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type
116  #define Eegeo_DELETE if(Eegeo_MAIN_THREAD && Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Scalar delete at %s :: %d\n", __FILE__, __LINE__);} delete
117  #define Eegeo_ARRAY_NEW(type, num) ((!Eegeo_MAIN_THREAD || !Eegeo_LOG_ALLOCATIONS) ? 0 : Eegeo_TTY("Array new at %s :: %d --> size %lu\n", __FILE__, __LINE__, sizeof(type))) && 0 ? 0 : new type[num]
118  #define Eegeo_ARRAY_DELETE if(Eegeo_MAIN_THREAD && Eegeo_LOG_ALLOCATIONS) {Eegeo_TTY("Array delete at %s :: %d\n", __FILE__, __LINE__);} delete[]
119 #elif defined(Eegeo_MEMORY_TRACKING_NEW)
120  #include <typeinfo>
121  #include "AllocHelper.h"
122 
123  #define Eegeo_TYPE_TO_STRING(...) typeid(__VA_ARGS__).name()
124 
125  #define Eegeo_NEW(...) (Eegeo::AllocHelper(Eegeo_TYPE_TO_STRING(__VA_ARGS__), __FILE__, __LINE__)) << new (__VA_ARGS__)
126  #define Eegeo_DELETE delete
127 
128  #define Eegeo_ARRAY_NEW(type, num) (Eegeo::AllocHelper(Eegeo_TYPE_TO_STRING(type), __FILE__, __LINE__, (int)(num))) << new type[num]
129  #define Eegeo_ARRAY_DELETE delete[]
130 #else
131  #define Eegeo_NEW(type) new type
132  #define Eegeo_DELETE delete
133  #define Eegeo_ARRAY_NEW(type, num) new type[num]
134  #define Eegeo_ARRAY_DELETE delete[]
135 #endif
136 
137 #if defined(__GNUC__) || defined(__MINGW32__)
138  #define EEGEO_ALIGNED(N) __attribute__ ((aligned (N)))
139 #elif defined(_MSC_VER)
140  #define EEGEO_ALIGNED(N) __declspec(align(N))
141 #else
142  #define EEGEO_ALIGNED(N)
143 #endif
144 
145 #define CHECK_CASTS 0
146 
147 #if CHECK_CASTS == 1
148 #include <typeinfo>
149 namespace Eegeo
150 {
151  template<typename T, typename U>
152  T CheckedCast(U u)
153  {
154  T t = dynamic_cast<T>(u);
155  Eegeo_ASSERT(t != NULL, "Object of type %s is not an instance of type %s.\n", typeid(U).name(), typeid(T).name());
156  return t;
157  }
158 }
159 #else
160 namespace Eegeo
161 {
162  template<typename T, typename U>
163  T CheckedCast(U u)
164  {
165  return static_cast<T>(u);
166  }
167 }
168 #endif
169 
170 namespace Eegeo
171 {
173  {
174  public:
175  NonCopyable (const NonCopyable &) = delete;
176  NonCopyable & operator = (const NonCopyable &) = delete;
177  protected:
178  NonCopyable () = default;
179  };
180 }