cesium-native  0.41.0
PropertyTypeTraits.h
1 #pragma once
2 
3 #include "CesiumGltf/PropertyArrayView.h"
4 #include "CesiumGltf/PropertyType.h"
5 
6 #include <glm/glm.hpp>
7 
8 #include <cstdint>
9 #include <optional>
10 #include <type_traits>
11 
12 namespace CesiumGltf {
16 template <typename... T> struct IsMetadataScalar;
17 template <typename T> struct IsMetadataScalar<T> : std::false_type {};
18 template <> struct IsMetadataScalar<uint8_t> : std::true_type {};
19 template <> struct IsMetadataScalar<int8_t> : std::true_type {};
20 template <> struct IsMetadataScalar<uint16_t> : std::true_type {};
21 template <> struct IsMetadataScalar<int16_t> : std::true_type {};
22 template <> struct IsMetadataScalar<uint32_t> : std::true_type {};
23 template <> struct IsMetadataScalar<int32_t> : std::true_type {};
24 template <> struct IsMetadataScalar<uint64_t> : std::true_type {};
25 template <> struct IsMetadataScalar<int64_t> : std::true_type {};
26 template <> struct IsMetadataScalar<float> : std::true_type {};
27 template <> struct IsMetadataScalar<double> : std::true_type {};
28 
32 template <typename... T> struct IsMetadataInteger;
33 template <typename T> struct IsMetadataInteger<T> : std::false_type {};
34 template <> struct IsMetadataInteger<uint8_t> : std::true_type {};
35 template <> struct IsMetadataInteger<int8_t> : std::true_type {};
36 template <> struct IsMetadataInteger<uint16_t> : std::true_type {};
37 template <> struct IsMetadataInteger<int16_t> : std::true_type {};
38 template <> struct IsMetadataInteger<uint32_t> : std::true_type {};
39 template <> struct IsMetadataInteger<int32_t> : std::true_type {};
40 template <> struct IsMetadataInteger<uint64_t> : std::true_type {};
41 template <> struct IsMetadataInteger<int64_t> : std::true_type {};
42 
47 template <typename... T> struct IsMetadataFloating;
48 template <typename T> struct IsMetadataFloating<T> : std::false_type {};
49 template <> struct IsMetadataFloating<float> : std::true_type {};
50 template <> struct IsMetadataFloating<double> : std::true_type {};
51 
55 template <typename... T> struct IsMetadataVecN;
56 template <typename T> struct IsMetadataVecN<T> : std::false_type {};
57 template <glm::length_t n, typename T, glm::qualifier P>
58 struct IsMetadataVecN<glm::vec<n, T, P>> : IsMetadataScalar<T> {};
59 
63 template <typename... T> struct IsMetadataMatN;
64 template <typename T> struct IsMetadataMatN<T> : std::false_type {};
65 template <glm::length_t n, typename T, glm::qualifier P>
66 struct IsMetadataMatN<glm::mat<n, n, T, P>> : IsMetadataScalar<T> {};
67 
72 template <typename... T> struct IsMetadataNumeric;
73 template <typename T> struct IsMetadataNumeric<T> {
74  static constexpr bool value = IsMetadataScalar<T>::value ||
77 };
78 
82 template <typename... T> struct IsMetadataBoolean;
83 template <typename T> struct IsMetadataBoolean<T> : std::false_type {};
84 template <> struct IsMetadataBoolean<bool> : std::true_type {};
85 
89 template <typename... T> struct IsMetadataString;
90 template <typename T> struct IsMetadataString<T> : std::false_type {};
91 template <> struct IsMetadataString<std::string_view> : std::true_type {};
92 
96 template <typename... T> struct IsMetadataArray;
97 template <typename T> struct IsMetadataArray<T> : std::false_type {};
98 template <typename T>
99 struct IsMetadataArray<PropertyArrayView<T>> : std::true_type {};
100 template <typename T>
101 struct IsMetadataArray<PropertyArrayCopy<T>> : std::true_type {};
102 
107 template <typename... T> struct IsMetadataNumericArray;
108 template <typename T> struct IsMetadataNumericArray<T> : std::false_type {};
109 template <typename T> struct IsMetadataNumericArray<PropertyArrayView<T>> {
110  static constexpr bool value = IsMetadataNumeric<T>::value;
111 };
112 template <typename T> struct IsMetadataNumericArray<PropertyArrayCopy<T>> {
113  static constexpr bool value = IsMetadataNumeric<T>::value;
114 };
115 
120 template <typename... T> struct IsMetadataBooleanArray;
121 template <typename T> struct IsMetadataBooleanArray<T> : std::false_type {};
122 template <>
123 struct IsMetadataBooleanArray<PropertyArrayView<bool>> : std::true_type {};
124 
129 template <typename... T> struct IsMetadataStringArray;
130 template <typename T> struct IsMetadataStringArray<T> : std::false_type {};
131 template <>
132 struct IsMetadataStringArray<PropertyArrayView<std::string_view>>
133  : std::true_type {};
134 
138 template <typename T> struct MetadataArrayType {
139  using type = void;
140 };
141 template <typename T>
143  using type = T;
144 };
145 template <typename T>
147  using type = T;
148 };
149 
153 template <typename T> struct TypeToPropertyType;
154 
155 #pragma region Scalar Property Types
156 
157 template <> struct TypeToPropertyType<uint8_t> {
158  static constexpr PropertyComponentType component =
159  PropertyComponentType::Uint8;
160  static constexpr PropertyType value = PropertyType::Scalar;
161 };
162 
163 template <> struct TypeToPropertyType<int8_t> {
164  static constexpr PropertyComponentType component =
165  PropertyComponentType::Int8;
166  static constexpr PropertyType value = PropertyType::Scalar;
167 };
168 
169 template <> struct TypeToPropertyType<uint16_t> {
170  static constexpr PropertyComponentType component =
171  PropertyComponentType::Uint16;
172  static constexpr PropertyType value = PropertyType::Scalar;
173 };
174 
175 template <> struct TypeToPropertyType<int16_t> {
176  static constexpr PropertyComponentType component =
177  PropertyComponentType::Int16;
178  static constexpr PropertyType value = PropertyType::Scalar;
179 };
180 
181 template <> struct TypeToPropertyType<uint32_t> {
182  static constexpr PropertyComponentType component =
183  PropertyComponentType::Uint32;
184  static constexpr PropertyType value = PropertyType::Scalar;
185 };
186 
187 template <> struct TypeToPropertyType<int32_t> {
188  static constexpr PropertyComponentType component =
189  PropertyComponentType::Int32;
190  static constexpr PropertyType value = PropertyType::Scalar;
191 };
192 
193 template <> struct TypeToPropertyType<uint64_t> {
194  static constexpr PropertyComponentType component =
195  PropertyComponentType::Uint64;
196  static constexpr PropertyType value = PropertyType::Scalar;
197 };
198 
199 template <> struct TypeToPropertyType<int64_t> {
200  static constexpr PropertyComponentType component =
201  PropertyComponentType::Int64;
202  static constexpr PropertyType value = PropertyType::Scalar;
203 };
204 
205 template <> struct TypeToPropertyType<float> {
206  static constexpr PropertyComponentType component =
207  PropertyComponentType::Float32;
208  static constexpr PropertyType value = PropertyType::Scalar;
209 };
210 
211 template <> struct TypeToPropertyType<double> {
212  static constexpr PropertyComponentType component =
213  PropertyComponentType::Float64;
214  static constexpr PropertyType value = PropertyType::Scalar;
215 };
216 #pragma endregion
217 
218 #pragma region Vector Property Types
219 
220 template <typename T, glm::qualifier P>
221 struct TypeToPropertyType<glm::vec<2, T, P>> {
222  static constexpr PropertyComponentType component =
224  static constexpr PropertyType value = PropertyType::Vec2;
225 };
226 
227 template <typename T, glm::qualifier P>
228 struct TypeToPropertyType<glm::vec<3, T, P>> {
229  static constexpr PropertyComponentType component =
231  static constexpr PropertyType value = PropertyType::Vec3;
232 };
233 
234 template <typename T, glm::qualifier P>
235 struct TypeToPropertyType<glm::vec<4, T, P>> {
236  static constexpr PropertyComponentType component =
238  static constexpr PropertyType value = PropertyType::Vec4;
239 };
240 
241 #pragma endregion
242 
243 #pragma region Matrix Property Types
244 
245 template <typename T, glm::qualifier P>
246 struct TypeToPropertyType<glm::mat<2, 2, T, P>> {
247  static constexpr PropertyComponentType component =
249  static constexpr PropertyType value = PropertyType::Mat2;
250 };
251 
252 template <typename T, glm::qualifier P>
253 struct TypeToPropertyType<glm::mat<3, 3, T, P>> {
254  static constexpr PropertyComponentType component =
256  static constexpr PropertyType value = PropertyType::Mat3;
257 };
258 
259 template <typename T, glm::qualifier P>
260 struct TypeToPropertyType<glm::mat<4, 4, T, P>> {
261  static constexpr PropertyComponentType component =
263  static constexpr PropertyType value = PropertyType::Mat4;
264 };
265 
266 #pragma endregion
267 
268 template <> struct TypeToPropertyType<bool> {
269  static constexpr PropertyComponentType component =
270  PropertyComponentType::None;
271  static constexpr PropertyType value = PropertyType::Boolean;
272 };
273 
274 template <> struct TypeToPropertyType<std::string_view> {
275  static constexpr PropertyComponentType component =
276  PropertyComponentType::None;
277  static constexpr PropertyType value = PropertyType::String;
278 };
279 
283 template <typename... T> struct CanBeNormalized;
284 template <typename T> struct CanBeNormalized<T> : std::false_type {};
285 template <> struct CanBeNormalized<uint8_t> : std::true_type {};
286 template <> struct CanBeNormalized<int8_t> : std::true_type {};
287 template <> struct CanBeNormalized<uint16_t> : std::true_type {};
288 template <> struct CanBeNormalized<int16_t> : std::true_type {};
289 template <> struct CanBeNormalized<uint32_t> : std::true_type {};
290 template <> struct CanBeNormalized<int32_t> : std::true_type {};
291 template <> struct CanBeNormalized<uint64_t> : std::true_type {};
292 template <> struct CanBeNormalized<int64_t> : std::true_type {};
293 
294 template <glm::length_t n, typename T, glm::qualifier P>
295 struct CanBeNormalized<glm::vec<n, T, P>> : CanBeNormalized<T> {};
296 
297 template <glm::length_t n, typename T, glm::qualifier P>
298 struct CanBeNormalized<glm::mat<n, n, T, P>> : CanBeNormalized<T> {};
299 
300 template <typename T>
306 template <typename T> struct TypeToNormalizedType;
307 
308 template <> struct TypeToNormalizedType<int8_t> {
309  using type = double;
310 };
311 template <> struct TypeToNormalizedType<uint8_t> {
312  using type = double;
313 };
314 template <> struct TypeToNormalizedType<int16_t> {
315  using type = double;
316 };
317 template <> struct TypeToNormalizedType<uint16_t> {
318  using type = double;
319 };
320 template <> struct TypeToNormalizedType<int32_t> {
321  using type = double;
322 };
323 template <> struct TypeToNormalizedType<uint32_t> {
324  using type = double;
325 };
326 template <> struct TypeToNormalizedType<int64_t> {
327  using type = double;
328 };
329 template <> struct TypeToNormalizedType<uint64_t> {
330  using type = double;
331 };
332 
333 template <glm::length_t N, typename T, glm::qualifier Q>
334 struct TypeToNormalizedType<glm::vec<N, T, Q>> {
335  using type = glm::vec<N, double, Q>;
336 };
337 
338 template <glm::length_t N, typename T, glm::qualifier Q>
339 struct TypeToNormalizedType<glm::mat<N, N, T, Q>> {
340  using type = glm::mat<N, N, double, Q>;
341 };
342 
343 template <> struct TypeToNormalizedType<PropertyArrayView<int8_t>> {
345 };
346 template <> struct TypeToNormalizedType<PropertyArrayView<uint8_t>> {
348 };
349 template <> struct TypeToNormalizedType<PropertyArrayView<int16_t>> {
351 };
352 template <> struct TypeToNormalizedType<PropertyArrayView<uint16_t>> {
354 };
355 template <> struct TypeToNormalizedType<PropertyArrayView<int32_t>> {
357 };
358 template <> struct TypeToNormalizedType<PropertyArrayView<uint32_t>> {
360 };
361 template <> struct TypeToNormalizedType<PropertyArrayView<int64_t>> {
363 };
364 template <> struct TypeToNormalizedType<PropertyArrayView<uint64_t>> {
366 };
367 
368 template <glm::length_t N, typename T, glm::qualifier Q>
369 struct TypeToNormalizedType<PropertyArrayView<glm::vec<N, T, Q>>> {
371 };
372 
373 template <glm::length_t N, typename T, glm::qualifier Q>
374 struct TypeToNormalizedType<PropertyArrayView<glm::mat<N, N, T, Q>>> {
376 };
377 
387 template <typename T>
388 using PropertyValueViewToCopy = std::conditional_t<
391  T>;
392 
393 template <typename T>
394 using PropertyValueCopyToView = std::conditional_t<
397  T>;
398 
408 template <typename T>
409 static std::optional<PropertyValueViewToCopy<T>>
410 propertyValueViewToCopy(const std::optional<T>& view) {
411  if constexpr (IsMetadataNumericArray<T>::value) {
412  if (view) {
413  return std::make_optional<PropertyValueViewToCopy<T>>(
414  std::vector(view->begin(), view->end()));
415  } else {
416  return std::nullopt;
417  }
418  } else {
419  return view;
420  }
421 }
422 
423 template <typename T>
424 static PropertyValueViewToCopy<T> propertyValueViewToCopy(const T& view) {
425  if constexpr (IsMetadataNumericArray<T>::value) {
426  return PropertyValueViewToCopy<T>(std::vector(view.begin(), view.end()));
427  } else {
428  return view;
429  }
430 }
431 
432 template <typename T>
433 static PropertyValueCopyToView<T> propertyValueCopyToView(const T& copy) {
434  if constexpr (IsMetadataNumericArray<T>::value) {
435  return copy.view();
436  } else {
437  return copy;
438  }
439 }
440 
441 } // namespace CesiumGltf
A copy of an array element of a PropertyTableProperty or PropertyTextureProperty.
A view on an array element of a PropertyTableProperty or PropertyTextureProperty.
Classes for working with glTF models.
std::conditional_t< IsMetadataNumericArray< T >::value, PropertyArrayCopy< typename MetadataArrayType< T >::type >, T > PropertyValueViewToCopy
Transforms a property value type from a view to an equivalent type that owns the data it is viewing....
Check if a C++ type can be normalized.
Check if a C++ type can be represented as an array.
Check if a C++ type can be represented as an array of booleans property type.
Check if a C++ type can be represented as a boolean property type.
Check if a C++ type can be represented as a floating-point property type.
Check if a C++ type can be represented as an integer property type.
Check if a C++ type can be represented as a matN type.
Check if a C++ type can be represented as an array of numeric elements property type.
Check if a C++ type can be represented as a numeric property, i.e. a scalar / vecN / matN type.
Check if a C++ type can be represented as a scalar property type.
Check if a C++ type can be represented as an array of strings property type.
Check if a C++ type can be represented as a string property type.
Check if a C++ type can be represented as a vecN type.
Retrieve the component type of a metadata array.
Convert an integer numeric type to the corresponding representation as a double type....
Convert a C++ type to PropertyType and PropertyComponentType.