8 #ifndef PXR_BASE_VT_VALUE_TRANSFORM_H
9 #define PXR_BASE_VT_VALUE_TRANSFORM_H
35 Can(
VtValueRef obj, std::type_info
const &xfType);
39 Try(
VtValueRef x, std::type_info
const &xfType,
void const *xfObj,
56 return Vt_TransformImpl::Can(obj,
typeid(xfObj));
73 return Vt_TransformImpl
74 ::Try(obj,
typeid(xfObj),
75 static_cast<void const *>(std::addressof(xfObj)), erasedXf);
81 std::type_info
const &objType,
82 std::type_info
const &xfType,
86 template <
bool RegisterForArrays,
class T,
class Xf>
90 static_assert(!VtIsKnownValueType<T>(),
91 "Unexpected transform registration for one of the "
95 "Use VT_VALUE_TYPE_CAN_TRANSFORM or directly specialize "
96 "VtValueTypeCanTransform<> before registering transform "
99 using TypedFn =
T (*)(
T const &, Xf
const &);
100 using VoidFn =
void (*)();
102 VoidFn voidFn =
reinterpret_cast<VoidFn
>(fn);
104 typeid(
T),
typeid(Xf), voidFn,
105 [](
VtValueRef obj,
void const *xf,
void (*vFn)()) {
106 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
114 if constexpr (RegisterForArrays) {
118 [](
VtValueRef obj,
void const *xf,
void (*vFn)()) {
119 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
123 T const *srcPtr = src.cdata();
124 Xf
const &xform = *
static_cast<Xf
const *
>(xf);
125 xformed.resize(src.size(), [&](
T *
first,
T *
last) {
126 while (first !=
last) {
127 new (first++)
T { tFn(*srcPtr++, xform) };
136 [](
VtValueRef obj,
void const *xf,
void (*vFn)()) {
137 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
141 Xf
const &xform = *
static_cast<Xf
const *
>(xf);
142 for (
T &elem: xformed.GetMutableLiterals()) {
143 elem = tFn(elem, xform);
153 template <
class T,
class Xf>
164 template <
class T,
class Xf>
173 std::type_info
const &objType,
187 static_assert(!VtIsKnownValueType<T>(),
188 "Unexpected transform registration for one of the "
189 "known value types");
192 "Use VT_VALUE_TYPE_CAN_TRANSFORM or specialize "
193 "VtValueTypeCanTransform<> before registering transform "
196 using TypedFn = std::optional<T> (*)(
198 using VoidFn =
void (*)();
200 VoidFn voidFn =
reinterpret_cast<VoidFn
>(fn);
205 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
210 ret = std::move(*optT);
218 #endif // PXR_BASE_VT_VALUE_TRANSFORM_H
static VtValue Take(T &obj)
#define PXR_NAMESPACE_OPEN_SCOPE
bool CanTransform() const
constexpr auto in(type t, int set) -> bool
#define TF_DEV_AXIOM(cond)
bool IsEmpty() const
Returns true iff this value is empty.
__hostdev__ uint64_t last(uint32_t i) const
_TypeInfoFor< T >::GetObjResultType UncheckedGet() const
#define PXR_NAMESPACE_CLOSE_SCOPE