1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_CORE_PROPERTY_PROPERTY_TYPES_H
17 #define API_CORE_PROPERTY_PROPERTY_TYPES_H
18
19 #include <cstdint>
20
21 #include <base/containers/string.h>
22 #include <base/containers/string_view.h>
23 #include <base/containers/type_traits.h>
24 #include <base/namespace.h>
25 #include <core/namespace.h>
26 #include <core/property/property.h>
27
BASE_BEGIN_NAMESPACE()28 BASE_BEGIN_NAMESPACE()
29 namespace Math {
30 class Mat3X3;
31 class Mat4X4;
32 class Quat;
33 class IVec2;
34 class IVec3;
35 class IVec4;
36 class UVec2;
37 class UVec3;
38 class UVec4;
39 class Vec2;
40 class Vec3;
41 class Vec4;
42 } // namespace Math
43 struct Uid;
44 template<typename T>
45 class vector;
46 BASE_END_NAMESPACE()
47
48 CORE_BEGIN_NAMESPACE()
49 class EntityReference;
50 struct Entity;
51
52 namespace PropertyType {
53 /* Primitive types */
54 inline constexpr PropertyTypeDecl BOOL_T = PROPERTYTYPE(bool);
55 inline constexpr PropertyTypeDecl CHAR_T = PROPERTYTYPE(char);
56 inline constexpr PropertyTypeDecl INT8_T = PROPERTYTYPE(int8_t);
57 inline constexpr PropertyTypeDecl INT16_T = PROPERTYTYPE(int16_t);
58 inline constexpr PropertyTypeDecl INT32_T = PROPERTYTYPE(int32_t);
59 inline constexpr PropertyTypeDecl INT64_T = PROPERTYTYPE(int64_t);
60 inline constexpr PropertyTypeDecl UINT8_T = PROPERTYTYPE(uint8_t);
61 inline constexpr PropertyTypeDecl UINT16_T = PROPERTYTYPE(uint16_t);
62 inline constexpr PropertyTypeDecl UINT32_T = PROPERTYTYPE(uint32_t);
63 inline constexpr PropertyTypeDecl UINT64_T = PROPERTYTYPE(uint64_t);
64 #ifdef __APPLE__
65 inline constexpr PropertyTypeDecl SIZE_T = PROPERTYTYPE(size_t);
66 #endif
67 inline constexpr PropertyTypeDecl FLOAT_T = PROPERTYTYPE(float);
68 inline constexpr PropertyTypeDecl DOUBLE_T = PROPERTYTYPE(double);
69
70 inline constexpr PropertyTypeDecl BOOL_ARRAY_T = PROPERTYTYPE_ARRAY(bool);
71 inline constexpr PropertyTypeDecl CHAR_ARRAY_T = PROPERTYTYPE_ARRAY(char);
72 inline constexpr PropertyTypeDecl INT8_ARRAY_T = PROPERTYTYPE_ARRAY(int8_t);
73 inline constexpr PropertyTypeDecl INT16_ARRAY_T = PROPERTYTYPE_ARRAY(int16_t);
74 inline constexpr PropertyTypeDecl INT32_ARRAY_T = PROPERTYTYPE_ARRAY(int32_t);
75 inline constexpr PropertyTypeDecl INT64_ARRAY_T = PROPERTYTYPE_ARRAY(int64_t);
76 inline constexpr PropertyTypeDecl UINT8_ARRAY_T = PROPERTYTYPE_ARRAY(uint8_t);
77 inline constexpr PropertyTypeDecl UINT16_ARRAY_T = PROPERTYTYPE_ARRAY(uint16_t);
78 inline constexpr PropertyTypeDecl UINT32_ARRAY_T = PROPERTYTYPE_ARRAY(uint32_t);
79 inline constexpr PropertyTypeDecl UINT64_ARRAY_T = PROPERTYTYPE_ARRAY(uint64_t);
80 #ifdef __APPLE__
81 inline constexpr PropertyTypeDecl SIZE_ARRAY_T = PROPERTYTYPE_ARRAY(size_t);
82 #endif
83 inline constexpr PropertyTypeDecl FLOAT_ARRAY_T = PROPERTYTYPE_ARRAY(float);
84 inline constexpr PropertyTypeDecl DOUBLE_ARRAY_T = PROPERTYTYPE_ARRAY(double);
85
86 /* Extended types */
87 inline constexpr PropertyTypeDecl IVEC2_T = PROPERTYTYPE(BASE_NS::Math::IVec2);
88 inline constexpr PropertyTypeDecl IVEC3_T = PROPERTYTYPE(BASE_NS::Math::IVec3);
89 inline constexpr PropertyTypeDecl IVEC4_T = PROPERTYTYPE(BASE_NS::Math::IVec4);
90 inline constexpr PropertyTypeDecl VEC2_T = PROPERTYTYPE(BASE_NS::Math::Vec2);
91 inline constexpr PropertyTypeDecl VEC3_T = PROPERTYTYPE(BASE_NS::Math::Vec3);
92 inline constexpr PropertyTypeDecl VEC4_T = PROPERTYTYPE(BASE_NS::Math::Vec4);
93 inline constexpr PropertyTypeDecl UVEC2_T = PROPERTYTYPE(BASE_NS::Math::UVec2);
94 inline constexpr PropertyTypeDecl UVEC3_T = PROPERTYTYPE(BASE_NS::Math::UVec3);
95 inline constexpr PropertyTypeDecl UVEC4_T = PROPERTYTYPE(BASE_NS::Math::UVec4);
96 inline constexpr PropertyTypeDecl QUAT_T = PROPERTYTYPE(BASE_NS::Math::Quat);
97 inline constexpr PropertyTypeDecl MAT3X3_T = PROPERTYTYPE(BASE_NS::Math::Mat3X3);
98 inline constexpr PropertyTypeDecl MAT4X4_T = PROPERTYTYPE(BASE_NS::Math::Mat4X4);
99 inline constexpr PropertyTypeDecl UID_T = PROPERTYTYPE(BASE_NS::Uid);
100 inline constexpr PropertyTypeDecl ENTITY_T = PROPERTYTYPE(Entity);
101 inline constexpr PropertyTypeDecl ENTITY_REFERENCE_T = PROPERTYTYPE(EntityReference);
102 inline constexpr PropertyTypeDecl STRING_T = PROPERTYTYPE(BASE_NS::string);
103
104 inline constexpr PropertyTypeDecl IVEC2_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::IVec2);
105 inline constexpr PropertyTypeDecl IVEC3_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::IVec3);
106 inline constexpr PropertyTypeDecl IVEC4_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::IVec4);
107 inline constexpr PropertyTypeDecl VEC2_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Vec2);
108 inline constexpr PropertyTypeDecl VEC3_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Vec3);
109 inline constexpr PropertyTypeDecl VEC4_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Vec4);
110 inline constexpr PropertyTypeDecl UVEC2_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::UVec2);
111 inline constexpr PropertyTypeDecl UVEC3_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::UVec3);
112 inline constexpr PropertyTypeDecl UVEC4_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::UVec4);
113 inline constexpr PropertyTypeDecl QUAT_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Quat);
114 inline constexpr PropertyTypeDecl MAT3X3_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Mat3X3);
115 inline constexpr PropertyTypeDecl MAT4X4_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Math::Mat4X4);
116 inline constexpr PropertyTypeDecl UID_ARRAY_T = PROPERTYTYPE_ARRAY(BASE_NS::Uid);
117 inline constexpr PropertyTypeDecl ENTITY_ARRAY_T = PROPERTYTYPE_ARRAY(Entity);
118 inline constexpr PropertyTypeDecl ENTITY_REFERENCE_ARRAY_T = PROPERTYTYPE_ARRAY(EntityReference);
119
120 inline constexpr PropertyTypeDecl FLOAT_VECTOR_T = PROPERTYTYPE(BASE_NS::vector<float>);
121 inline constexpr PropertyTypeDecl MAT4X4_VECTOR_T = PROPERTYTYPE(BASE_NS::vector<BASE_NS::Math::Mat4X4>);
122 inline constexpr PropertyTypeDecl ENTITY_REFERENCE_VECTOR_T = PROPERTYTYPE(BASE_NS::vector<EntityReference>);
123
124 inline constexpr PropertyTypeDecl INVALID = PropertyTypeDecl { false, 0, 0, "" };
125 } // namespace PropertyType
126
127 // The following declarations should not be used at public headers anymore, it's purely implementation stuff now
128 namespace PropertySystem {
129 template<class T>
130 struct is_defined : BASE_NS::false_type {
131 using type = BASE_NS::false_type;
132 };
133 template<class T, class B>
PropertyTypeDeclFromType()134 inline constexpr auto PropertyTypeDeclFromType()
135 {
136 static_assert(is_defined<T>().value, "Missing DECLARE_PROPERTY_TYPE for used type.");
137 return CORE_NS::PropertyTypeDecl {};
138 }
139 } // namespace PropertySystem
140
141 #define DECLARE_PROPERTY_TYPE(aType) \
142 namespace PropertySystem { \
143 template<> \
144 struct is_defined<aType> : BASE_NS::true_type { \
145 using type = BASE_NS::true_type; \
146 }; \
147 template<> \
148 inline constexpr auto PropertyTypeDeclFromType<const aType, BASE_NS::false_type>() \
149 { \
150 return PROPERTYTYPE(aType); \
151 } \
152 template<> \
153 inline constexpr auto PropertyTypeDeclFromType<const aType, BASE_NS::true_type>() \
154 { \
155 return PROPERTYTYPE_ARRAY(aType); \
156 } \
157 template<> \
158 inline constexpr auto PropertyTypeDeclFromType<aType, BASE_NS::false_type>() \
159 { \
160 return PROPERTYTYPE(aType); \
161 } \
162 template<> \
163 inline constexpr auto PropertyTypeDeclFromType<aType, BASE_NS::true_type>() \
164 { \
165 return PROPERTYTYPE_ARRAY(aType); \
166 } \
167 } // namespace PropertySystem
168 CORE_END_NAMESPACE()
169 #endif // API_CORE_PROPERTY_PROPERTY_TYPES_H
170