24 #ifndef PXR_BASE_TF_ANY_WEAK_PTR_H
25 #define PXR_BASE_TF_ANY_WEAK_PTR_H
37 #ifdef PXR_PYTHON_SUPPORT_ENABLED
39 #endif // PXR_PYTHON_SUPPORT_ENABLED
44 #include <type_traits>
63 template <
class Ptr,
class =
typename
67 static_assert(
sizeof(_PointerHolder<Ptr>) <=
sizeof(_Data),
68 "Ptr is too big to fit in a TfAnyWeakPtr");
69 new (&_ptrStorage) _PointerHolder<Ptr>(ptr);
74 static_assert(
sizeof(_EmptyHolder) <=
sizeof(_Data),
75 "Ptr is too big to fit in a TfAnyWeakPtr");
76 new (&_ptrStorage) _EmptyHolder;
86 other._Get()->Clone(&_ptrStorage);
91 _Get()->~_PointerHolderBase();
92 other._Get()->Clone(&_ptrStorage);
98 _Get()->~_PointerHolderBase();
112 TF_API operator bool()
const;
122 return !(*
this == rhs);
130 return !(rhs < *
this);
140 return !(*
this < rhs);
155 #ifdef PXR_PYTHON_SUPPORT_ENABLED
161 Tf_GetPythonObjectFromAnyWeakPtr(
This const &
self);
165 #endif // PXR_PYTHON_SUPPORT_ENABLED
167 template <
class WeakPtr>
171 struct _PointerHolderBase {
172 TF_API virtual ~_PointerHolderBase();
173 virtual void Clone(_Data *
target)
const = 0;
177 virtual operator bool()
const = 0;
178 virtual bool _IsConst()
const = 0;
180 virtual const std::type_info &
GetTypeInfo()
const = 0;
182 virtual const void* _GetMostDerivedPtr()
const = 0;
183 virtual bool _IsPolymorphic()
const = 0;
186 struct _EmptyHolder : _PointerHolderBase {
187 TF_API virtual ~_EmptyHolder();
192 TF_API virtual operator bool()
const;
193 TF_API virtual bool _IsConst()
const;
197 TF_API virtual const void* _GetMostDerivedPtr()
const;
198 TF_API virtual bool _IsPolymorphic()
const;
201 template <
typename Ptr>
202 struct _PointerHolder : _PointerHolderBase {
203 _PointerHolder(Ptr
const &
ptr) : _ptr(ptr) {
206 virtual ~_PointerHolder();
207 virtual void Clone(_Data *
target)
const;
211 virtual operator bool()
const;
212 virtual bool _IsConst()
const;
214 virtual const std::type_info &
GetTypeInfo()
const;
216 virtual const void* _GetMostDerivedPtr()
const;
217 virtual bool _IsPolymorphic()
const;
222 _PointerHolderBase* _Get()
const {
223 return (_PointerHolderBase*)(&_ptrStorage);
233 template <
class HashState,
234 class T,
class =
typename std::enable_if<
239 h.Append(ptr.GetUniqueIdentifier());
243 TfAnyWeakPtr::_PointerHolder<Ptr>::~_PointerHolder() {}
247 TfAnyWeakPtr::_PointerHolder<Ptr>::Clone(_Data *
target)
const
249 new (
target) _PointerHolder<Ptr>(_ptr);
254 TfAnyWeakPtr::_PointerHolder<Ptr>::IsInvalid()
const
256 return _ptr.IsInvalid();
261 TfAnyWeakPtr::_PointerHolder<Ptr>::GetUniqueIdentifier()
const
263 return _ptr.GetUniqueIdentifier();
268 TfAnyWeakPtr::_PointerHolder<Ptr>::GetWeakBase()
const
270 return &(_ptr->__GetTfWeakBase__());
274 TfAnyWeakPtr::_PointerHolder<Ptr>::operator bool()
const
281 TfAnyWeakPtr::_PointerHolder<Ptr>::GetPythonObject()
const
283 #ifdef PXR_PYTHON_SUPPORT_ENABLED
287 #endif // PXR_PYTHON_SUPPORT_ENABLED
290 const std::type_info &
291 TfAnyWeakPtr::_PointerHolder<Ptr>::GetTypeInfo()
const
298 TfAnyWeakPtr::_PointerHolder<Ptr>::GetType()
const
305 TfAnyWeakPtr::_PointerHolder<Ptr>::_GetMostDerivedPtr()
const
317 TfAnyWeakPtr::_PointerHolder<Ptr>::_IsPolymorphic()
const
324 TfAnyWeakPtr::_PointerHolder<Ptr>::_IsConst()
const
TF_API const std::type_info & GetTypeInfo() const
returns the type_info of the underlying WeakPtr
void TfHashAppend(HashState &h, const T &ptr)
TfAnyWeakPtr(Ptr const &ptr)
Construct an AnyWeakPtr watching ptr.
GLsizei const GLfloat * value
static TfType const & Find()
TfAnyWeakPtr(TfNullPtrType)
Construct and implicitly convert from TfNullPtr.
fallback_uintptr uintptr_t
TfAnyWeakPtr(std::nullptr_t)
Construct and implicitly convert from std::nullptr_t.
TF_API bool operator<(const TfAnyWeakPtr &rhs) const
comparison operator
Y * get_pointer(TfWeakPtrFacade< X, Y > const &p)
TF_API bool operator!() const
operator !
TfAnyWeakPtr()
Construct an AnyWeakPtr not watching any ptr.
TF_API void const * GetUniqueIdentifier() const
Return the unique identifier of the WeakPtr this AnyWeakPtr contains.
std::weak_ptr< T > WeakPtr
TF_API bool IsInvalid() const
std::enable_if< std::is_polymorphic< T >::value, Tf_CopyCV< T, void > * >::type TfCastToMostDerivedType(T *ptr)
TF_API TfType const & GetType() const
Returns the TfType of the underlying WeakPtr.
bool operator<=(const TfAnyWeakPtr &rhs) const
less than or equal operator
const std::type_info & TfTypeid(const TfRefPtr< T > &ptr)
friend WeakPtr TfAnyWeakPtrDynamicCast(const TfAnyWeakPtr &anyWeak, WeakPtr *)
TfAnyWeakPtr & operator=(TfAnyWeakPtr const &other)
hboost::python::object TfPyObject(T const &t, bool complainOnFailure=true)
TF_API bool operator==(const TfAnyWeakPtr &rhs) const
equality operator
size_t GetHash() const
Return a hash value for this instance.
GLfloat GLfloat GLfloat GLfloat h
bool operator>=(const TfAnyWeakPtr &rhs) const
greater than or equal operator
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
TfAnyWeakPtr(TfAnyWeakPtr const &other)
#define PXR_NAMESPACE_CLOSE_SCOPE
bool operator!=(const TfAnyWeakPtr &rhs) const
inequality operator
TF_API TfWeakBase const * GetWeakBase() const
Return the TfWeakBase object of the WeakPtr we are holding.
bool operator>(const TfAnyWeakPtr &rhs) const
greater than operator