24 #ifndef PXR_BASE_VT_VALUE_H
25 #define PXR_BASE_VT_VALUE_H
29 #ifdef PXR_PYTHON_SUPPORT_ENABLED
33 #endif // PXR_PYTHON_SUPPORT_ENABLED
52 #include <hboost/aligned_storage.hpp>
53 #include <hboost/intrusive_ptr.hpp>
54 #include <hboost/mpl/and.hpp>
55 #include <hboost/mpl/if.hpp>
56 #include <hboost/type_traits/decay.hpp>
57 #include <hboost/type_traits/has_trivial_assign.hpp>
58 #include <hboost/type_traits/has_trivial_constructor.hpp>
59 #include <hboost/type_traits/has_trivial_copy.hpp>
60 #include <hboost/type_traits/has_trivial_destructor.hpp>
61 #include <hboost/type_traits/is_same.hpp>
62 #include <hboost/utility/enable_if.hpp>
66 #include <type_traits>
107 : _ptr(std::move(
ptr)), _type(&type) {}
110 std::type_info
const *_type;
119 #define VT_VALUE_SET_STORED_TYPE(SRC, DST) \
120 template <> struct Vt_ValueStoredType<SRC> { typedef DST Type; }
126 #ifdef PXR_PYTHON_SUPPORT_ENABLED
128 #endif // PXR_PYTHON_SUPPORT_ENABLED
130 #undef VT_VALUE_SET_STORED_TYPE
176 static const unsigned int _LocalFlag = 1 << 0;
177 static const unsigned int _TrivialCopyFlag = 1 << 1;
178 static const unsigned int _ProxyFlag = 1 << 2;
182 explicit _Counted(
T const &
obj) : _obj(obj) {
185 bool IsUnique()
const {
return _refCount == 1; }
186 T const &
Get()
const {
return _obj; }
187 T &GetMutable() {
return _obj; }
191 mutable std::atomic<int> _refCount;
194 d->_refCount.fetch_add(1, std::memory_order_relaxed);
197 if (d->_refCount.fetch_sub(1, std::memory_order_release) == 1) {
198 std::atomic_thread_fence(std::memory_order_acquire);
207 static const size_t _MaxLocalSize =
sizeof(
void*);
208 typedef std::aligned_storage<
209 _MaxLocalSize, _MaxLocalSize>
::type _Storage;
212 struct _IsTriviallyCopyable : hboost::mpl::and_<
213 hboost::has_trivial_constructor<T>,
214 hboost::has_trivial_copy<T>,
215 hboost::has_trivial_assign<T>,
216 hboost::has_trivial_destructor<T> > {};
221 struct _UsesLocalStore : hboost::mpl::bool_<
222 (sizeof(T) <= sizeof(_Storage)) &&
223 VtValueTypeHasCheapCopy<T>::value &&
224 std::is_nothrow_move_constructible<T>::value &&
225 std::is_nothrow_move_assignable<T>::value> {};
230 using _CopyInitFunc = void (*)(_Storage const &, _Storage &);
231 using _DestroyFunc = void (*)(_Storage &);
232 using _MoveFunc = void (*)(_Storage &, _Storage &);
233 using _CanHashFunc = bool (*)(_Storage const &);
234 using _HashFunc = size_t (*)(_Storage const &);
235 using _EqualFunc = bool (*)(_Storage const &, _Storage const &);
236 using _EqualPtrFunc = bool (*)(_Storage const &, void const *);
237 using _MakeMutableFunc = void (*)(_Storage &);
238 #ifdef PXR_PYTHON_SUPPORT_ENABLED
239 using _GetPyObjFunc = TfPyObjWrapper (*)(_Storage const &);
241 using _StreamOutFunc =
242 std::ostream & (*)(_Storage const &, std::ostream &);
243 using _GetTypeidFunc = std::type_info const & (*)(_Storage const &);
244 using _IsArrayValuedFunc = bool (*)(_Storage const &);
245 using _GetElementTypeidFunc =
246 std::type_info const & (*)(_Storage const &);
247 using _GetShapeDataFunc = const Vt_ShapeData* (*)(_Storage const &);
248 using _GetNumElementsFunc = size_t (*)(_Storage const &);
249 using _ProxyHoldsTypeFunc = bool (*)(_Storage const &, std::type_info const &);
250 using _GetProxiedTypeFunc = TfType (*)(_Storage const &);
251 using _GetProxiedTypeidFunc =
252 std::type_info const & (*)(_Storage const &);
253 using _GetProxiedObjPtrFunc = void const *(*)(_Storage const &);
254 using _GetProxiedAsVtValueFunc = VtValue (*)(_Storage const &);
257 constexpr _TypeInfo(const std::type_info &ti,
258 const std::type_info &elementTi,
262 _CopyInitFunc copyInit,
263 _DestroyFunc destroy,
265 _CanHashFunc canHash,
268 _EqualPtrFunc equalPtr,
269 _MakeMutableFunc makeMutable,
270 #ifdef PXR_PYTHON_SUPPORT_ENABLED
271 _GetPyObjFunc getPyObj,
273 _StreamOutFunc streamOut,
274 _GetTypeidFunc getTypeid,
275 _IsArrayValuedFunc isArrayValued,
276 _GetElementTypeidFunc getElementTypeid,
277 _GetShapeDataFunc getShapeData,
278 _GetNumElementsFunc getNumElements,
279 _ProxyHoldsTypeFunc proxyHoldsType,
280 _GetProxiedTypeFunc getProxiedType,
281 _GetProxiedTypeidFunc getProxiedTypeid,
282 _GetProxiedObjPtrFunc getProxiedObjPtr,
283 _GetProxiedAsVtValueFunc getProxiedAsVtValue)
285 , elementTypeInfo(elementTi)
288 , isHashable(isHashable)
290 , _copyInit(copyInit)
296 , _equalPtr(equalPtr)
297 , _makeMutable(makeMutable)
298 #ifdef PXR_PYTHON_SUPPORT_ENABLED
299 , _getPyObj(getPyObj)
301 , _streamOut(streamOut)
302 , _getTypeid(getTypeid)
303 , _isArrayValued(isArrayValued)
304 , _getElementTypeid(getElementTypeid)
305 , _getShapeData(getShapeData)
306 , _getNumElements(getNumElements)
307 , _proxyHoldsType(proxyHoldsType)
308 , _getProxiedType(getProxiedType)
309 , _getProxiedTypeid(getProxiedTypeid)
310 , _getProxiedObjPtr(getProxiedObjPtr)
311 , _getProxiedAsVtValue(getProxiedAsVtValue)
315 void CopyInit(_Storage const &src, _Storage &dst) const {
318 void Destroy(_Storage &storage) const {
321 void Move(_Storage &src, _Storage &dst) const noexcept {
324 bool CanHash(_Storage const &storage) const {
325 return _canHash(storage);
327 size_t Hash(_Storage const &storage) const {
328 return _hash(storage);
330 bool Equal(_Storage const &lhs, _Storage const &rhs) const {
331 return _equal(lhs, rhs);
333 bool EqualPtr(_Storage const &lhs, void const *rhs) const {
334 return _equalPtr(lhs, rhs);
336 void MakeMutable(_Storage &storage) const {
337 _makeMutable(storage);
339 #ifdef PXR_PYTHON_SUPPORT_ENABLED
340 TfPyObjWrapper GetPyObj(_Storage const &storage) const {
341 return _getPyObj(storage);
344 std::ostream &StreamOut(_Storage const &storage,
345 std::ostream &out) const {
346 return _streamOut(storage, out);
348 bool IsArrayValued(_Storage const &storage) const {
349 return _isArrayValued(storage);
351 std::type_info const &GetElementTypeid(_Storage const &storage) const {
352 return _getElementTypeid(storage);
354 std::type_info const &GetTypeid(_Storage const &storage) const {
355 return _getTypeid(storage);
357 const Vt_ShapeData* GetShapeData(_Storage const &storage) const {
358 return _getShapeData(storage);
360 size_t GetNumElements(_Storage const &storage) const {
361 return _getNumElements(storage);
363 bool ProxyHoldsType(_Storage const &storage,
364 std::type_info const &t) const {
365 return _proxyHoldsType(storage, t);
367 TfType GetProxiedType(_Storage const &storage) const {
368 return _getProxiedType(storage);
370 std::type_info const &GetProxiedTypeid(_Storage const &storage) const {
371 return _getProxiedTypeid(storage);
373 VtValue GetProxiedAsVtValue(_Storage const &storage) const {
374 return _getProxiedAsVtValue(storage);
376 void const *GetProxiedObjPtr(_Storage const &storage) const {
377 return _getProxiedObjPtr(storage);
380 const std::type_info &typeInfo;
381 const std::type_info &elementTypeInfo;
387 _CopyInitFunc _copyInit;
388 _DestroyFunc _destroy;
390 _CanHashFunc _canHash;
393 _EqualPtrFunc _equalPtr;
394 _MakeMutableFunc _makeMutable;
395 #ifdef PXR_PYTHON_SUPPORT_ENABLED
396 _GetPyObjFunc _getPyObj;
398 _StreamOutFunc _streamOut;
399 _GetTypeidFunc _getTypeid;
400 _IsArrayValuedFunc _isArrayValued;
401 _GetElementTypeidFunc _getElementTypeid;
402 _GetShapeDataFunc _getShapeData;
403 _GetNumElementsFunc _getNumElements;
404 _ProxyHoldsTypeFunc _proxyHoldsType;
405 _GetProxiedTypeFunc _getProxiedType;
406 _GetProxiedTypeidFunc _getProxiedTypeid;
407 _GetProxiedObjPtrFunc _getProxiedObjPtr;
408 _GetProxiedAsVtValueFunc _getProxiedAsVtValue;
414 template <class T, class Enable=void>
417 static const Vt_ShapeData* GetShapeData(T const &) { return NULL; }
418 static size_t GetNumElements(T const &) { return 0; }
419 constexpr static std::type_info const &GetElementTypeid() {
423 template <class Array>
425 Array, typename std::enable_if<VtIsArray<Array>::value>::type>
427 static const Vt_ShapeData* GetShapeData(Array const &obj) {
428 return obj._GetShapeData();
430 static size_t GetNumElements(Array const &obj) {
433 constexpr static std::type_info const &GetElementTypeid() {
434 return typeid(typename Array::ElementType);
441 _TypedProxyEqualityImpl(T const &a, T const &b, int) -> decltype(a == b) {
445 template <
class NoEqual>
447 _TypedProxyEqualityImpl(NoEqual
const &
a, NoEqual
const &
b,
long) {
453 _ErasedProxyEqualityImpl(
T const &a,
T const &b,
int) -> decltype(a == b) {
457 template <
class NoEqual>
459 _ErasedProxyEqualityImpl(NoEqual
const &a, NoEqual
const &b,
long) {
460 return *VtGetErasedProxiedVtValue(a) == *VtGetErasedProxiedVtValue(b);
464 template <
class T,
class Enable =
void>
469 static bool CanHash(
T const &) {
return VtIsHashable<ProxiedType>(); }
473 static bool Equal(
T const &a,
T const &b) {
478 return _TypedProxyEqualityImpl(a, b, 0);
480 #ifdef PXR_PYTHON_SUPPORT_ENABLED
486 #endif //PXR_PYTHON_SUPPORT_ENABLED
487 static std::ostream &StreamOut(
T const &obj, std::ostream &out) {
491 return _ArrayHelper<ProxiedType>::GetShapeData(
494 static size_t GetNumElements(
T const &obj) {
495 return _ArrayHelper<ProxiedType>::GetNumElements(
501 static std::type_info
const &
GetTypeid(
T const &) {
502 return typeid(ProxiedType);
505 return _ArrayHelper<ProxiedType>::GetElementTypeid();
507 static VtValue GetProxiedAsVtValue(
T const &obj) {
510 static bool HoldsType(
T const &tp, std::type_info
const &
query) {
513 static TfType GetTfType(
T const &tp) {
514 return TfType::Find<ProxiedType>();
516 static void const *GetObjPtr(
T const &tp) {
521 template <
class ErasedProxy>
523 ErasedProxy, typename std::enable_if<
524 VtIsErasedValueProxy<ErasedProxy>::value>
::type>
526 static bool CanHash(ErasedProxy
const &proxy) {
527 return VtGetErasedProxiedVtValue(proxy)->CanHash();
529 static size_t Hash(ErasedProxy
const &proxy) {
530 return VtGetErasedProxiedVtValue(proxy)->GetHash();
532 static bool Equal(ErasedProxy
const &a, ErasedProxy
const &b) {
537 return _ErasedProxyEqualityImpl(a, b, 0);
539 #ifdef PXR_PYTHON_SUPPORT_ENABLED
541 VtValue const *
val = VtGetErasedProxiedVtValue(obj);
545 #endif //PXR_PYTHON_SUPPORT_ENABLED
547 static std::ostream &
548 StreamOut(ErasedProxy
const &obj, std::ostream &out) {
551 static Vt_ShapeData const *GetShapeData(ErasedProxy
const &obj) {
552 return VtGetErasedProxiedVtValue(obj)->_GetShapeData();
554 static size_t GetNumElements(ErasedProxy
const &obj) {
555 return VtGetErasedProxiedVtValue(obj)->_GetNumElements();
558 return VtGetErasedProxiedVtValue(obj)->IsArrayValued();
560 static std::type_info
const &
GetTypeid(ErasedProxy
const &obj) {
561 return VtGetErasedProxiedVtValue(obj)->GetTypeid();
564 return VtGetErasedProxiedVtValue(obj)->GetElementTypeid();
566 static VtValue GetProxiedAsVtValue(ErasedProxy
const &ep) {
567 return *VtGetErasedProxiedVtValue(ep);
570 HoldsType(ErasedProxy
const &ep, std::type_info
const &
query) {
571 return VtErasedProxyHoldsType(ep, query);
573 static TfType GetTfType(ErasedProxy
const &ep) {
574 return VtGetErasedProxiedTfType(ep);
576 static void const *GetObjPtr(ErasedProxy
const &ep) {
577 VtValue const *
val = VtGetErasedProxiedVtValue(ep);
578 return val ? val->_GetProxiedObjPtr() :
nullptr;
585 template <
class T,
class Container,
class Derived>
586 struct _TypeInfoImpl :
public _TypeInfo
592 using ProxyHelper = _ProxyHelper<T>;
594 using This = _TypeInfoImpl;
596 constexpr _TypeInfoImpl()
597 : _TypeInfo(
typeid(
T),
598 _ArrayHelper<T>::GetElementTypeid(),
618 &This::_IsArrayValued,
619 &This::_GetElementTypeid,
620 &This::_GetShapeData,
621 &This::_GetNumElements,
624 &This::_ProxyHoldsType,
625 &This::_GetProxiedType,
626 &This::_GetProxiedTypeid,
627 &This::_GetProxiedObjPtr,
628 &This::_GetProxiedAsVtValue)
633 static T const &GetObj(_Storage
const &
storage) {
634 return Derived::_GetObj(_Container(storage));
637 static T &GetMutableObj(_Storage &storage) {
638 return Derived::_GetMutableObj(_Container(storage));
641 static void CopyInitObj(
T const &objSrc, _Storage &
dst) {
642 Derived::_PlaceCopy(&_Container(dst), objSrc);
646 static_assert(
sizeof(Container) <=
sizeof(_Storage),
647 "Container size cannot exceed storage size.");
651 static void _CopyInit(_Storage
const &
src, _Storage &dst) {
652 new (&_Container(dst)) Container(_Container(src));
655 static void _Destroy(_Storage &storage) {
656 _Container(storage).~Container();
659 static bool _CanHash(_Storage
const &storage) {
660 return ProxyHelper::CanHash(GetObj(storage));
663 static size_t _Hash(_Storage
const &storage) {
667 static bool _Equal(_Storage
const &lhs, _Storage
const &rhs) {
671 return ProxyHelper::Equal(GetObj(lhs), GetObj(rhs));
674 static bool _EqualPtr(_Storage
const &lhs,
void const *rhs) {
678 return ProxyHelper::Equal(
679 GetObj(lhs), *static_cast<T const *>(rhs));
682 static void _Move(_Storage &src, _Storage &dst) noexcept {
683 new (&_Container(dst)) Container(std::move(_Container(src)));
687 static void _MakeMutable(_Storage &storage) {
688 GetMutableObj(storage);
691 #ifdef PXR_PYTHON_SUPPORT_ENABLED
693 return ProxyHelper::GetPyObj(GetObj(storage));
695 #endif // PXR_PYTHON_SUPPORT_ENABLED
697 static std::ostream &_StreamOut(
698 _Storage
const &storage, std::ostream &out) {
699 return ProxyHelper::StreamOut(GetObj(storage), out);
702 static std::type_info
const &_GetTypeid(_Storage
const &storage) {
703 return ProxyHelper::GetTypeid(GetObj(storage));
706 static bool _IsArrayValued(_Storage
const &storage) {
707 return ProxyHelper::IsArrayValued(GetObj(storage));
710 static std::type_info
const &
711 _GetElementTypeid(_Storage
const &storage) {
712 return ProxyHelper::GetElementTypeid(GetObj(storage));
715 static const Vt_ShapeData* _GetShapeData(_Storage
const &storage) {
716 return ProxyHelper::GetShapeData(GetObj(storage));
719 static size_t _GetNumElements(_Storage
const &storage) {
720 return ProxyHelper::GetNumElements(GetObj(storage));
724 _ProxyHoldsType(_Storage
const &storage, std::type_info
const &
t) {
725 return ProxyHelper::HoldsType(GetObj(storage), t);
729 _GetProxiedType(_Storage
const &storage) {
730 return ProxyHelper::GetTfType(GetObj(storage));
733 static std::type_info
const &
734 _GetProxiedTypeid(_Storage
const &storage) {
735 return ProxyHelper::GetTypeid(GetObj(storage));
739 _GetProxiedObjPtr(_Storage
const &storage) {
740 return ProxyHelper::GetObjPtr(GetObj(storage));
744 _GetProxiedAsVtValue(_Storage
const &storage) {
745 return ProxyHelper::GetProxiedAsVtValue(GetObj(storage));
751 static Container &_Container(_Storage &storage) {
753 return *
reinterpret_cast<Container *
>(&
storage);
755 static Container
const &_Container(_Storage
const &storage) {
757 return *
reinterpret_cast<Container
const *
>(&
storage);
765 struct _LocalTypeInfo : _TypeInfoImpl<
771 constexpr _LocalTypeInfo()
772 : _TypeInfoImpl<T, T, _LocalTypeInfo<T>>()
776 static T &_GetMutableObj(
T &
obj) {
return obj; }
777 static T const &_GetObj(
T const &obj) {
return obj; }
779 static void _PlaceCopy(
T *
dst,
T const &
src) {
new (
dst)
T(src); }
786 struct _RemoteTypeInfo : _TypeInfoImpl<
788 hboost::intrusive_ptr<_Counted<T> >,
792 constexpr _RemoteTypeInfo()
794 T, hboost::intrusive_ptr<_Counted<T>>, _RemoteTypeInfo<T>>()
797 typedef hboost::intrusive_ptr<_Counted<T> > Ptr;
799 static T &_GetMutableObj(Ptr &
ptr) {
800 if (!ptr->IsUnique())
801 ptr.reset(
new _Counted<T>(ptr->Get()));
802 return ptr->GetMutable();
804 static T const &_GetObj(Ptr
const &ptr) {
return ptr->Get(); }
806 static void _PlaceCopy(Ptr *
dst,
T const &
src) {
807 new (
dst) Ptr(
new _Counted<T>(src));
813 struct _TypeInfoFor {
815 typedef typename hboost::mpl::if_<_UsesLocalStore<T>,
822 struct _TypeInfoFor<char[N]> {
824 typedef typename hboost::mpl::if_<_UsesLocalStore<std::string>,
825 _LocalTypeInfo<std::string>,
833 typedef typename _TypeInfoFor<T>::Type TI;
835 static constexpr
unsigned int flags =
836 (TI::IsLocal ? _LocalFlag : 0) |
837 (TI::HasTrivialCopy ? _TrivialCopyFlag : 0) |
838 (TI::IsProxy ? _ProxyFlag : 0);
851 : info((val->
IsEmpty() || val->_IsLocalAndTriviallyCopyable())
852 ? static_cast<_TypeInfo
const *>(NULL) : val->_info.
Get()) {
854 info->Move(val->_storage,
storage);
861 _TypeInfo
const *info;
865 typename hboost::enable_if<
867 _Init(
T const &
obj) {
868 _info = GetTypeInfo<T>();
870 TypeInfo::CopyInitObj(obj, _storage);
874 typename hboost::disable_if<
876 _Init(
T const &
obj) {
951 typename hboost::enable_if_c<
952 _TypeInfoFor<T>::Type::IsLocal &&
953 _TypeInfoFor<T>::Type::HasTrivialCopy,
969 typename hboost::disable_if_c<
970 _TypeInfoFor<T>::Type::IsLocal &&
971 _TypeInfoFor<T>::Type::HasTrivialCopy,
990 return *
this =
const_cast<char const *
>(cstr);
996 if (!
IsEmpty() || !rhs.IsEmpty()) {
1018 typename hboost::enable_if<
1021 if (!IsHolding<T>())
1037 typename hboost::enable_if<
1041 swap(_GetMutable<T>(), rhs);
1118 return *(
static_cast<T const *
>(
1119 _FailGet(Factory::Invoke,
typeid(
T))));
1131 return IsHolding<T>() ? UncheckedGet<T>() : def;
1135 template <
typename From,
typename To>
1137 _RegisterCast(
typeid(From),
typeid(To), castFn);
1142 template <
typename From,
typename To>
1144 _RegisterCast(
typeid(From),
typeid(To), _SimpleCast<From, To>);
1149 template <
typename From,
typename To>
1151 RegisterSimpleCast<From, To>();
1152 RegisterSimpleCast<To, From>();
1162 template <
typename T>
1165 return ret.
Cast<
T>();
1192 std::type_info
const &to) {
1193 return _CanCast(from, to);
1203 template <
typename T>
1207 return *
this = _PerformCast(
typeid(
T), *
this);
1218 return *
this = _PerformCast(other.
GetTypeid(), *
this);
1229 return *
this = _PerformCast(type, *
this);
1235 template <
typename T>
1268 template <
typename T>
1273 template <
typename T>
1279 template <
typename T>
1281 return !(lhs == rhs);
1283 template <
typename T>
1285 return !(lhs == rhs);
1291 if (empty || rhsEmpty) {
1293 return empty == rhsEmpty;
1297 return _info.
Get()->Equal(_storage, rhs._storage);
1299 return _EqualityImpl(rhs);
1304 VT_API friend std::ostream &
1309 VT_API size_t _GetNumElements()
const;
1319 dst._info = src._info;
1320 if (src._IsLocalAndTriviallyCopyable()) {
1321 dst._storage = src._storage;
1323 dst._info->CopyInit(src._storage, dst._storage);
1334 dst._info = src._info;
1335 if (src._IsLocalAndTriviallyCopyable()) {
1336 dst._storage = src._storage;
1338 dst._info->Move(src._storage, dst._storage);
1341 src._info.
Set(
nullptr, 0);
1345 inline bool _TypeIs()
const {
1346 std::type_info
const &
t =
typeid(
T);
1348 return ARCH_UNLIKELY(_IsProxy() && !cmp) ? _TypeIsImpl(t) : cmp;
1351 VT_API bool _TypeIsImpl(std::type_info
const &queriedType)
const;
1355 template <
class Proxy>
1356 typename hboost::enable_if<VtIsValueProxy<Proxy>, Proxy &>
::type
1359 return TypeInfo::GetMutableObj(_storage);
1363 typename hboost::disable_if<VtIsValueProxy<T>,
T &>
::type
1367 *
this = _info->GetProxiedAsVtValue(_storage);
1370 return TypeInfo::GetMutableObj(_storage);
1373 template <
class Proxy>
1374 typename hboost::enable_if<VtIsValueProxy<Proxy>, Proxy
const &>
::type
1377 return TypeInfo::GetObj(_storage);
1381 typename hboost::disable_if<VtIsValueProxy<T>,
T const &>
::type
1385 return *
static_cast<T const *
>(_GetProxiedObjPtr());
1387 return TypeInfo::GetObj(_storage);
1390 void const *_GetProxiedObjPtr()
const {
1391 return _info->GetProxiedObjPtr(_storage);
1398 std::type_info
const &queryType)
const;
1400 inline void _Clear() {
1402 if (_info.
GetLiteral() && !_IsLocalAndTriviallyCopyable())
1403 _info.
Get()->Destroy(_storage);
1404 _info.
Set(
nullptr, 0);
1407 inline bool _IsLocalAndTriviallyCopyable()
const {
1408 unsigned int bits = _info.
BitsAs<
unsigned int>();
1409 return (bits & (_LocalFlag | _TrivialCopyFlag)) ==
1410 (_LocalFlag | _TrivialCopyFlag);
1413 inline bool _IsProxy()
const {
1414 return _info.
BitsAs<
unsigned int>() & _ProxyFlag;
1417 VT_API static void _RegisterCast(std::type_info
const &from,
1418 std::type_info
const &to,
1422 _PerformCast(std::type_info
const &to,
VtValue const &val);
1425 _CanCast(std::type_info
const &from, std::type_info
const &to);
1428 template <
typename From,
typename To>
1433 #ifdef PXR_PYTHON_SUPPORT_ENABLED
1439 Vt_GetPythonObjectFromHeldValue(
VtValue const &
self);
1442 #endif // PXR_PYTHON_SUPPORT_ENABLED
1457 return Vt_DefaultValueHolder::Create<T>();
1463 return value._GetShapeData();
1467 return value._GetNumElements();
1481 #define _VT_DECLARE_ZERO_VALUE_FACTORY(r, unused, elem) \
1483 VT_API Vt_DefaultValueHolder Vt_DefaultValueFactory<VT_TYPE(elem)>::Invoke();
1491 #undef _VT_DECLARE_ZERO_VALUE_FACTORY
1500 VtValue::Get<VtValue>()
const {
1506 VtValue::UncheckedGet<VtValue>()
const {
1512 VtValue::IsHolding<VtValue>()
const {
1519 VtValue::IsHolding<void>()
const {
1529 #endif // PXR_BASE_VT_VALUE_H
T const & UncheckedGet() const
static Vt_DefaultValueHolder Create(T const &val)
static VtValue Take(T &obj)
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)
VtValue & CastToTypeOf(VtValue const &other)
static void RegisterCast(VtValue(*castFn)(VtValue const &))
Register a cast from VtValue holding From to VtValue holding To.
GLuint const GLfloat * val
static const Vt_ShapeData * _GetShapeData(const VtValue &value)
GLboolean GLboolean GLboolean GLboolean a
VtValue & operator=(char const *cstr)
Assigning a char const * gives a VtValue holding a std::string.
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
hboost::enable_if_c< _TypeInfoFor< T >::Type::IsLocal &&_TypeInfoFor< T >::Type::HasTrivialCopy, VtValue & >::type operator=(T obj)
size_t GetArraySize() const
VtValue & Swap(VtValue &rhs) noexcept
Swap this with rhs.
bool IsEmpty() const
Returns true iff this value is empty.
VtValue & operator=(char *cstr)
Assigning a char * gives a VtValue holding a std::string.
HBOOST_PP_SEQ_FOR_EACH(SDF_DECLARE_VALUE_TYPE_TRAITS,~, SDF_VALUE_TYPES)
T const & VtGetProxiedObject(T const &nonProxy)
static size_t _GetNumElements(const VtValue &value)
VtValue(VtValue const &other)
Copy construct with other.
size_t OIIO_API Hash(const char *s, size_t len)
constexpr T * Get() const noexcept
Retrieve the pointer.
hboost::enable_if< hboost::is_same< T, typename Vt_ValueGetStored< T >::Type > >::type UncheckedSwap(T &rhs)
bool CanCastToTypeOf(VtValue const &other) const
static VT_API VtValue CastToTypeOf(VtValue const &val, VtValue const &other)
constexpr uintptr_t GetLiteral() const noexcept
static VT_API VtValue CastToTypeid(VtValue const &val, std::type_info const &type)
void intrusive_ptr_release(T *x)
VT_API bool IsArrayValued() const
Returns true iff this is holding an array type (see VtIsArray<>).
VT_API std::type_info const & GetElementTypeid() const
friend bool operator!=(VtValue const &lhs, T const &rhs)
Tests for inequality.
void UncheckedSwap(VtValue &rhs)
typename std::decay< decltype(VtGetProxiedObject(std::declval< T >()))>::type type
constexpr Integral BitsAs() const noexcept
Retrieve the stored bits as the integral type Integral.
static bool CanCastFromTypeidToTypeid(std::type_info const &from, std::type_info const &to)
friend bool operator==(VtValue const &lhs, T const &rhs)
Tests for equality.
#define VT_VEC_VALUE_TYPES
VT_API std::ostream & VtStreamOut(std::vector< VtValue > const &val, std::ostream &)
#define VT_VALUE_SET_STORED_TYPE(SRC, DST)
VtValue(VtValue &&other) noexcept
Move construct with other.
#define _VT_DECLARE_ZERO_VALUE_FACTORY(r, unused, elem)
GLuint GLuint GLsizei GLenum type
void const * GetPointer() const
VtValue & operator=(VtValue &&other) noexcept
Move assignment from another VtValue.
void Set(T *ptr) noexcept
Set the pointer value to ptr.
VT_API std::type_info const & GetTypeid() const
Returns the typeid of the type held by this value.
GLdouble GLdouble GLdouble b
Array concept. By default, types are not arrays.
GLsizei const GLchar *const * string
VT_API size_t GetHash() const
Return a hash code for the held object by calling VtHashValue() on it.
void intrusive_ptr_add_ref(T *x)
VtValue & operator=(VtValue const &other)
Copy assignment from another VtValue.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
friend size_t hash_value(VtValue const &val)
size_t VtHashValue(T const &val)
static VtValue Cast(VtValue const &val)
std::type_info const & GetType() const
static Vt_DefaultValueHolder Create()
VT_API std::string GetTypeName() const
Return the type name of the held typeid.
#define PXR_NAMESPACE_CLOSE_SCOPE
friend void swap(VtValue &lhs, VtValue &rhs)
Overloaded swap() for generic code/stl/etc.
hboost::enable_if< hboost::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,.
static void RegisterSimpleCast()
Register a simple cast from VtValue holding From to VtValue.
static Vt_DefaultValueHolder Invoke()
This function must return an object of type T.
getOption("OpenEXR.storage") storage
static TfAnyUniquePtr New()
#define VT_QUATERNION_VALUE_TYPES
VtValue & CastToTypeid(std::type_info const &type)
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
VtValue()
Default ctor gives empty VtValue.
static void RegisterSimpleBidirectionalCast()
VT_API friend std::ostream & operator<<(std::ostream &out, const VtValue &self)
Calls through to operator << on the held object.
T GetWithDefault(T const &def=T()) const
GLsizei const GLfloat * value
hboost::disable_if_c< _TypeInfoFor< T >::Type::IsLocal &&_TypeInfoFor< T >::Type::HasTrivialCopy, VtValue & >::type operator=(T const &obj)
Assignment operator from any type.
#define VT_MATRIX_VALUE_TYPES
#define PXR_PYTHON_SUPPORT_ENABLED
bool CanCastToTypeid(std::type_info const &type) const
VT_API TfType GetType() const
Returns the TfType of the type held by this value.
VT_API bool CanHash() const
Return true if the held object provides a hash implementation.
void const * Get() const
Return a pointer to the owned object.