1.3.1.2
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 #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>
62 {
63 };
64 #endif
65 
66 template <typename T>
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>
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>
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>
262 {
263  typedef T Type;
264 };
265 
266 template <typename T>
267 struct RemoveConst<const T>
268 {
269  typedef T Type;
270 };
271 
272 template <typename T>
273 struct RemoveConst<const T&>
274 {
275  typedef T& Type;
276 };
277 
278 template <typename T>
279 struct RemoveRef
280 {
281  typedef T Type;
282 };
283 
284 template <typename T>
285 struct RemoveRef<T&>
286 {
287  typedef T Type;
288 };
289 
290 template <typename T>
291 struct RemoveRef<const T&>
292 {
293  typedef const T Type;
294 };
295 
296 template <typename T>
298 {
299  typedef T StoredType;
300 
301  static void* Deref(T& ptr)
302  {
303  return &ptr;
304  }
305 };
306 
307 template <typename T>
309 {
310 };
311 
312 template <typename T>
313 struct PointerTrait<const T> : PointerTrait<T>
314 {
315 };
316 
317 template <typename T>
318 struct PointerTrait<const T&> : PointerTrait<T>
319 {
320 };
321 
322 template <typename T>
324 {
325  static void* Unwrap(T* ptr)
326  {
327  if (!ptr || !PointerTrait<T>::Value)
328  {
329  return ptr;
330  }
331  typedef typename PointerTrait<T>::StoredType StoredType;
333  }
334 };
335 
336 template <typename T>
337 struct UnwrapPointer<const T> : UnwrapPointer<T>
338 {
339 };
340 
341 template <typename T>
343 {
344 };
345 
346 template <typename T>
347 struct UnwrapPointer<const T&> : UnwrapPointer<T>
348 {
349 };
350 
351 template <typename T, bool v>
353 {
354  typedef T Type;
355 };
356 
357 template <typename T>
358 struct UnwrapPointerType<T, true>
359 {
362 };
363 
364 template <typename T>
365 struct PointerTrait<T*> : TrueType
366 {
367  typedef T StoredType;
368  static void* Deref(T*& ptr)
369  {
370  return ptr;
371  }
372 };
373 
374 template <typename T>
375 struct PointerTrait<const T*> : TrueType
376 {
377  typedef T StoredType;
378  static void* Deref(const T*& ptr)
379  {
380  return const_cast<T*&>(ptr);
381  }
382 };
383 
384 template <bool Test, typename T = void>
385 struct EnableIf
386 {
387 };
388 
389 template <typename T>
390 struct EnableIf<true, T>
391 {
392  typedef T Type;
393 };
394 
395 template <typename T>
397 {
398 };
399 
400 template <typename T>
401 struct IsCString<const T*> : IsCString<T*>
402 {
403 };
404 
405 #define CSTRING_TYPETRAIT(CharType) \
406 template <> \
407 struct IsCString<CharType*> : TrueType \
408 { \
409 }; \
410 template <> \
411 struct PointerTrait<CharType*> : FalseType \
412 { \
413  typedef CharType* StoredType; \
414  static void* Deref(StoredType& ptr) \
415  { \
416  return &ptr; \
417  } \
418 }; \
419 template <> \
420 struct PointerTrait<const CharType*> : FalseType \
421 { \
422  typedef const CharType* StoredType; \
423  static void* Deref(StoredType& ptr) \
424  { \
425  return &ptr; \
426  } \
427 };
428 
429 CSTRING_TYPETRAIT(char);
430 CSTRING_TYPETRAIT(wchar_t);
431 CSTRING_TYPETRAIT(char16_t);
432 CSTRING_TYPETRAIT(char32_t);
433 
434 #undef CSTRING_TYPETRAIT
435 
436 }
UnwrapPointerType< StoredType, PointerTrait< StoredType >::Value >::Type Type
Definition: TypeTraits.h:361
Definition: TypeTraits.h:237
Definition: TypeTraits.h:297
const T & ValuePassType
Definition: TypeTraits.h:233
Definition: TypeTraits.h:323
T Type
Definition: TypeTraits.h:354
Definition: TypeTraits.h:261
const T & ValuePassType
Definition: TypeTraits.h:227
T & Type
Definition: TypeTraits.h:275
Definition: TypeTraits.h:61
static void * Unwrap(T *ptr)
Definition: TypeTraits.h:325
Contains almost all Coherent namespaces, classes and functions.
Definition: CursorTypes.h:37
T Type
Definition: TypeTraits.h:392
BoolConstant< false > FalseType
Definition: TypeTraits.h:52
T Type
Definition: TypeTraits.h:281
Definition: TypeTraits.h:67
CSTRING_TYPETRAIT(char)
T StoredType
Definition: TypeTraits.h:377
BoolConstant< true > TrueType
Definition: TypeTraits.h:51
T & ValuePassType
Definition: TypeTraits.h:209
Definition: TypeTraits.h:396
static void * Deref(const T *&ptr)
Definition: TypeTraits.h:378
T Type
Definition: TypeTraits.h:257
static void * Deref(T *&ptr)
Definition: TypeTraits.h:368
T ValuePassType
Definition: TypeTraits.h:215
T Type
Definition: TypeTraits.h:239
T StoredType
Definition: TypeTraits.h:299
T Type
Definition: TypeTraits.h:263
T Type
Definition: TypeTraits.h:251
T ValuePassType
Definition: TypeTraits.h:221
Definition: TypeTraits.h:202
T Type
Definition: TypeTraits.h:287
Definition: TypeTraits.h:48
Definition: TypeTraits.h:46
T StoredType
Definition: TypeTraits.h:367
T Type
Definition: TypeTraits.h:269
PointerTrait< T >::StoredType StoredType
Definition: TypeTraits.h:360
Definition: TypeTraits.h:352
Definition: TypeTraits.h:385
const T Type
Definition: TypeTraits.h:293
T Type
Definition: TypeTraits.h:245
static void * Deref(T &ptr)
Definition: TypeTraits.h:301
Definition: TypeTraits.h:279