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"
15#include "pxr/base/tf/type.h"
16
17#include <cmath>
18#include <type_traits>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22
23// Internal helper to avoid repeated lookups.
24//
25template <typename T>
26TfType Ts_GetType();
27
28// Compile-time type whose value is true only for supported value types.
29//
30template <typename T>
31struct Ts_IsSupportedValueType;
32
33// Default to false.
34template <typename T>
35struct 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 {};
44TF_PP_SEQ_FOR_EACH(_MAKE_CLAUSE, ~, TS_SPLINE_SUPPORTED_VALUE_TYPES)
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//
52TS_API
53TfType Ts_GetTypeFromTypeName(const std::string &typeName);
54
55// Opposite of the above.
56//
57TS_API
58std::string Ts_GetTypeNameFromType(TfType valueType);
59
60
61// GfHalf doesn't have an overload for std::isfinite, so we provide an adapter.
62//
63template <typename T>
64bool Ts_IsFinite(T value);
65
66template <>
67TS_API bool Ts_IsFinite(const GfHalf value);
68
69template <typename T>
70bool Ts_IsFinite(const T value)
71{
72 return std::isfinite(value);
73}
74
75PXR_NAMESPACE_CLOSE_SCOPE
76
77#endif
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