Loading...
Searching...
No Matches
typeHelpers.h
1//
2// Copyright 2024 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TS_TYPE_HELPERS_H
9#define PXR_BASE_TS_TYPE_HELPERS_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/api.h"
13#include "pxr/base/ts/types.h"
14#include "pxr/base/gf/half.h"
16#include "pxr/base/tf/type.h"
17
18#include <cmath>
19#include <type_traits>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23
24// Internal helper to avoid repeated lookups.
25//
26template <typename T>
27TfType Ts_GetType();
28
29// Compile-time type whose value is true only for supported value types.
30//
31template <typename T>
32struct Ts_IsSupportedValueType;
33
34// Default to false.
35template <typename T>
36struct Ts_IsSupportedValueType : public std::false_type {};
37
38// Specializations for supported value types.
39#define _MAKE_CLAUSE(unused, tuple) \
40 template <> \
41 TS_API TfType Ts_GetType<TS_SPLINE_VALUE_CPP_TYPE(tuple)>(); \
42 template <> \
43 struct Ts_IsSupportedValueType<TS_SPLINE_VALUE_CPP_TYPE(tuple)> : \
44 public std::true_type {};
45TF_PP_SEQ_FOR_EACH(_MAKE_CLAUSE, ~, TS_SPLINE_SUPPORTED_VALUE_TYPES)
46#undef _MAKE_CLAUSE
47
48// Mapping from Python type names to TfTypes for supported spline value types.
49// These strings align with type names used in downstream libraries; we can't
50// depend on them directly, so we replicate these few simple, stable type names
51// here.
52//
53TS_API
54TfType Ts_GetTypeFromTypeName(const std::string &typeName);
55
56// Opposite of the above.
57//
58TS_API
59std::string Ts_GetTypeNameFromType(TfType valueType);
60
61template <class T>
62using Ts_StorageType =
63 std::conditional_t<std::is_same_v<T, GfTimeCode>, double, T>;
64
65// GfHalf, GfTimeCode don't have an overload for std::isfinite, so we
66// provide adapters.
67//
68template <typename T>
69bool Ts_IsFinite(T value);
70
71template <>
72TS_API bool Ts_IsFinite(const GfHalf value);
73
74template <>
75TS_API bool Ts_IsFinite(const GfTimeCode value);
76
77template <typename T>
78bool Ts_IsFinite(const T value)
79{
80 return std::isfinite(value);
81}
82
83PXR_NAMESPACE_CLOSE_SCOPE
84
85#endif
Value type that represents a time code.
Definition timeCode.h:28
TfType represents a dynamic runtime type.
Definition type.h:48
This header serves to simply bring in the half float datatype and provide a hash_value function.
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition half.h:26