29 #ifdef PXR_PYTHON_SUPPORT_ENABLED
32 #include "pxr/base/tf/pyObjWrapper.h"
33 #endif // PXR_PYTHON_SUPPORT_ENABLED
35 #include "pxr/base/tf/pyLock.h"
37 #include "pxr/base/arch/demangle.h"
38 #include "pxr/base/arch/hints.h"
39 #include "pxr/base/tf/anyUniquePtr.h"
40 #include "pxr/base/tf/pointerAndBits.h"
41 #include "pxr/base/tf/safeTypeCompare.h"
42 #include "pxr/base/tf/stringUtils.h"
43 #include "pxr/base/tf/tf.h"
44 #include "pxr/base/tf/type.h"
46 #include "pxr/base/vt/api.h"
47 #include "pxr/base/vt/hash.h"
48 #include "pxr/base/vt/streamOut.h"
49 #include "pxr/base/vt/traits.h"
50 #include "pxr/base/vt/types.h"
52 #include <boost/aligned_storage.hpp>
53 #include <boost/intrusive_ptr.hpp>
54 #include <boost/mpl/and.hpp>
55 #include <boost/mpl/if.hpp>
56 #include <boost/type_traits/decay.hpp>
57 #include <boost/type_traits/has_trivial_assign.hpp>
58 #include <boost/type_traits/has_trivial_constructor.hpp>
59 #include <boost/type_traits/has_trivial_copy.hpp>
60 #include <boost/type_traits/has_trivial_destructor.hpp>
61 #include <boost/type_traits/is_same.hpp>
62 #include <boost/utility/enable_if.hpp>
66 #include <type_traits>
68 PXR_NAMESPACE_OPEN_SCOPE
74 struct Vt_DefaultValueFactory;
78 struct Vt_DefaultValueHolder
83 static Vt_DefaultValueHolder Create() {
84 return Vt_DefaultValueHolder(TfAnyUniquePtr::New<T>(),
typeid(T));
90 static Vt_DefaultValueHolder Create(T
const &val) {
91 return Vt_DefaultValueHolder(TfAnyUniquePtr::New(val),
typeid(T));
95 std::type_info
const &GetType()
const {
101 void const *GetPointer()
const {
106 Vt_DefaultValueHolder(
TfAnyUniquePtr &&ptr, std::type_info
const &type)
107 : _ptr(std::move(ptr)), _type(&type) {}
110 std::type_info
const *_type;
117 VT_API std::ostream &VtStreamOut(std::vector<VtValue>
const &val, std::ostream &);
121 bool VtProxyHoldsType(T
const &, std::type_info
const &) {
return false; }
125 VtValue const *VtGetProxiedValue(T
const &) {
return NULL; }
127 #define VT_VALUE_SET_STORED_TYPE(SRC, DST) \
128 template <> struct Vt_ValueStoredType<SRC> { typedef DST Type; }
130 template <
class T>
struct Vt_ValueStoredType {
typedef T Type; };
131 VT_VALUE_SET_STORED_TYPE(
char const *, std::string);
132 VT_VALUE_SET_STORED_TYPE(
char *, std::string);
134 #ifdef PXR_PYTHON_SUPPORT_ENABLED
136 #endif // PXR_PYTHON_SUPPORT_ENABLED
138 #undef VT_VALUE_SET_STORED_TYPE
142 struct Vt_ValueGetStored
143 : Vt_ValueStoredType<typename boost::decay<T>::type> {};
184 static const unsigned int _LocalFlag = 1 << 0;
185 static const unsigned int _TrivialCopyFlag = 1 << 1;
186 static const unsigned int _ProxyFlag = 1 << 2;
190 explicit _Counted(T
const &obj) : _obj(obj) {
193 bool IsUnique()
const {
return _refCount == 1; }
194 T
const &
Get()
const {
return _obj; }
195 T &GetMutable() {
return _obj; }
199 mutable std::atomic<int> _refCount;
201 friend inline void intrusive_ptr_add_ref(_Counted
const *d) {
202 d->_refCount.fetch_add(1, std::memory_order_relaxed);
204 friend inline void intrusive_ptr_release(_Counted
const *d) {
205 if (d->_refCount.fetch_sub(1, std::memory_order_release) == 1) {
206 std::atomic_thread_fence(std::memory_order_acquire);
215 static const size_t _MaxLocalSize =
sizeof(
void*);
216 typedef std::aligned_storage<
217 _MaxLocalSize, _MaxLocalSize>::type _Storage;
220 struct _IsTriviallyCopyable : boost::mpl::and_<
221 boost::has_trivial_constructor<T>,
222 boost::has_trivial_copy<T>,
223 boost::has_trivial_assign<T>,
224 boost::has_trivial_destructor<T> > {};
229 struct _UsesLocalStore : boost::mpl::bool_<
230 (sizeof(T) <= sizeof(_Storage)) &&
231 VtValueTypeHasCheapCopy<T>::value &&
232 std::is_nothrow_move_constructible<T>::value &&
233 std::is_nothrow_move_assignable<T>::value> {};
238 using _CopyInitFunc = void (*)(_Storage const &, _Storage &);
239 using _DestroyFunc = void (*)(_Storage &);
240 using _MoveFunc = void (*)(_Storage &, _Storage &);
241 using _HashFunc = size_t (*)(_Storage const &);
242 using _EqualFunc = bool (*)(_Storage const &, _Storage const &);
243 using _MakeMutableFunc = void (*)(_Storage &);
244 #ifdef PXR_PYTHON_SUPPORT_ENABLED
245 using _GetPyObjFunc = TfPyObjWrapper (*)(_Storage const &);
247 using _StreamOutFunc = std::ostream & (*)(_Storage const &, std::ostream &);
248 using _GetShapeDataFunc = const Vt_ShapeData* (*)(_Storage const &);
249 using _GetNumElementsFunc = size_t (*)(_Storage const &);
250 using _ProxyHoldsTypeFunc = bool (*)(_Storage const &, std::type_info const &);
251 using _GetProxiedTypeFunc = TfType (*)(_Storage const &);
252 using _GetProxiedValueFunc = VtValue const *(*)(_Storage const &);
255 constexpr _TypeInfo(const std::type_info &ti,
256 const std::type_info &elementTi,
259 _CopyInitFunc copyInit,
260 _DestroyFunc destroy,
264 _MakeMutableFunc makeMutable,
265 #ifdef PXR_PYTHON_SUPPORT_ENABLED
266 _GetPyObjFunc getPyObj,
268 _StreamOutFunc streamOut,
269 _GetShapeDataFunc getShapeData,
270 _GetNumElementsFunc getNumElements,
271 _ProxyHoldsTypeFunc proxyHoldsType,
272 _GetProxiedTypeFunc getProxiedType,
273 _GetProxiedValueFunc getProxiedValue)
275 , elementTypeInfo(elementTi)
277 , isHashable(isHashable)
279 , _copyInit(copyInit)
284 , _makeMutable(makeMutable)
285 #ifdef PXR_PYTHON_SUPPORT_ENABLED
286 , _getPyObj(getPyObj)
288 , _streamOut(streamOut)
289 , _getShapeData(getShapeData)
290 , _getNumElements(getNumElements)
291 , _proxyHoldsType(proxyHoldsType)
292 , _getProxiedType(getProxiedType)
293 , _getProxiedValue(getProxiedValue)
297 void CopyInit(_Storage const &src, _Storage &dst) const {
300 void Destroy(_Storage &storage) const {
303 void Move(_Storage &src, _Storage &dst) const noexcept {
306 size_t Hash(_Storage const &storage) const {
307 return _hash(storage);
309 bool Equal(_Storage const &lhs, _Storage const &rhs) const {
310 return _equal(lhs, rhs);
312 void MakeMutable(_Storage &storage) const {
313 _makeMutable(storage);
315 #ifdef PXR_PYTHON_SUPPORT_ENABLED
316 TfPyObjWrapper GetPyObj(_Storage const &storage) const {
317 return _getPyObj(storage);
320 std::ostream & StreamOut(_Storage const &storage,
321 std::ostream &out) const {
322 return _streamOut(storage, out);
324 const Vt_ShapeData* GetShapeData(_Storage const &storage) const {
325 return _getShapeData(storage);
327 size_t GetNumElements(_Storage const &storage) const {
328 return _getNumElements(storage);
330 bool ProxyHoldsType(_Storage const &storage,
331 std::type_info const &t) const {
332 return _proxyHoldsType(storage, t);
334 TfType GetProxiedType(_Storage const &storage) const {
335 return _getProxiedType(storage);
337 VtValue const *GetProxiedValue(_Storage const &storage) const {
338 return _getProxiedValue(storage);
341 const std::type_info &typeInfo;
342 const std::type_info &elementTypeInfo;
347 _CopyInitFunc _copyInit;
348 _DestroyFunc _destroy;
352 _MakeMutableFunc _makeMutable;
353 #ifdef PXR_PYTHON_SUPPORT_ENABLED
354 _GetPyObjFunc _getPyObj;
356 _StreamOutFunc _streamOut;
357 _GetShapeDataFunc _getShapeData;
358 _GetNumElementsFunc _getNumElements;
359 _ProxyHoldsTypeFunc _proxyHoldsType;
360 _GetProxiedTypeFunc _getProxiedType;
361 _GetProxiedValueFunc _getProxiedValue;
367 template <class T, class Enable=void>
368 struct _ArrayHelper {
369 static const Vt_ShapeData* GetShapeData(T const &) { return NULL; }
370 static size_t GetNumElements(T const &) { return 0; }
371 constexpr static std::type_info const &GetElementTypeid() { return typeid(void); }
373 template <class Array>
374 struct _ArrayHelper<Array,
375 typename boost::enable_if<VtIsArray<Array> >::type> {
376 static const Vt_ShapeData* GetShapeData(Array const &obj) {
377 return obj._GetShapeData();
379 static size_t GetNumElements(Array const &obj) {
382 constexpr static std::type_info const &GetElementTypeid() {
383 return typeid(typename Array::ElementType);
390 template <class T, class Container, class Derived>
391 struct _TypeInfoImpl : public _TypeInfo
393 static const bool IsLocal = _UsesLocalStore<T>::value;
394 static const bool HasTrivialCopy = _IsTriviallyCopyable<T>::value;
395 static const bool IsProxy = VtIsValueProxy<T>::value;
397 using This = _TypeInfoImpl;
399 constexpr _TypeInfoImpl()
400 : _TypeInfo(typeid(T),
401 _ArrayHelper<T>::GetElementTypeid(),
410 #ifdef PXR_PYTHON_SUPPORT_ENABLED
414 &This::_GetShapeData,
415 &This::_GetNumElements,
416 &This::_ProxyHoldsType,
417 &This::_GetProxiedType,
418 &This::_GetProxiedValue)
423 static T const &GetObj(_Storage const &storage) {
424 return Derived::_GetObj(_Container(storage));
427 static T &GetMutableObj(_Storage &storage) {
428 return Derived::_GetMutableObj(_Container(storage));
431 static void CopyInitObj(T const &objSrc, _Storage &dst) {
432 Derived::_PlaceCopy(&_Container(dst), objSrc);
436 static_assert(sizeof(Container) <= sizeof(_Storage),
437 "Container size cannot exceed storage size.");
441 static void _CopyInit(_Storage const &src, _Storage &dst) {
442 new (&_Container(dst)) Container(_Container(src));
445 static void _Destroy(_Storage &storage) {
446 _Container(storage).~Container();
449 static size_t _Hash(_Storage const &storage) {
450 return VtHashValue(GetObj(storage));
453 static bool _Equal(_Storage const &lhs, _Storage const &rhs) {
457 return GetObj(lhs) == GetObj(rhs);
460 static void _Move(_Storage &src, _Storage &dst) noexcept {
461 new (&_Container(dst)) Container(std::move(_Container(src)));
465 static void _MakeMutable(_Storage &storage) {
466 GetMutableObj(storage);
469 #ifdef PXR_PYTHON_SUPPORT_ENABLED
470 static TfPyObjWrapper _GetPyObj(_Storage const &storage) {
472 return boost::python::api::object(GetObj(storage));
476 static std::ostream &_StreamOut(
477 _Storage const &storage, std::ostream &out) {
478 return VtStreamOut(GetObj(storage), out);
481 static const Vt_ShapeData* _GetShapeData(_Storage const &storage) {
482 return _ArrayHelper<T>::GetShapeData(GetObj(storage));
485 static size_t _GetNumElements(_Storage const &storage) {
486 return _ArrayHelper<T>::GetNumElements(GetObj(storage));
490 _ProxyHoldsType(_Storage const &storage, std::type_info const &t) {
491 return VtProxyHoldsType(GetObj(storage), t);
495 _GetProxiedType(_Storage const &storage) {
496 return VtGetProxiedType(GetObj(storage));
499 static VtValue const *
500 _GetProxiedValue(_Storage const &storage) {
501 return VtGetProxiedValue(GetObj(storage));
507 static Container &_Container(_Storage &storage) {
508 return *((Container *)&storage);
510 static Container const &_Container(_Storage const &storage) {
511 return *((Container const *)&storage);
519 struct _LocalTypeInfo : _TypeInfoImpl<
525 constexpr _LocalTypeInfo()
526 : _TypeInfoImpl<T, T, _LocalTypeInfo<T>>()
530 static T &_GetMutableObj(T &obj) { return obj; }
531 static T const &_GetObj(T const &obj) { return obj; }
533 static void _PlaceCopy(T *dst, T const &src) { new (dst) T(src); }
540 struct _RemoteTypeInfo : _TypeInfoImpl<
542 boost::intrusive_ptr<_Counted<T> >,
546 constexpr _RemoteTypeInfo()
548 T, boost::intrusive_ptr<_Counted<T>>, _RemoteTypeInfo<T>>()
551 typedef boost::intrusive_ptr<_Counted<T> > Ptr;
553 static T &_GetMutableObj(Ptr &ptr) {
554 if (!ptr->IsUnique())
555 ptr.reset(new _Counted<T>(ptr->Get()));
556 return ptr->GetMutable();
558 static T const &_GetObj(Ptr const &ptr) {
return ptr->Get(); }
560 static void _PlaceCopy(Ptr *dst, T
const &src) {
561 new (dst) Ptr(
new _Counted<T>(src));
567 struct _TypeInfoFor {
569 typedef typename boost::mpl::if_<_UsesLocalStore<T>,
571 _RemoteTypeInfo<T> >::type Type;
576 struct _TypeInfoFor<char[N]> {
578 typedef typename boost::mpl::if_<_UsesLocalStore<std::string>,
579 _LocalTypeInfo<std::string>,
580 _RemoteTypeInfo<std::string> >::type Type;
587 typedef typename _TypeInfoFor<T>::Type TI;
589 static constexpr
unsigned int flags =
590 (TI::IsLocal ? _LocalFlag : 0) |
591 (TI::HasTrivialCopy ? _TrivialCopyFlag : 0) |
592 (TI::IsProxy ? _ProxyFlag : 0);
602 friend struct _HoldAside;
604 explicit _HoldAside(
VtValue *val)
605 : info((val->IsEmpty() || val->_IsLocalAndTriviallyCopyable())
606 ? static_cast<_TypeInfo const *>(NULL) : val->_info.Get()) {
608 info->Move(val->_storage, storage);
612 info->Destroy(storage);
615 _TypeInfo
const *info;
619 typename boost::enable_if<
620 boost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type
621 _Init(T
const &obj) {
622 _info = GetTypeInfo<T>();
623 typedef typename _TypeInfoFor<T>::Type TypeInfo;
624 TypeInfo::CopyInitObj(obj, _storage);
628 typename boost::disable_if<
629 boost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type
630 _Init(T
const &obj) {
631 _Init(
typename Vt_ValueGetStored<T>::Type(obj));
690 if (ARCH_LIKELY(
this != &other))
697 if (ARCH_LIKELY(
this != &other))
705 typename boost::enable_if_c<
706 _TypeInfoFor<T>::Type::IsLocal &&
707 _TypeInfoFor<T>::Type::HasTrivialCopy,
717 typename boost::disable_if_c<
718 _TypeInfoFor<T>::Type::IsLocal &&
719 _TypeInfoFor<T>::Type::HasTrivialCopy,
722 _HoldAside tmp(
this);
729 std::string tmp(cstr);
737 return *
this =
const_cast<char const *
>(cstr);
743 if (!IsEmpty() || !rhs.IsEmpty()) {
760 typename boost::enable_if<
761 boost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type
773 typename boost::enable_if<
774 boost::is_same<T, typename Vt_ValueGetStored<T>::Type> >::type
777 swap(_GetMutable<T>(), rhs);
800 UncheckedSwap(result);
809 return _info.GetLiteral() && _TypeIs<T>();
813 VT_API
bool IsArrayValued()
const;
820 VT_API std::type_info
const &GetTypeid()
const;
824 VT_API std::type_info
const &GetElementTypeid()
const;
827 VT_API
TfType GetType()
const;
830 VT_API std::string GetTypeName()
const;
848 typedef Vt_DefaultValueFactory<T> Factory;
852 if (ARCH_UNLIKELY(!IsHolding<T>())) {
853 return *(
static_cast<T
const *
>(
854 _FailGet(Factory::Invoke,
typeid(T))));
866 return IsHolding<T>() ? UncheckedGet<T>() : def;
870 template <
typename From,
typename To>
872 _RegisterCast(
typeid(From),
typeid(To), castFn);
877 template <
typename From,
typename To>
879 _RegisterCast(
typeid(From),
typeid(To), _SimpleCast<From, To>);
884 template <
typename From,
typename To>
886 RegisterSimpleCast<From, To>();
887 RegisterSimpleCast<To, From>();
897 template <
typename T>
900 return ret.
Cast<T>();
921 CastToTypeid(
VtValue const &val, std::type_info
const &type);
927 std::type_info
const &to) {
928 return _CanCast(from, to);
938 template <
typename T>
942 return *
this = _PerformCast(
typeid(T), *
this);
953 return *
this = _PerformCast(other.
GetTypeid(), *
this);
964 return *
this = _PerformCast(type, *
this);
970 template <
typename T>
972 return _CanCast(GetTypeid(),
typeid(T));
979 return _CanCast(GetTypeid(), other.
GetTypeid());
986 return _CanCast(GetTypeid(), type);
990 bool IsEmpty()
const {
return _info.GetLiteral() == 0; }
993 VT_API
bool CanHash()
const;
996 VT_API
size_t GetHash()
const;
998 friend inline size_t hash_value(
VtValue const &val) {
1003 template <
typename T>
1005 typedef typename Vt_ValueGetStored<T>::Type Stored;
1008 template <
typename T>
1014 template <
typename T>
1016 return !(lhs == rhs);
1018 template <
typename T>
1020 return !(lhs == rhs);
1025 bool empty = IsEmpty(), rhsEmpty = rhs.
IsEmpty();
1026 if (empty || rhsEmpty)
1027 return empty == rhsEmpty;
1028 if (_info.GetLiteral() == rhs._info.
GetLiteral())
1029 return _info.Get()->Equal(_storage, rhs._storage);
1030 return _EqualityImpl(rhs);
1035 VT_API
friend std::ostream &
1039 VT_API
const Vt_ShapeData* _GetShapeData()
const;
1040 VT_API
size_t _GetNumElements()
const;
1041 friend struct Vt_ValueShapeDataAccess;
1049 _HoldAside tmp(&dst);
1050 dst._info = src._info;
1051 if (src._IsLocalAndTriviallyCopyable()) {
1052 dst._storage = src._storage;
1054 dst._info->CopyInit(src._storage, dst._storage);
1064 _HoldAside tmp(&dst);
1065 dst._info = src._info;
1066 if (src._IsLocalAndTriviallyCopyable()) {
1067 dst._storage = src._storage;
1069 dst._info->Move(src._storage, dst._storage);
1072 src._info.
Set(
nullptr, 0);
1075 VtValue const *_ResolveProxy()
const {
1076 return ARCH_UNLIKELY(_IsProxy()) ?
1077 _info->GetProxiedValue(_storage) :
this;
1081 inline bool _TypeIs()
const {
1082 std::type_info
const &t =
typeid(T);
1084 return ARCH_UNLIKELY(_IsProxy() && !cmp) ? _TypeIsImpl(t) : cmp;
1087 VT_API
bool _TypeIsImpl(std::type_info
const &queriedType)
const;
1089 VT_API
bool _EqualityImpl(
VtValue const &rhs)
const;
1091 template <
class Proxy>
1092 typename boost::enable_if<VtIsValueProxy<Proxy>, Proxy &>::type
1094 typedef typename _TypeInfoFor<Proxy>::Type TypeInfo;
1095 return TypeInfo::GetMutableObj(_storage);
1099 typename boost::disable_if<VtIsValueProxy<T>, T &>::type
1102 if (ARCH_UNLIKELY(_IsProxy()))
1103 *
this = _info->GetProxiedValue(_storage);
1104 typedef typename _TypeInfoFor<T>::Type TypeInfo;
1105 return TypeInfo::GetMutableObj(_storage);
1108 template <
class Proxy>
1109 typename boost::enable_if<VtIsValueProxy<Proxy>, Proxy
const &>::type
1111 typedef typename _TypeInfoFor<Proxy>::Type TypeInfo;
1112 return TypeInfo::GetObj(_storage);
1116 typename boost::disable_if<VtIsValueProxy<T>, T
const &>::type
1118 typedef typename _TypeInfoFor<T>::Type TypeInfo;
1119 return TypeInfo::GetObj(_ResolveProxy()->_storage);
1125 _FailGet(Vt_DefaultValueHolder (*factory)(),
1126 std::type_info
const &queryType)
const;
1128 inline void _Clear() {
1130 if (_info.GetLiteral() && !_IsLocalAndTriviallyCopyable())
1131 _info.Get()->Destroy(_storage);
1132 _info.Set(
nullptr, 0);
1135 inline bool _IsLocalAndTriviallyCopyable()
const {
1136 unsigned int bits = _info.BitsAs<
unsigned int>();
1137 return (bits & (_LocalFlag | _TrivialCopyFlag)) ==
1138 (_LocalFlag | _TrivialCopyFlag);
1141 inline bool _IsProxy()
const {
1142 return _info.BitsAs<
unsigned int>() & _ProxyFlag;
1145 VT_API
static void _RegisterCast(std::type_info
const &from,
1146 std::type_info
const &to,
1150 _PerformCast(std::type_info
const &to,
VtValue const &val);
1153 _CanCast(std::type_info
const &from, std::type_info
const &to);
1156 template <
typename From,
typename To>
1161 #ifdef PXR_PYTHON_SUPPORT_ENABLED
1167 Vt_GetPythonObjectFromHeldValue(
VtValue const &
self);
1170 #endif // PXR_PYTHON_SUPPORT_ENABLED
1176 #if !defined(doxygen)
1182 struct Vt_DefaultValueFactory {
1184 static Vt_DefaultValueHolder Invoke() {
1185 return Vt_DefaultValueHolder::Create<T>();
1189 struct Vt_ValueShapeDataAccess {
1190 static const Vt_ShapeData* _GetShapeData(
const VtValue& value) {
1191 return value._GetShapeData();
1194 static size_t _GetNumElements(
const VtValue& value) {
1195 return value._GetNumElements();
1209 #define _VT_DECLARE_ZERO_VALUE_FACTORY(r, unused, elem) \
1211 VT_API Vt_DefaultValueHolder Vt_DefaultValueFactory<VT_TYPE(elem)>::Invoke();
1213 BOOST_PP_SEQ_FOR_EACH(_VT_DECLARE_ZERO_VALUE_FACTORY,
1216 VT_MATRIX_VALUE_TYPES
1217 VT_QUATERNION_VALUE_TYPES)
1219 #undef _VT_DECLARE_ZERO_VALUE_FACTORY
1228 VtValue::Get<VtValue>()
const {
1234 VtValue::UncheckedGet<VtValue>()
const {
1240 VtValue::IsHolding<VtValue>()
const {
1247 VtValue::IsHolding<void>()
const {
1253 PXR_NAMESPACE_CLOSE_SCOPE
1255 #endif // VT_VALUE_H
boost::enable_if< boost::is_same< T, typename Vt_ValueGetStored< T >::Type > >::type Swap(T &rhs)
Swap the held value with rhs. If this value is holding a T,.
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
static void RegisterSimpleBidirectionalCast()
Register a two-way cast from VtValue holding From to VtValue holding To.
T const & UncheckedGet() const
Returns a const reference to the held object if the held object is of type T.
VtValue(VtValue &&other) noexcept
Move construct with other.
VtValue & operator=(char const *cstr)
Assigning a char const * gives a VtValue holding a std::string.
bool CanCastToTypeOf(VtValue const &other) const
Return if this can be cast to type.
VtValue & Cast()
Return this holding value type cast to T.
bool CanCast() const
Return if this can be cast to T.
size_t GetArraySize() const
Return the number of elements in the held value if IsArrayValued(), return 0 otherwise.
boost::enable_if_c< _TypeInfoFor< T >::Type::IsLocal &&_TypeInfoFor< T >::Type::HasTrivialCopy, VtValue & >::type operator=(T obj)
Assignment operator from any type.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
constexpr uintptr_t GetLiteral() const noexcept
Retrieve the raw underlying value.
VtValue(VtValue const &other)
Copy construct with other.
T const & Get() const
Returns a const reference to the held object if the held object is of type T.
T UncheckedRemove()
Make this value empty and return the held T instance.
static void RegisterSimpleCast()
Register a simple cast from VtValue holding From to VtValue.
static bool CanCastFromTypeidToTypeid(std::type_info const &from, std::type_info const &to)
Return if a value of type from can be cast to type to.
VtValue & CastToTypeOf(VtValue const &other)
Return this holding value type cast to same type that other is holding.
boost::enable_if< boost::is_same< T, typename Vt_ValueGetStored< T >::Type > >::type UncheckedSwap(T &rhs)
Swap the held value with rhs.
static VtValue Take(T &obj)
Create a new VtValue, taking its contents from obj.
boost::disable_if_c< _TypeInfoFor< T >::Type::IsLocal &&_TypeInfoFor< T >::Type::HasTrivialCopy, VtValue & >::type operator=(T const &obj)
Assignment operator from any type.
void swap(UsdStageLoadRules &l, UsdStageLoadRules &r)
Swap the contents of rules l and r.
bool CanCastToTypeid(std::type_info const &type) const
Return if this can be cast to type.
VT_API std::type_info const & GetTypeid() const
Returns the typeid of the type held by this value.
static VtValue Cast(VtValue const &val)
Return a VtValue holding val cast to hold T.
VtValue & operator=(VtValue &&other) noexcept
Move assignment from another VtValue.
T GetWithDefault(T const &def=T()) const
Return a copy of the held object if the held object is of type T.
A simple type-erased container that provides only destruction, moves and immutable, untyped access to the held value.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
static void RegisterCast(VtValue(*castFn)(VtValue const &))
Register a cast from VtValue holding From to VtValue holding To.
VtValue & operator=(char *cstr)
Assigning a char * gives a VtValue holding a std::string.
Boost Python object wrapper.
VtValue(T const &obj)
Construct a VtValue holding a copy of obj.
VT_API size_t GetHash() const
Return a hash code for the held object by calling VtHashValue() on it.
VtValue & Swap(VtValue &rhs) noexcept
Swap this with rhs.
void UncheckedSwap(VtValue &rhs)
friend void swap(VtValue &lhs, VtValue &rhs)
Overloaded swap() for generic code/stl/etc.
TfType represents a dynamic runtime type.
void Set(T *ptr) noexcept
Set the pointer value to ptr.
VtValue & CastToTypeid(std::type_info const &type)
Return this holding value type cast to type.
VtValue()
Default ctor gives empty VtValue.
T Remove()
Make this value empty and return the held T instance.
bool IsEmpty() const
Returns true iff this value is empty.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
VtValue & operator=(VtValue const &other)
Copy assignment from another VtValue.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.