ezEngine  Milestone 7
Common.h
1 #pragma once
2 
3 // On MSVC 2008 in 64 Bit <cmath> generates a lot of warnings (actually it is math.h, which is included by cmath)
4 #define EZ_MSVC_WARNING_NUMBER 4985
5 #include <Foundation/Basics/Compiler/DisableWarning.h>
6 
7 // include std header
8 #include <new>
9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <cwchar>
13 #include <cwctype>
14 #include <cmath>
15 
16 #include <Foundation/Basics/Compiler/RestoreWarning.h>
17 
18 // redefine NULL to nullptr
19 #undef NULL
20 #define NULL nullptr
21 
22 // include c++11 specific header
23 #include <type_traits>
24 
25 #ifndef __INTELLISENSE__
26 
27  // Macros to do compile-time checks, such as to ensure sizes of types
28  // EZ_CHECK_AT_COMPILETIME(exp) : only checks exp
29  // EZ_CHECK_AT_COMPILETIME_MSG(exp, msg) : checks exp and displays msg
30  #define EZ_CHECK_AT_COMPILETIME(exp) \
31  static_assert(exp, EZ_STRINGIZE(exp) " is false.");
32 
33  #define EZ_CHECK_AT_COMPILETIME_MSG(exp, msg) \
34  static_assert(exp, EZ_STRINGIZE(exp) " is false. Message: " msg);
35 
36 #else
37 
38  // Intellisense often isn't smart enough to evaluate these conditions correctly
39 
40  #define EZ_CHECK_AT_COMPILETIME(exp)
41 
42  #define EZ_CHECK_AT_COMPILETIME_MSG(exp, msg)
43 
44 #endif
45 
47 #define EZ_DISALLOW_COPY_AND_ASSIGN(type) \
48  private: \
49  type(const type&); \
50  void operator=(const type&)
51 
52 #if EZ_ENABLED(EZ_COMPILE_FOR_DEVELOPMENT)
53 
54  #define EZ_CHECK_ALIGNMENT(ptr, alignment) \
55  EZ_ASSERT_DEV(((size_t)ptr & (alignment - 1)) == 0, "Wrong alignment. Expected %d bytes alignment", alignment)
56 #else
57 
58  #define EZ_CHECK_ALIGNMENT(ptr, alignment)
59 #endif
60 
61 #define EZ_ALIGN_16(decl) EZ_ALIGN(decl, 16)
62 #define EZ_ALIGN_32(decl) EZ_ALIGN(decl, 32)
63 #define EZ_ALIGN_64(decl) EZ_ALIGN(decl, 64)
64 #define EZ_ALIGN_128(decl) EZ_ALIGN(decl, 128)
65 #define EZ_CHECK_ALIGNMENT_16(ptr) EZ_CHECK_ALIGNMENT(ptr, 16)
66 #define EZ_CHECK_ALIGNMENT_32(ptr) EZ_CHECK_ALIGNMENT(ptr, 32)
67 #define EZ_CHECK_ALIGNMENT_64(ptr) EZ_CHECK_ALIGNMENT(ptr, 64)
68 #define EZ_CHECK_ALIGNMENT_128(ptr) EZ_CHECK_ALIGNMENT(ptr, 128)
69 
70 #if EZ_ENABLED(EZ_COMPILE_ENGINE_AS_DLL)
71 
77  #define EZ_STATICLINK_FILE(LibraryName, UniqueName)
78 
81  #define EZ_STATICLINK_REFERENCE(UniqueName)
82 
84  #define EZ_STATICLINK_LIBRARY(LibraryName) \
85  void ezReferenceFunction_##LibraryName(bool bReturn = true)
86 
87 #else
88 
90  {
91  typedef void(*Func)(bool);
92  ezStaticLinkHelper(Func f) { f(true); }
93  };
94 
100  #define EZ_STATICLINK_FILE(LibraryName, UniqueName) \
101  void ezReferenceFunction_##UniqueName(bool bReturn = true) { } \
102  void ezReferenceFunction_##LibraryName(bool bReturn = true); \
103  static ezStaticLinkHelper StaticLinkHelper(ezReferenceFunction_##LibraryName);
104 
107  #define EZ_STATICLINK_REFERENCE(UniqueName) \
108  void ezReferenceFunction_##UniqueName(bool bReturn = true); \
109  ezReferenceFunction_##UniqueName()
110 
112  #define EZ_STATICLINK_LIBRARY(LibraryName) \
113  void ezReferenceFunction_##LibraryName(bool bReturn = true)
114 
115 #endif
116 
117 namespace ezInternal
118 {
119  template <typename T, size_t N>
120  char (*ArraySizeHelper(T (&)[N]))[N];
121 }
122 
124 #define EZ_ARRAY_SIZE(a) (sizeof(*ezInternal::ArraySizeHelper(a))+0)
125 
127 template<class T>
128 void EZ_IGNORE_UNUSED(const T&) {}
129 
130 
131 // Math Debug checks
132 #if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG)
133 
134  #undef EZ_MATH_CHECK_FOR_NAN
135  #define EZ_MATH_CHECK_FOR_NAN EZ_ON
136 
137 #endif
138