HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
typeHelpers.h
Go to the documentation of this file.
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"
15 #include "pxr/base/tf/type.h"
16 
17 #include <cmath>
18 #include <type_traits>
19 
21 
22 
23 // Internal helper to avoid repeated lookups.
24 //
25 template <typename T>
27 
28 // Compile-time type whose value is true only for supported value types.
29 //
30 template <typename T>
32 
33 // Default to false.
34 template <typename T>
35 struct Ts_IsSupportedValueType : public std::false_type {};
36 
37 // Specializations for supported value types.
38 #define _MAKE_CLAUSE(unused, tuple) \
39  template <> \
40  TS_API TfType Ts_GetType<TS_SPLINE_VALUE_CPP_TYPE(tuple)>(); \
41  template <> \
42  struct Ts_IsSupportedValueType<TS_SPLINE_VALUE_CPP_TYPE(tuple)> : \
43  public std::true_type {};
45 #undef _MAKE_CLAUSE
46 
47 // Mapping from Python type names to TfTypes for supported spline value types.
48 // These strings align with type names used in downstream libraries; we can't
49 // depend on them directly, so we replicate these few simple, stable type names
50 // here.
51 //
52 TS_API
53 TfType Ts_GetTypeFromTypeName(const std::string &typeName);
54 
55 // Opposite of the above.
56 //
57 TS_API
58 std::string Ts_GetTypeNameFromType(TfType valueType);
59 
60 
61 // GfHalf doesn't have an overload for std::isfinite, so we provide an adapter.
62 //
63 template <typename T>
64 bool Ts_IsFinite(T value);
65 
66 template <>
67 TS_API bool Ts_IsFinite(const GfHalf value);
68 
69 template <typename T>
70 bool Ts_IsFinite(const T value)
71 {
72  return std::isfinite(value);
73 }
74 
76 
77 #endif
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define TS_API
Definition: api.h:24
bool Ts_IsFinite(T value)
Definition: typeHelpers.h:70
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
TS_API TfType Ts_GetTypeFromTypeName(const std::string &typeName)
#define TF_PP_SEQ_FOR_EACH(_macro, data, seq)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PXR_NAMESPACE_OPEN_SCOPE TfType Ts_GetType()
#define _MAKE_CLAUSE(unused, tuple)
Definition: typeHelpers.h:38
Definition: type.h:47
#define TS_SPLINE_SUPPORTED_VALUE_TYPES
Definition: types.h:29
TS_API std::string Ts_GetTypeNameFromType(TfType valueType)