1.14.0.5
Hummingbird
A modern user interface library for games
TypeTraits.h
1 /*
2 This file is part of Hummingbird, a modern user interface library.
3 
4 Copyright (c) 2012-2017 Coherent Labs AD and/or its licensors. All
5 rights reserved in all media.
6 
7 The coded instructions, statements, computer programs, and/or related
8 material (collectively the "Data") in these files contain confidential
9 and unpublished information proprietary Coherent Labs and/or its
10 licensors, which is protected by United States of America federal
11 copyright law and by international treaties.
12 
13 This software or source code is supplied under the terms of a license
14 agreement and nondisclosure agreement with Coherent Labs AD and may
15 not be copied, disclosed, or exploited except in accordance with the
16 terms of that agreement. The Data may not be disclosed or distributed to
17 third parties, in whole or in part, without the prior written consent of
18 Coherent Labs AD.
19 
20 COHERENT LABS MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS
21 SOURCE CODE FOR ANY PURPOSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22 HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, ITS AFFILIATES,
26 PARENT COMPANIES, LICENSORS, SUPPLIERS, OR CONTRIBUTORS BE LIABLE FOR
27 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE OR SOURCE CODE,
33 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #pragma once
36 
37 #include <cohtml/Config.h>
38 
39 #if defined(COHERENT_COMPILER_SUPPORTS_IS_ENUM)
40 #include <type_traits>
41 #endif
42 
43 namespace cohtml
44 {
45 template <bool v>
46 struct BoolConstant
47 {
48  enum { Value = v };
49 };
50 
51 typedef BoolConstant<true> TrueType;
52 typedef BoolConstant<false> FalseType;
53 
54 #if defined(COHERENT_COMPILER_SUPPORTS_IS_ENUM)
55 template <typename T>
56 struct IsExposedByRef : BoolConstant<std::is_enum<T>::value>
57 {
58 };
59 #else
60 template <typename T>
61 struct IsExposedByRef : FalseType
62 {
63 };
64 #endif
65 
66 template <typename T>
67 struct IsExposedByRef<T&> : TrueType
68 {
69 };
70 
71 template <>
72 struct IsExposedByRef<bool> : TrueType
73 {
74 };
75 
76 template <>
77 struct IsExposedByRef<signed int> : TrueType
78 {
79 };
80 
81 template <>
82 struct IsExposedByRef<unsigned int> : TrueType
83 {
84 };
85 
86 template <>
87 struct IsExposedByRef<signed long> : TrueType
88 {
89 };
90 
91 template <>
92 struct IsExposedByRef<unsigned long> : TrueType
93 {
94 };
95 
96 template <>
97 struct IsExposedByRef<signed long long> : TrueType
98 {
99 };
100 
101 template <>
102 struct IsExposedByRef<unsigned long long> : TrueType
103 {
104 };
105 
106 template <>
107 struct IsExposedByRef<signed char> : TrueType
108 {
109 };
110 
111 template <>
112 struct IsExposedByRef<unsigned char> : TrueType
113 {
114 };
115 
116 template <>
117 struct IsExposedByRef<float> : TrueType
118 {
119 };
120 
121 template <>
122 struct IsExposedByRef<double> : TrueType
123 {
124 };
125 
126 template <>
127 struct IsExposedByRef<char*> : TrueType
128 {
129 };
130 
131 template <>
132 struct IsExposedByRef<wchar_t*> : TrueType
133 {
134 };
135 
136 template <>
137 struct IsExposedByRef<const bool> : TrueType
138 {
139 };
140 
141 template <>
142 struct IsExposedByRef<const signed int> : TrueType
143 {
144 };
145 
146 template <>
147 struct IsExposedByRef<const unsigned int> : TrueType
148 {
149 };
150 
151 template <>
152 struct IsExposedByRef<const signed long> : TrueType
153 {
154 };
155 
156 template <>
157 struct IsExposedByRef<const unsigned long> : TrueType
158 {
159 };
160 
161 template <>
162 struct IsExposedByRef<const signed long long> : TrueType
163 {
164 };
165 
166 template <>
167 struct IsExposedByRef<const unsigned long long> : TrueType
168 {
169 };
170 
171 template <>
172 struct IsExposedByRef<const signed char> : TrueType
173 {
174 };
175 
176 template <>
177 struct IsExposedByRef<const unsigned char> : TrueType
178 {
179 };
180 
181 template <>
182 struct IsExposedByRef<const float> : TrueType
183 {
184 };
185 
186 template <>
187 struct IsExposedByRef<const double> : TrueType
188 {
189 };
190 
191 template <>
192 struct IsExposedByRef<const char*> : TrueType
193 {
194 };
195 
196 template <>
197 struct IsExposedByRef<const wchar_t*> : TrueType
198 {
199 };
200 
201 template <typename T>
202 struct ReturnsByRef : FalseType
203 {
204 };
205 
206 template <typename T, typename C>
207 struct ReturnsByRef<T(C::*)> : TrueType
208 {
209  typedef T& ValuePassType;
210 };
211 
212 template <typename T, typename C>
213 struct ReturnsByRef<T(C::*)()> : IsExposedByRef<T>
214 {
215  typedef T ValuePassType;
216 };
217 
218 template <typename T, typename C>
219 struct ReturnsByRef<T(C::*)() const> : IsExposedByRef<T>
220 {
221  typedef T ValuePassType;
222 };
223 
224 template <typename T, typename C>
225 struct ReturnsByRef<T& (C::*)()> : IsExposedByRef<T&>
226 {
227  typedef const T& ValuePassType;
228 };
229 
230 template <typename T, typename C>
231 struct ReturnsByRef<T& (C::*)() const> : IsExposedByRef<T&>
232 {
233  typedef const T& ValuePassType;
234 };
235 
236 template <typename T>
237 struct RemoveConstRef
238 {
239  typedef T Type;
240 };
241 
242 template <typename T>
243 struct RemoveConstRef<const T>
244 {
245  typedef T Type;
246 };
247 
248 template <typename T>
249 struct RemoveConstRef<T &>
250 {
251  typedef T Type;
252 };
253 
254 template <typename T>
255 struct RemoveConstRef<const T &>
256 {
257  typedef T Type;
258 };
259 
260 template <typename T>
261 struct PointerTrait : FalseType
262 {
263  typedef T StoredType;
264 
265  static void* Deref(T& ptr)
266  {
267  return &ptr;
268  }
269 };
270 
271 template <typename T>
272 struct UnwrapPointer : PointerTrait<T>
273 {
274  static void* Unwrap(T* ptr)
275  {
276  if (!ptr || !PointerTrait<T>::Value)
277  {
278  return ptr;
279  }
280  typedef typename RemoveConstRef<typename PointerTrait<T>::StoredType>::Type ClearedStoredType;
281  return UnwrapPointer<ClearedStoredType>::Unwrap((ClearedStoredType*)PointerTrait<T>::Deref(*ptr));
282  }
283 };
284 
285 template <typename T, bool v>
286 struct UnwrapPointerType
287 {
288  typedef T Type;
289 };
290 
291 template <typename T>
292 struct UnwrapPointerType<T, true>
293 {
294  typedef typename PointerTrait<T>::StoredType StoredType;
295  typedef typename RemoveConstRef<StoredType>::Type ClearedStoredType;
296  typedef typename UnwrapPointerType<ClearedStoredType, PointerTrait<ClearedStoredType>::Value>::Type Type;
297 };
298 
299 template <typename T>
300 struct PointerTrait<T*> : TrueType
301 {
302  typedef T StoredType;
303  static void* Deref(T*& ptr)
304  {
305  return ptr;
306  }
307 };
308 
309 template <typename T>
310 struct PointerTrait<const T*> : TrueType
311 {
312  typedef T StoredType;
313  static void* Deref(const T*& ptr)
314  {
315  return const_cast<T*&>(ptr);
316  }
317 };
318 
319 template <bool Test, typename T = void>
320 struct EnableIf
321 {
322 };
323 
324 template <typename T>
325 struct EnableIf<true, T>
326 {
327  typedef T Type;
328 };
329 
330 }
Contains almost all Coherent namespaces, classes and functions.
Definition: DataStorage.h:38