ezEngine  Milestone 7
Types.h
1 #pragma once
2 
3 // ***** Definition of types *****
4 
5 typedef unsigned char ezUInt8;
6 typedef unsigned short ezUInt16;
7 typedef unsigned int ezUInt32;
8 // ezUInt64 is defined in the compiler specific header
9 
10 typedef char ezInt8;
11 typedef short ezInt16;
12 typedef int ezInt32;
13 // ezInt64 is defined in the compiler specific header
14 
15 // no float-types, since those are well portable
16 
17 // Do some compile-time checks on the types
18 EZ_CHECK_AT_COMPILETIME(sizeof(bool) == 1);
19 EZ_CHECK_AT_COMPILETIME(sizeof(char) == 1);
20 EZ_CHECK_AT_COMPILETIME(sizeof(float) == 4);
21 EZ_CHECK_AT_COMPILETIME(sizeof(double) == 8);
22 EZ_CHECK_AT_COMPILETIME(sizeof(ezInt8) == 1);
23 EZ_CHECK_AT_COMPILETIME(sizeof(ezInt16) == 2);
24 EZ_CHECK_AT_COMPILETIME(sizeof(ezInt32) == 4);
25 EZ_CHECK_AT_COMPILETIME(sizeof(ezInt64) == 8); // must be defined in the specific compiler header
26 EZ_CHECK_AT_COMPILETIME(sizeof(ezUInt8) == 1);
27 EZ_CHECK_AT_COMPILETIME(sizeof(ezUInt16) == 2);
28 EZ_CHECK_AT_COMPILETIME(sizeof(ezUInt32) == 4);
29 EZ_CHECK_AT_COMPILETIME(sizeof(ezUInt64) == 8); // must be defined in the specific compiler header
30 EZ_CHECK_AT_COMPILETIME(sizeof(long long int) == 8);
31 
32 
33 #if EZ_ENABLED(EZ_PLATFORM_64BIT)
34  #define EZ_ALIGNMENT_MINIMUM 8
35 #elif EZ_ENABLED(EZ_PLATFORM_32BIT)
36  #define EZ_ALIGNMENT_MINIMUM 4
37 #else
38  #error "Unknown pointer size."
39 #endif
40 
41 EZ_CHECK_AT_COMPILETIME(sizeof(void*) == EZ_ALIGNMENT_MINIMUM);
42 
44 enum ezResultEnum
45 {
46  EZ_FAILURE,
47  EZ_SUCCESS
48 };
49 
51 struct ezResult
52 {
53 public:
54  ezResult(ezResultEnum res) : e (res) {}
55 
56  void operator= (ezResultEnum rhs) { e = rhs; }
57  bool operator== (ezResultEnum cmp) const { return e == cmp; }
58  bool operator!= (ezResultEnum cmp) const { return e != cmp; }
59 
60  bool Succeeded() const { return e == EZ_SUCCESS; }
61  bool Failed() const { return e == EZ_FAILURE; }
62 
63 private:
64  ezResultEnum e;
65 };
66 
67 class ezRTTI;
68 
70 class ezNoBase
71 {
72 public:
73  static const ezRTTI* GetStaticRTTI() { return nullptr; }
74 
75 };
76 
79 {
80 };
81 
84 {
85 };
86 
89 template <size_t Alignment> struct ezAligned;
90 template <> struct EZ_ALIGN(ezAligned<1>, 1) { };
91 template <> struct EZ_ALIGN(ezAligned<2>, 2) { };
92 template <> struct EZ_ALIGN(ezAligned<4>, 4) { };
93 template <> struct EZ_ALIGN(ezAligned<8>, 8) { };
94 template <> struct EZ_ALIGN(ezAligned<16>, 16) { };
95 template <> struct EZ_ALIGN(ezAligned<32>, 32) { };
96 template <> struct EZ_ALIGN(ezAligned<64>, 64) { };
97 template <> struct EZ_ALIGN(ezAligned<128>, 128) { };
98 template <> struct EZ_ALIGN(ezAligned<256>, 256) { };
99 template <> struct EZ_ALIGN(ezAligned<512>, 512) { };
100 template <> struct EZ_ALIGN(ezAligned<1024>, 1024) { };
101 template <> struct EZ_ALIGN(ezAligned<2048>, 2048) { };
102 template <> struct EZ_ALIGN(ezAligned<4096>, 4096) { };
103 template <> struct EZ_ALIGN(ezAligned<8192>, 8192) { };
104 
105 
107 template <size_t SizeInByte> struct ezSizeToType;
109 template <> struct ezSizeToType<1> { typedef ezUInt8 Type; };
110 template <> struct ezSizeToType<2> { typedef ezUInt16 Type; };
111 template <> struct ezSizeToType<3> { typedef ezUInt32 Type; };
112 template <> struct ezSizeToType<4> { typedef ezUInt32 Type; };
113 template <> struct ezSizeToType<5> { typedef ezUInt64 Type; };
114 template <> struct ezSizeToType<6> { typedef ezUInt64 Type; };
115 template <> struct ezSizeToType<7> { typedef ezUInt64 Type; };
116 template <> struct ezSizeToType<8> { typedef ezUInt64 Type; };