1.6.0.1
Gameface
TypeTraits.h
1 /*
2 This file is part of Cohtml, Gameface and Prysm - modern user interface technologies.
3 
4 Copyright (c) 2012-2018 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>
47 {
48  enum { Value = v };
49 };
50 
53 
54 template <typename T1, typename T2>
55 struct IsSame : FalseType
56 {
57 };
58 
59 template <typename T>
60 struct IsSame<T, T> : TrueType
61 {
62 };
63 
64 
65 #if defined(COHERENT_COMPILER_SUPPORTS_IS_ENUM)
66 template <typename T>
67 struct IsExposedByRef : BoolConstant<std::is_enum<T>::value>
68 {
69 };
70 #else
71 template <typename T>
73 {
74 };
75 #endif
76 
77 template <typename T>
79 {
80 };
81 
82 template <>
83 struct IsExposedByRef<bool> : TrueType
84 {
85 };
86 
87 template <>
88 struct IsExposedByRef<signed int> : TrueType
89 {
90 };
91 
92 template <>
93 struct IsExposedByRef<unsigned int> : TrueType
94 {
95 };
96 
97 template <>
98 struct IsExposedByRef<signed long> : TrueType
99 {
100 };
101 
102 template <>
103 struct IsExposedByRef<unsigned long> : TrueType
104 {
105 };
106 
107 template <>
108 struct IsExposedByRef<signed long long> : TrueType
109 {
110 };
111 
112 template <>
113 struct IsExposedByRef<unsigned long long> : TrueType
114 {
115 };
116 
117 template <>
118 struct IsExposedByRef<signed char> : TrueType
119 {
120 };
121 
122 template <>
123 struct IsExposedByRef<unsigned char> : TrueType
124 {
125 };
126 
127 template <>
128 struct IsExposedByRef<float> : TrueType
129 {
130 };
131 
132 template <>
133 struct IsExposedByRef<double> : TrueType
134 {
135 };
136 
137 template <>
138 struct IsExposedByRef<char*> : TrueType
139 {
140 };
141 
142 template <>
143 struct IsExposedByRef<wchar_t*> : TrueType
144 {
145 };
146 
147 template <>
148 struct IsExposedByRef<const bool> : TrueType
149 {
150 };
151 
152 template <>
153 struct IsExposedByRef<const signed int> : TrueType
154 {
155 };
156 
157 template <>
158 struct IsExposedByRef<const unsigned int> : TrueType
159 {
160 };
161 
162 template <>
163 struct IsExposedByRef<const signed long> : TrueType
164 {
165 };
166 
167 template <>
168 struct IsExposedByRef<const unsigned long> : TrueType
169 {
170 };
171 
172 template <>
173 struct IsExposedByRef<const signed long long> : TrueType
174 {
175 };
176 
177 template <>
178 struct IsExposedByRef<const unsigned long long> : TrueType
179 {
180 };
181 
182 template <>
183 struct IsExposedByRef<const signed char> : TrueType
184 {
185 };
186 
187 template <>
188 struct IsExposedByRef<const unsigned char> : TrueType
189 {
190 };
191 
192 template <>
193 struct IsExposedByRef<const float> : TrueType
194 {
195 };
196 
197 template <>
198 struct IsExposedByRef<const double> : TrueType
199 {
200 };
201 
202 template <>
203 struct IsExposedByRef<const char*> : TrueType
204 {
205 };
206 
207 template <>
208 struct IsExposedByRef<const wchar_t*> : TrueType
209 {
210 };
211 
212 template <typename T>
214 {
215 };
216 
217 template <typename T, typename C>
218 struct ReturnsByRef<T(C::*)> : TrueType
219 {
220  typedef T& ValuePassType;
221 };
222 
223 template <typename T, typename C>
224 struct ReturnsByRef<T(C::*)()> : IsExposedByRef<T>
225 {
226  typedef T ValuePassType;
227 };
228 
229 template <typename T, typename C>
230 struct ReturnsByRef<T(C::*)() const> : IsExposedByRef<T>
231 {
232  typedef T ValuePassType;
233 };
234 
235 template <typename T, typename C>
236 struct ReturnsByRef<T& (C::*)()> : IsExposedByRef<T&>
237 {
238  typedef const T& ValuePassType;
239 };
240 
241 template <typename T, typename C>
242 struct ReturnsByRef<T& (C::*)() const> : IsExposedByRef<T&>
243 {
244  typedef const T& ValuePassType;
245 };
246 
247 template <typename T>
249 {
250  typedef T Type;
251 };
252 
253 template <typename T>
254 struct RemoveConstRef<const T>
255 {
256  typedef T Type;
257 };
258 
259 template <typename T>
260 struct RemoveConstRef<T &>
261 {
262  typedef T Type;
263 };
264 
265 template <typename T>
266 struct RemoveConstRef<const T &>
267 {
268  typedef T Type;
269 };
270 
271 template <typename T>
273 {
274  typedef T Type;
275 };
276 
277 template <typename T>
278 struct RemoveConst<const T>
279 {
280  typedef T Type;
281 };
282 
283 template <typename T>
284 struct RemoveConst<const T&>
285 {
286  typedef T& Type;
287 };
288 
289 template <typename T>
290 struct RemoveRef
291 {
292  typedef T Type;
293 };
294 
295 template <typename T>
296 struct RemoveRef<T&>
297 {
298  typedef T Type;
299 };
300 
301 template <typename T>
302 struct RemoveRef<const T&>
303 {
304  typedef const T Type;
305 };
306 
307 template <typename T>
309 {
310  typedef T StoredType;
311 
312  static void* Deref(T& ptr)
313  {
314  return &ptr;
315  }
316 };
317 
318 template <typename T>
320 {
321 };
322 
323 template <typename T>
324 struct PointerTrait<const T> : PointerTrait<T>
325 {
326 };
327 
328 template <typename T>
329 struct PointerTrait<const T&> : PointerTrait<T>
330 {
331 };
332 
333 template <typename T>
335 {
336  static void* Unwrap(T* ptr)
337  {
338  if (!ptr || !PointerTrait<T>::Value)
339  {
340  return ptr;
341  }
342  typedef typename PointerTrait<T>::StoredType StoredType;
344  }
345 };
346 
347 template <typename T>
348 struct UnwrapPointer<const T> : UnwrapPointer<T>
349 {
350 };
351 
352 template <typename T>
354 {
355 };
356 
357 template <typename T>
358 struct UnwrapPointer<const T&> : UnwrapPointer<T>
359 {
360 };
361 
362 template <typename T, bool v>
364 {
365  typedef T Type;
366 };
367 
368 template <typename T>
369 struct UnwrapPointerType<T, true>
370 {
373 };
374 
375 template <typename T>
376 struct PointerTrait<T*> : TrueType
377 {
378  typedef T StoredType;
379  static void* Deref(T*& ptr)
380  {
381  return ptr;
382  }
383 };
384 
385 template <typename T>
386 struct PointerTrait<const T*> : TrueType
387 {
388  typedef T StoredType;
389  static void* Deref(const T*& ptr)
390  {
391  return const_cast<T*&>(ptr);
392  }
393 };
394 
395 template <bool Test, typename T = void>
396 struct EnableIf
397 {
398 };
399 
400 template <typename T>
401 struct EnableIf<true, T>
402 {
403  typedef T Type;
404 };
405 
406 template <typename T>
408 {
409 };
410 
411 template <typename T>
412 struct IsConst<const T> : TrueType
413 {
414 };
415 
416 
417 template <typename T>
419 {
420 };
421 
422 template <typename T, typename C>
423 struct MemberPointerTraits<T C::*>
424 {
425  typedef C ObjectType;
426  typedef T MemberType;
427 };
428 
429 template <typename T>
431 {
432 };
433 
434 template <typename T>
436 {
437 };
438 
439 template <typename T>
440 struct IsCString<const T*> : IsCString<T*>
441 {
442 };
443 
444 #define CSTRING_TYPETRAIT(CharType) \
445 template <> \
446 struct IsCString<CharType*> : TrueType \
447 { \
448 }; \
449 template <> \
450 struct PointerTrait<CharType*> : FalseType \
451 { \
452  typedef CharType* StoredType; \
453  static void* Deref(StoredType& ptr) \
454  { \
455  return &ptr; \
456  } \
457 }; \
458 template <> \
459 struct PointerTrait<const CharType*> : FalseType \
460 { \
461  typedef const CharType* StoredType; \
462  static void* Deref(StoredType& ptr) \
463  { \
464  return &ptr; \
465  } \
466 }; \
467 template <> \
468 struct IsChar<CharType> : TrueType \
469 { \
470 }; \
471 template <> \
472 struct IsChar<const CharType> : TrueType \
473 { \
474 };
475 
476 CSTRING_TYPETRAIT(char);
477 CSTRING_TYPETRAIT(signed char);
478 CSTRING_TYPETRAIT(unsigned char);
479 CSTRING_TYPETRAIT(wchar_t);
480 CSTRING_TYPETRAIT(char16_t);
481 CSTRING_TYPETRAIT(char32_t);
482 
483 #undef CSTRING_TYPETRAIT
484 
485 }
C ObjectType
Definition: TypeTraits.h:425
UnwrapPointerType< StoredType, PointerTrait< StoredType >::Value >::Type Type
Definition: TypeTraits.h:372
Definition: TypeTraits.h:248
Definition: TypeTraits.h:308
Definition: TypeTraits.h:407
const T & ValuePassType
Definition: TypeTraits.h:244
Definition: TypeTraits.h:334
T Type
Definition: TypeTraits.h:365
Definition: TypeTraits.h:272
const T & ValuePassType
Definition: TypeTraits.h:238
T & Type
Definition: TypeTraits.h:286
Definition: TypeTraits.h:72
static void * Unwrap(T *ptr)
Definition: TypeTraits.h:336
Contains almost all Coherent namespaces, classes and functions.
Definition: CursorTypes.h:37
T MemberType
Definition: TypeTraits.h:426
T Type
Definition: TypeTraits.h:403
BoolConstant< false > FalseType
Definition: TypeTraits.h:52
T Type
Definition: TypeTraits.h:292
Definition: TypeTraits.h:78
CSTRING_TYPETRAIT(char)
T StoredType
Definition: TypeTraits.h:388
BoolConstant< true > TrueType
Definition: TypeTraits.h:51
T & ValuePassType
Definition: TypeTraits.h:220
Definition: TypeTraits.h:435
static void * Deref(const T *&ptr)
Definition: TypeTraits.h:389
T Type
Definition: TypeTraits.h:268
static void * Deref(T *&ptr)
Definition: TypeTraits.h:379
T ValuePassType
Definition: TypeTraits.h:226
T Type
Definition: TypeTraits.h:250
Definition: TypeTraits.h:55
T StoredType
Definition: TypeTraits.h:310
T Type
Definition: TypeTraits.h:274
T Type
Definition: TypeTraits.h:262
T ValuePassType
Definition: TypeTraits.h:232
Definition: TypeTraits.h:213
T Type
Definition: TypeTraits.h:298
Definition: TypeTraits.h:48
Definition: TypeTraits.h:46
T StoredType
Definition: TypeTraits.h:378
T Type
Definition: TypeTraits.h:280
PointerTrait< T >::StoredType StoredType
Definition: TypeTraits.h:371
Definition: TypeTraits.h:363
Definition: TypeTraits.h:396
const T Type
Definition: TypeTraits.h:304
Definition: TypeTraits.h:418
T Type
Definition: TypeTraits.h:256
Definition: TypeTraits.h:430
static void * Deref(T &ptr)
Definition: TypeTraits.h:312
Definition: TypeTraits.h:290