8#ifndef PXR_BASE_VT_VALUE_TRANSFORM_H
9#define PXR_BASE_VT_VALUE_TRANSFORM_H
15#include "pxr/base/vt/value.h"
16#include "pxr/base/vt/valueRef.h"
20PXR_NAMESPACE_OPEN_SCOPE
27 VtValueCanTransform(
VtValueRef obj, Xf
const &xfObj);
31 VtValueTryTransform(
VtValueRef obj, Xf
const &xfObj);
35 Can(
VtValueRef obj, std::type_info
const &xfType);
39 Try(
VtValueRef x, std::type_info
const &xfType,
void const *xfObj,
51VtValueCanTransform(
VtValueRef obj, Xf
const &xfObj)
56 return Vt_TransformImpl::Can(obj,
typeid(xfObj));
64VtValueTryTransform(
VtValueRef obj, Xf
const &xfObj)
71 return VtValueTryTransform(in, xfObj);
73 return Vt_TransformImpl
74 ::Try(obj,
typeid(xfObj),
75 static_cast<void const *
>(std::addressof(xfObj)), erasedXf);
80Vt_RegisterTypedTransform(
81 std::type_info
const &objType,
82 std::type_info
const &xfType,
86template <
bool RegisterForArrays,
class T,
class Xf>
88Vt_RegisterTransformImpl(T (*fn)(T
const &obj, Xf
const &xform))
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);
103 Vt_RegisterTypedTransform(
104 typeid(T),
typeid(Xf), voidFn,
105 [](
VtValueRef obj,
void const *xf,
void (*vFn)()) {
106 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
109 tFn(obj.
UncheckedGet<T>(), *
static_cast<Xf
const *
>(xf))
114 if constexpr (RegisterForArrays) {
116 Vt_RegisterTypedTransform(
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) };
134 Vt_RegisterTypedTransform(
136 [](
VtValueRef obj,
void const *xf,
void (*vFn)()) {
137 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
141 Xf
const &xform = *
static_cast<Xf
const *
>(xf);
143 elem = tFn(elem, xform);
153template <
class T,
class Xf>
155VtRegisterTransformNoArrays(T (*fn)(T
const &obj, Xf
const &xform))
157 Vt_RegisterTransformImpl<
false>(fn);
164template <
class T,
class Xf>
166VtRegisterTransform(T (*fn)(T
const &obj, Xf
const &xform))
168 Vt_RegisterTransformImpl<
true>(fn);
172Vt_RegisterErasedTransform(
173 std::type_info
const &objType,
184VtRegisterErasedTransform(
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);
201 Vt_RegisterErasedTransform(
205 TypedFn tFn =
reinterpret_cast<TypedFn
>(vFn);
207 std::optional<T> optT = tFn(obj.
UncheckedGet<T>(), xform);
210 ret = std::move(*optT);
216PXR_NAMESPACE_CLOSE_SCOPE
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
This class provides a non-owning reference to a type-erased callable object with a specified signatur...
An array edit represents a sequence of per-element modifications to a VtArray.
TfSpan< ElementType > GetMutableLiterals()
Return a mutable view of the literal elements that this edit makes use of.
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
static VtValue Take(T &obj)
Create a new VtValue, taking its contents from obj.
A non-owning type-erased view of a value, interoperating with VtValue.
bool IsEmpty() const
Returns true iff this value is empty.
bool CanTransform() const
Return true if this value holds a type that has been declared to support value transforms at compile ...
_TypeInfoFor< T >::GetObjResultType UncheckedGet() const
Return a const reference to the viewed object if the viewed object is of type T.
bool IsHolding() const
Return true if this value is viewing an object of type T, false otherwise.
const_pointer cdata() const
Return a const pointer to the data held by this array.
size_t size() const
Return the total number of elements in this array.
void resize(size_t newSize)
Resize this array.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.