7 #ifndef PXR_BASE_VT_VALUEREF_H
8 #define PXR_BASE_VT_VALUEREF_H
37 #include <type_traits>
87 using _StreamOutFunc = std::ostream & (*)(
_RefdObjPtr, std::ostream &);
89 using _GetNumElementsFunc = size_t (*)(
_RefdObjPtr);
93 const std::type_info &elementTi,
100 _CanHashFunc canHash,
103 _GetPyObjFunc getPyObj,
104 _GetVtValueFunc getVtValue,
105 _StreamOutFunc streamOut,
106 _IsArrayValuedFunc isArrayValued,
107 _GetNumElementsFunc getNumElements)
110 , knownTypeIndex(knownTypeIndex)
112 , isHashable(isHashable)
113 , canComposeOver(canComposeOver)
114 , canTransform(canTransform)
115 , isMutable(isMutable)
120 , _getPyObj(getPyObj)
121 , _getVtValue(getVtValue)
122 , _streamOut(streamOut)
123 , _isArrayValued(isArrayValued)
124 , _getNumElements(getNumElements)
129 return _canHash(storage);
132 return _hash(storage);
135 return _equal(lhs, rhs);
138 return _getPyObj(storage);
143 std::ostream &out)
const {
144 return _streamOut(storage, out);
147 return _isArrayValued(storage);
150 return _getNumElements(storage);
163 _CanHashFunc _canHash;
166 _GetPyObjFunc _getPyObj;
167 _GetVtValueFunc _getVtValue;
168 _StreamOutFunc _streamOut;
169 _IsArrayValuedFunc _isArrayValued;
170 _GetNumElementsFunc _getNumElements;
187 template <
class Array>
194 return typeid(
typename Array::ElementType);
199 template <
class ArrayEdit>
203 return typeid(
typename ArrayEdit::ElementType);
214 _IsArrayEditHelper<T>, _NonArrayHelper<T>>
218 template <
class T,
bool IsMutable>
224 static constexpr
bool IsPointer = std::is_pointer_v<Type>;
226 IsPointer && std::is_function_v<std::remove_pointer_t<Type>>;
230 const std::remove_pointer_t<Type> *,
261 &
This::_IsArrayValued,
262 &
This::_GetNumElements)
289 return reinterpret_cast<
293 return *
static_cast<Type *
>(
const_cast<void *
>(storage.
objPtr));
299 storage.
fnPtr =
reinterpret_cast<void (*)()
>(obj);
302 storage.
objPtr =
static_cast<void const *
>(obj);
305 storage.
objPtr =
static_cast<void const *
>(std::addressof(obj));
311 return VtIsHashable<T>();
314 static size_t _Hash(_RefdObjPtr
ptr) {
318 static bool _Equal(_RefdObjPtr lhs, _RefdObjPtr rhs) {
323 #ifdef PXR_PYTHON_SUPPORT_ENABLED
332 static VtValue _GetVtValue(_RefdObjPtr storage);
334 static std::ostream &_StreamOut(
335 _RefdObjPtr storage, std::ostream &out) {
339 static bool _IsArrayValued(_RefdObjPtr storage) {
343 static std::type_info
const &
344 _GetElementTypeid(_RefdObjPtr ptr) {
345 return _ArrayHelper<T>::GetElementTypeid();
348 static size_t _GetNumElements(_RefdObjPtr ptr) {
349 return _ArrayHelper<T>::GetNumElements(
GetObj(ptr));
361 std::is_reference_v<T> && std::is_const_v<T>>;
375 !std::is_same_v<std::decay_t<T>,
VtValueRef> &&
376 !std::is_same_v<std::decay_t<T>,
VtValue>> * = 0) {
380 "VtValueRef does not support proxies");
381 static const TypeInfo ti;
382 ti.SetObj(obj,
_ptr);
383 _info = std::addressof(ti);
404 return _info && _TypeIs<T>();
451 typename _TypeInfoFor<T>::GetObjResultType
463 typename _TypeInfoFor<T>::GetObjResultType
470 return *(
static_cast<T const *
>(
483 return IsHolding<T>() ? UncheckedGet<T>() : def;
493 if (IsHolding<T>()) {
494 return UncheckedRemove<T>();
509 return std::move(_GetMutable<T>());
551 if (empty || rhsEmpty) {
553 return empty == rhsEmpty;
564 VT_API friend std::ostream &
577 std::type_info
const &
t =
typeid(
T);
583 typename _TypeInfoFor<T>::GetMutableObjResultType
586 return TypeInfo::GetMutableObj(
_ptr);
590 typename _TypeInfoFor<T>::GetObjResultType
593 return TypeInfo::GetObj(
_ptr);
600 std::type_info
const &queryType)
const;
626 VtValueRef::Get<VtValueRef>()
const {
632 VtValueRef::UncheckedGet<VtValueRef>()
const {
638 VtValueRef::IsHolding<VtValueRef>()
const {
645 VtValueRef::IsHolding<void>()
const {
674 "Can only assign to VtMutableValueRef with a type T "
676 if (IsHolding<T>()) {
677 _GetMutable<T>() = std::forward<T>(obj);
680 _FailAssign(
typeid(
T));
688 "Can only assign to VtMutableValueRef with a type T "
690 _GetMutable<T>() = std::forward<T>(obj);
702 "Can only VtValueRef::Swap with a type T "
704 if (IsHolding<T>()) {
708 _FailSwap(
typeid(
T));
720 "Can only VtValueRef::Swap with a type T "
723 swap(_GetMutable<T>(), rhs);
729 template <
class T,
class Fn>
733 "Can only VtValueRef::Mutate a type T that stores as T");
734 if (!IsHolding<T>()) {
737 UncheckedMutate<T>(std::forward<Fn>(mutateFn));
744 template <
class T,
class Fn>
748 "Can only VtValueRef::Mutate a type T that stores as T");
752 T &stored = _GetMutable<T>();
753 T tmp = std::move(stored);
754 std::forward<Fn>(mutateFn)(tmp);
755 stored = std::move(tmp);
759 VT_API void _FailAssign(std::type_info
const &);
760 VT_API void _FailSwap(std::type_info
const &);
781 return _getVtValue(storage);
784 template <
class T,
bool B>
787 return VtValue { GetObj(storage) };
792 #ifdef PXR_PYTHON_SUPPORT_ENABLED
794 #include "pxr/external/boost/python/converter/arg_from_python.hpp"
797 namespace PXR_BOOST_NAMESPACE::python::converter {
808 :
public arg_rvalue_from_python<PXR_NS::VtValue>
810 using base_type = arg_rvalue_from_python<PXR_NS::VtValue>;
811 using base_type::convertible;
812 using result_type = PXR_NS::VtValueRef &;
814 VT_API arg_rvalue_from_python(PyObject* obj);
816 VT_API result_type operator()();
818 std::optional<PXR_NS::VtValueRef> optValueRef;
823 #endif // PXR_PYTHON_SUPPORT_ENABLED
825 #endif // PXR_BASE_VT_VALUEREF_H
bool Equal(_RefdObjPtr lhs, _RefdObjPtr rhs) const
VtMutableValueRef & UncheckedAssign(T &&obj)
static constexpr std::type_info const & GetElementTypeid()
bool operator==(const VtValueRef &rhs) const
Test two values for equality.
friend void swap(VtValueRef &lhs, VtValueRef &rhs)
Overloaded swap() for generic code/stl/etc. Swaps the viewed objects.
friend size_t hash_value(VtValueRef const &val)
typename std::enable_if< B, T >::type enable_if_t
Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
bool Mutate(Fn &&mutateFn)
VtValueRef(T &&obj, std::enable_if_t< !std::is_same_v< std::decay_t< T >, VtValueRef > &&!std::is_same_v< std::decay_t< T >, VtValue >> *=0)
VtMutableValueRef(T &obj)
friend TfPyObjWrapper Vt_GetPythonObjectFromHeldValue(VtValueRef const &self)
getFileOption("OpenEXR:storage") storage
static constexpr std::type_info const & GetElementTypeid()
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
typename std::conditional< B, T, F >::type conditional_t
TfPyObjWrapper GetPyObj(_RefdObjPtr storage) const
std::ostream & StreamOut(_RefdObjPtr storage, std::ostream &out) const
#define PXR_NAMESPACE_OPEN_SCOPE
GLsizei const GLfloat * value
static void SetObj(T const &obj, _RefdObjPtr &storage)
VT_API size_t _GetNumElements() const
static size_t GetNumElements(Array const &obj)
static constexpr bool IsPointer
void UncheckedSwap(T &rhs)
const std::type_info & typeInfo
bool CanTransform() const
VT_API bool IsArrayValued() const
Return true if this views a VtArray instance, false otherwise.
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
VT_API bool CanHash() const
Return true if the viewed object provides a hash implementation.
VT_API void _FailRemove(std::type_info const &)
VtValue GetVtValue(_RefdObjPtr storage) const
_TypeInfoFor< T >::GetObjResultType _Get() const
VT_API size_t GetHash() const
Return a hash code for the viewed object by calling VtHashValue() on it.
VtValueRef & operator=(VtValueRef const &ref)=default
Rebind to view the same object as another VtValueRef.
VT_API std::ostream & VtStreamOut(std::vector< VtValueRef > const &val, std::ostream &)
VT_API bool IsArrayEditValued() const
Return true if this views a VtArrayEdit instance, false otherwise.
VT_API void const * _FailGet(Vt_DefaultValueHolder(*factory)(), std::type_info const &queryType) const
_TypeInfoFor< T >::GetObjResultType Get() const
bool CanComposeOver() const
std::conditional_t< IsPointer, const std::remove_pointer_t< Type > *, const Type > ConstType
std::type_info const & GetTypeid() const
Return the typeid of the type viewed by this value.
size_t GetNumElements(_RefdObjPtr storage) const
bool IsEmpty() const
Returns true iff this value is empty.
VT_API TfType GetType() const
Returns the TfType of the type viewed by this value.
static constexpr bool IsFunctionPointer
constexpr _TypeInfo(const std::type_info &ti, const std::type_info &elementTi, int knownTypeIndex, bool isArray, bool isHashable, bool canComposeOver, bool canTransform, bool isMutable, _CanHashFunc canHash, _HashFunc hash, _EqualFunc equal, _GetPyObjFunc getPyObj, _GetVtValueFunc getVtValue, _StreamOutFunc streamOut, _IsArrayValuedFunc isArrayValued, _GetNumElementsFunc getNumElements)
VT_API TfPyObjWrapper _GetPythonObject() const
std::conditional_t< IsPointer, Type, Type & > GetMutableObjResultType
constexpr bool VtIsHashable()
size_t Hash(_RefdObjPtr storage) const
int GetKnownValueTypeIndex() const
void UncheckedMutate(Fn &&mutateFn)
VtMutableValueRef & operator=(T &&obj)
Assign to the viewed value.
T GetWithDefault(T const &def=T()) const
VT_API std::string GetTypeName() const
Return the type name of the viewed typeid.
A trait to detect instantiations of VtArray, specialized in array.h.
bool IsArrayValued(_RefdObjPtr storage) const
_TypeInfoFor< T >::GetObjResultType UncheckedGet() const
VtValueRef()
Default ctor gives empty VtValueRef.
_TypeInfoFor< T >::GetMutableObjResultType _GetMutable()
constexpr _TypeInfoImpl()
bool CanHash(_RefdObjPtr storage) const
size_t VtHashValue(T const &val)
VT_API friend std::ostream & operator<<(std::ostream &out, const VtValueRef &self)
Calls through to operator << on the viewed object.
static size_t GetNumElements(U &&)
#define PXR_NAMESPACE_CLOSE_SCOPE
std::type_info const & GetElementTypeid() const
static GetObjResultType GetObj(_RefdObjPtr const &storage)
VtMutableValueRef()=default
Default ctor gives empty VtMutableValueRef.
static GetMutableObjResultType GetMutableObj(_RefdObjPtr &storage)
static constexpr std::type_info const & GetElementTypeid()
std::conditional_t< IsPointer, ConstType, ConstType & > GetObjResultType
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
TfConditionalType< VtIsArray< T >::value, _IsArrayHelper< T >, TfConditionalType< VtIsArrayEdit< T >::value, _IsArrayEditHelper< T >, _NonArrayHelper< T >> > _ArrayHelper
const bool canComposeOver
_TypeInfoImpl< std::decay_t< T >, std::is_reference_v< T > &&std::is_const_v< T >> _TypeInfoFor
const std::type_info & elementTypeInfo
size_t GetArraySize() const
bool operator!=(const VtValueRef &rhs) const