1 /*************************************************************************/
2 /*  simple_type.h                                                        */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 #ifndef SIMPLE_TYPE_H
31 #define SIMPLE_TYPE_H
32 
33 /* Batch of specializations to obtain the actual simple type */
34 
35 template <class T>
36 struct GetSimpleType {
37 
38 	T type;
39 };
40 
41 template <class T>
42 struct GetSimpleTypeT {
43 
44 	typedef T type_t;
45 };
46 
47 template <class T>
48 struct GetSimpleType<T &> {
49 
50 	T type;
51 };
52 
53 template <class T>
54 struct GetSimpleTypeT<T &> {
55 
56 	typedef T type_t;
57 };
58 
59 template <class T>
60 struct GetSimpleType<T const> {
61 
62 	T type;
63 	_FORCE_INLINE_ GetSimpleType() {}
64 };
65 
66 template <class T>
67 struct GetSimpleTypeT<T const> {
68 
69 	typedef T type_t;
70 };
71 
72 template <class T>
73 struct GetSimpleType<const T &> {
74 
75 	T type;
76 	_FORCE_INLINE_ GetSimpleType() {}
77 };
78 
79 template <class T>
80 struct GetSimpleType<T *> {
81 
82 	T *type;
83 	_FORCE_INLINE_ GetSimpleType() { type = NULL; }
84 };
85 
86 template <class T>
87 struct GetSimpleType<const T *> {
88 
89 	T *type;
90 	_FORCE_INLINE_ GetSimpleType() { type = NULL; }
91 };
92 
93 #define SIMPLE_NUMERIC_TYPE(m_type)                          \
94 	template <>                                              \
95 	struct GetSimpleType<m_type> {                           \
96 		m_type type;                                         \
97 		_FORCE_INLINE_ GetSimpleType() { type = (m_type)0; } \
98 	};                                                       \
99 	template <>                                              \
100 	struct GetSimpleType<m_type const> {                     \
101 		m_type type;                                         \
102 		_FORCE_INLINE_ GetSimpleType() { type = (m_type)0; } \
103 	};                                                       \
104 	template <>                                              \
105 	struct GetSimpleType<m_type &> {                         \
106 		m_type type;                                         \
107 		_FORCE_INLINE_ GetSimpleType() { type = (m_type)0; } \
108 	};                                                       \
109 	template <>                                              \
110 	struct GetSimpleType<const m_type &> {                   \
111 		m_type type;                                         \
112 		_FORCE_INLINE_ GetSimpleType() { type = (m_type)0; } \
113 	};
114 
115 SIMPLE_NUMERIC_TYPE(bool);
116 SIMPLE_NUMERIC_TYPE(uint8_t);
117 SIMPLE_NUMERIC_TYPE(int8_t);
118 SIMPLE_NUMERIC_TYPE(uint16_t);
119 SIMPLE_NUMERIC_TYPE(int16_t);
120 SIMPLE_NUMERIC_TYPE(uint32_t);
121 SIMPLE_NUMERIC_TYPE(int32_t);
122 SIMPLE_NUMERIC_TYPE(int64_t);
123 SIMPLE_NUMERIC_TYPE(uint64_t);
124 SIMPLE_NUMERIC_TYPE(float);
125 SIMPLE_NUMERIC_TYPE(double);
126 
127 #endif
128