cesium-native 0.43.0
Loading...
Searching...
No Matches
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
12namespace CesiumGltf {
16template <typename... T> struct IsMetadataScalar;
18template <typename T> struct IsMetadataScalar<T> : std::false_type {};
20template <> struct IsMetadataScalar<uint8_t> : std::true_type {};
22template <> struct IsMetadataScalar<int8_t> : std::true_type {};
24template <> struct IsMetadataScalar<uint16_t> : std::true_type {};
26template <> struct IsMetadataScalar<int16_t> : std::true_type {};
28template <> struct IsMetadataScalar<uint32_t> : std::true_type {};
30template <> struct IsMetadataScalar<int32_t> : std::true_type {};
32template <> struct IsMetadataScalar<uint64_t> : std::true_type {};
34template <> struct IsMetadataScalar<int64_t> : std::true_type {};
36template <> struct IsMetadataScalar<float> : std::true_type {};
38template <> struct IsMetadataScalar<double> : std::true_type {};
39
43template <typename... T> struct IsMetadataInteger;
45template <typename T> struct IsMetadataInteger<T> : std::false_type {};
47template <> struct IsMetadataInteger<uint8_t> : std::true_type {};
49template <> struct IsMetadataInteger<int8_t> : std::true_type {};
51template <> struct IsMetadataInteger<uint16_t> : std::true_type {};
53template <> struct IsMetadataInteger<int16_t> : std::true_type {};
55template <> struct IsMetadataInteger<uint32_t> : std::true_type {};
57template <> struct IsMetadataInteger<int32_t> : std::true_type {};
59template <> struct IsMetadataInteger<uint64_t> : std::true_type {};
61template <> struct IsMetadataInteger<int64_t> : std::true_type {};
62
67template <typename... T> struct IsMetadataFloating;
69template <typename T> struct IsMetadataFloating<T> : std::false_type {};
71template <> struct IsMetadataFloating<float> : std::true_type {};
73template <> struct IsMetadataFloating<double> : std::true_type {};
74
78template <typename... T> struct IsMetadataVecN;
80template <typename T> struct IsMetadataVecN<T> : std::false_type {};
82template <glm::length_t n, typename T, glm::qualifier P>
83struct IsMetadataVecN<glm::vec<n, T, P>> : IsMetadataScalar<T> {};
84
88template <typename... T> struct IsMetadataMatN;
90template <typename T> struct IsMetadataMatN<T> : std::false_type {};
92template <glm::length_t n, typename T, glm::qualifier P>
93struct IsMetadataMatN<glm::mat<n, n, T, P>> : IsMetadataScalar<T> {};
94
99template <typename... T> struct IsMetadataNumeric;
103template <typename T> struct IsMetadataNumeric<T> {
107 static constexpr bool value = IsMetadataScalar<T>::value ||
110};
111
115template <typename... T> struct IsMetadataBoolean;
117template <typename T> struct IsMetadataBoolean<T> : std::false_type {};
119template <> struct IsMetadataBoolean<bool> : std::true_type {};
120
124template <typename... T> struct IsMetadataString;
126template <typename T> struct IsMetadataString<T> : std::false_type {};
128template <> struct IsMetadataString<std::string_view> : std::true_type {};
129
133template <typename... T> struct IsMetadataArray;
135template <typename T> struct IsMetadataArray<T> : std::false_type {};
137template <typename T>
138struct IsMetadataArray<PropertyArrayView<T>> : std::true_type {};
140template <typename T>
141struct IsMetadataArray<PropertyArrayCopy<T>> : std::true_type {};
142
147template <typename... T> struct IsMetadataNumericArray;
149template <typename T> struct IsMetadataNumericArray<T> : std::false_type {};
151template <typename T> struct IsMetadataNumericArray<PropertyArrayView<T>> {
153 static constexpr bool value = IsMetadataNumeric<T>::value;
154};
156template <typename T> struct IsMetadataNumericArray<PropertyArrayCopy<T>> {
158 static constexpr bool value = IsMetadataNumeric<T>::value;
159};
160
165template <typename... T> struct IsMetadataBooleanArray;
167template <typename T> struct IsMetadataBooleanArray<T> : std::false_type {};
169template <>
170struct IsMetadataBooleanArray<PropertyArrayView<bool>> : std::true_type {};
171
176template <typename... T> struct IsMetadataStringArray;
178template <typename T> struct IsMetadataStringArray<T> : std::false_type {};
180template <>
182 : std::true_type {};
183
187template <typename T> struct MetadataArrayType {
189 using type = void;
190};
192template <typename T>
198template <typename T>
203
207template <typename T> struct TypeToPropertyType;
208
209#pragma region Scalar Property Types
210
212template <> struct TypeToPropertyType<uint8_t> {
214 static constexpr PropertyComponentType component =
217 static constexpr PropertyType value = PropertyType::Scalar;
218};
219
221template <> struct TypeToPropertyType<int8_t> {
223 static constexpr PropertyComponentType component =
226 static constexpr PropertyType value = PropertyType::Scalar;
227};
228
230template <> struct TypeToPropertyType<uint16_t> {
232 static constexpr PropertyComponentType component =
235 static constexpr PropertyType value = PropertyType::Scalar;
236};
237
239template <> struct TypeToPropertyType<int16_t> {
241 static constexpr PropertyComponentType component =
244 static constexpr PropertyType value = PropertyType::Scalar;
245};
246
248template <> struct TypeToPropertyType<uint32_t> {
250 static constexpr PropertyComponentType component =
253 static constexpr PropertyType value = PropertyType::Scalar;
254};
255
257template <> struct TypeToPropertyType<int32_t> {
259 static constexpr PropertyComponentType component =
262 static constexpr PropertyType value = PropertyType::Scalar;
263};
264
266template <> struct TypeToPropertyType<uint64_t> {
268 static constexpr PropertyComponentType component =
271 static constexpr PropertyType value = PropertyType::Scalar;
272};
273
275template <> struct TypeToPropertyType<int64_t> {
277 static constexpr PropertyComponentType component =
280 static constexpr PropertyType value = PropertyType::Scalar;
281};
282
284template <> struct TypeToPropertyType<float> {
286 static constexpr PropertyComponentType component =
289 static constexpr PropertyType value = PropertyType::Scalar;
290};
291
293template <> struct TypeToPropertyType<double> {
295 static constexpr PropertyComponentType component =
298 static constexpr PropertyType value = PropertyType::Scalar;
299};
300#pragma endregion
301
302#pragma region Vector Property Types
303
305template <typename T, glm::qualifier P>
306struct TypeToPropertyType<glm::vec<2, T, P>> {
309 static constexpr PropertyComponentType component =
312 static constexpr PropertyType value = PropertyType::Vec2;
313};
314
316template <typename T, glm::qualifier P>
317struct TypeToPropertyType<glm::vec<3, T, P>> {
320 static constexpr PropertyComponentType component =
323 static constexpr PropertyType value = PropertyType::Vec3;
324};
325
327template <typename T, glm::qualifier P>
328struct TypeToPropertyType<glm::vec<4, T, P>> {
331 static constexpr PropertyComponentType component =
334 static constexpr PropertyType value = PropertyType::Vec4;
335};
336
337#pragma endregion
338
339#pragma region Matrix Property Types
340
342template <typename T, glm::qualifier P>
343struct TypeToPropertyType<glm::mat<2, 2, T, P>> {
346 static constexpr PropertyComponentType component =
349 static constexpr PropertyType value = PropertyType::Mat2;
350};
351
353template <typename T, glm::qualifier P>
354struct TypeToPropertyType<glm::mat<3, 3, T, P>> {
357 static constexpr PropertyComponentType component =
360 static constexpr PropertyType value = PropertyType::Mat3;
361};
362
364template <typename T, glm::qualifier P>
365struct TypeToPropertyType<glm::mat<4, 4, T, P>> {
368 static constexpr PropertyComponentType component =
371 static constexpr PropertyType value = PropertyType::Mat4;
372};
373
374#pragma endregion
375
377template <> struct TypeToPropertyType<bool> {
379 static constexpr PropertyComponentType component =
382 static constexpr PropertyType value = PropertyType::Boolean;
383};
384
386template <> struct TypeToPropertyType<std::string_view> {
389 static constexpr PropertyComponentType component =
392 static constexpr PropertyType value = PropertyType::String;
393};
394
398template <typename... T> struct CanBeNormalized;
400template <typename T> struct CanBeNormalized<T> : std::false_type {};
402template <> struct CanBeNormalized<uint8_t> : std::true_type {};
404template <> struct CanBeNormalized<int8_t> : std::true_type {};
406template <> struct CanBeNormalized<uint16_t> : std::true_type {};
408template <> struct CanBeNormalized<int16_t> : std::true_type {};
410template <> struct CanBeNormalized<uint32_t> : std::true_type {};
412template <> struct CanBeNormalized<int32_t> : std::true_type {};
414template <> struct CanBeNormalized<uint64_t> : std::true_type {};
416template <> struct CanBeNormalized<int64_t> : std::true_type {};
417
419template <glm::length_t n, typename T, glm::qualifier P>
420struct CanBeNormalized<glm::vec<n, T, P>> : CanBeNormalized<T> {};
421
423template <glm::length_t n, typename T, glm::qualifier P>
424struct CanBeNormalized<glm::mat<n, n, T, P>> : CanBeNormalized<T> {};
425
427template <typename T>
433template <typename T> struct TypeToNormalizedType;
434
436template <> struct TypeToNormalizedType<int8_t> {
438 using type = double;
439};
441template <> struct TypeToNormalizedType<uint8_t> {
443 using type = double;
444};
446template <> struct TypeToNormalizedType<int16_t> {
448 using type = double;
449};
451template <> struct TypeToNormalizedType<uint16_t> {
453 using type = double;
454};
456template <> struct TypeToNormalizedType<int32_t> {
458 using type = double;
459};
461template <> struct TypeToNormalizedType<uint32_t> {
463 using type = double;
464};
466template <> struct TypeToNormalizedType<int64_t> {
468 using type = double;
469};
471template <> struct TypeToNormalizedType<uint64_t> {
473 using type = double;
474};
475
477template <glm::length_t N, typename T, glm::qualifier Q>
478struct TypeToNormalizedType<glm::vec<N, T, Q>> {
480 using type = glm::vec<N, double, Q>;
481};
482
484template <glm::length_t N, typename T, glm::qualifier Q>
485struct TypeToNormalizedType<glm::mat<N, N, T, Q>> {
487 using type = glm::mat<N, N, double, Q>;
488};
489
497template <> struct TypeToNormalizedType<PropertyArrayView<uint8_t>> {
501};
503template <> struct TypeToNormalizedType<PropertyArrayView<int16_t>> {
507};
509template <> struct TypeToNormalizedType<PropertyArrayView<uint16_t>> {
513};
515template <> struct TypeToNormalizedType<PropertyArrayView<int32_t>> {
519};
521template <> struct TypeToNormalizedType<PropertyArrayView<uint32_t>> {
525};
527template <> struct TypeToNormalizedType<PropertyArrayView<int64_t>> {
531};
533template <> struct TypeToNormalizedType<PropertyArrayView<uint64_t>> {
537};
538
540template <glm::length_t N, typename T, glm::qualifier Q>
546
548template <glm::length_t N, typename T, glm::qualifier Q>
554
567template <typename T>
568using PropertyValueViewToCopy = std::conditional_t<
571 T>;
572
584template <typename T>
585using PropertyValueCopyToView = std::conditional_t<
588 T>;
589
599template <typename T>
600static std::optional<PropertyValueViewToCopy<T>>
601propertyValueViewToCopy(const std::optional<T>& view) {
602 if constexpr (IsMetadataNumericArray<T>::value) {
603 if (view) {
604 return std::make_optional<PropertyValueViewToCopy<T>>(
605 std::vector(view->begin(), view->end()));
606 } else {
607 return std::nullopt;
608 }
609 } else {
610 return view;
611 }
612}
613
622template <typename T>
623static PropertyValueViewToCopy<T> propertyValueViewToCopy(const T& view) {
624 if constexpr (IsMetadataNumericArray<T>::value) {
625 return PropertyValueViewToCopy<T>(std::vector(view.begin(), view.end()));
626 } else {
627 return view;
628 }
629}
630
639template <typename T>
640static PropertyValueCopyToView<T> propertyValueCopyToView(const T& copy) {
641 if constexpr (IsMetadataNumericArray<T>::value) {
642 return copy.view();
643 } else {
644 return copy;
645 }
646}
647
648} // 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.
PropertyComponentType
The possible types of a property component.
@ Float32
A property component equivalent to a float.
@ Uint32
A property component equivalent to a uint32_t.
@ Uint16
A property component equivalent to a uint16_t.
@ Int16
A property component equivalent to an int16_t.
@ Uint8
A property component equivalent to a uint8_t.
@ Int8
A property component equivalent to an int8_t.
@ Int32
A property component equivalent to an int32_t.
@ Uint64
A property component equivalent to a uint32_t.
@ Float64
A property component equivalent to a double.
@ Int64
A property component equivalent to an int64_t.
std::conditional_t< IsMetadataNumericArray< T >::value, PropertyArrayView< typename MetadataArrayType< T >::type >, T > PropertyValueCopyToView
Transforms a property value type from a copy that owns the data it is viewing to a view into that dat...
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....
PropertyType
The possible types of a property in a PropertyTableView.
@ Vec3
A vector with three components.
@ Scalar
A scalar property, i.e. an integer or floating point value.
@ Vec4
A vector with four components.
@ Vec2
A vector with two components.
STL namespace.
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.
void type
The component type of this metadata array.
glm::mat< N, N, double, Q > type
The representation of a glm::mat<N, N, T, Q> as a double type.
glm::vec< N, double, Q > type
The representation of a glm::vec<N, T, Q> as a double type.
double type
The representation of an int16_t as a double type.
double type
The representation of an int32_t as a double type.
double type
The representation of an int64_t as a double type.
double type
The representation of an int8_t as a double type.
double type
The representation of a uint16_t as a double type.
double type
The representation of a uint32_t as a double type.
double type
The representation of a uint64_t as a double type.
double type
The representation of a uint8_t as a double type.
Convert an integer numeric type to the corresponding representation as a double type....
Convert a C++ type to PropertyType and PropertyComponentType.