Urho3D::WeakPtr< T > Class Template Reference

Weak pointer template class with intrusive reference counting. Does not keep the object pointed to alive. More...

#include <Urho3D/Container/Ptr.h>

Collaboration diagram for Urho3D::WeakPtr< T >:
[legend]

Public Member Functions

 WeakPtr () noexcept
 Construct a null weak pointer.
 
 WeakPtr (std::nullptr_t) noexcept
 Construct a null weak pointer.
 
 WeakPtr (const WeakPtr< T > &rhs) noexcept
 Copy-construct from another weak pointer.
 
 WeakPtr (WeakPtr< T > &&rhs) noexcept
 Move-construct from another weak pointer.
 
template<class U >
 WeakPtr (const WeakPtr< U > &rhs) noexcept
 Copy-construct from another weak pointer allowing implicit upcasting.
 
 WeakPtr (const SharedPtr< T > &rhs) noexcept
 Construct from a shared pointer.
 
 WeakPtr (T *ptr) noexcept
 Construct from a raw pointer.
 
 ~WeakPtr () noexcept
 Destruct. Release the weak reference to the object.
 
WeakPtr< T > & operator= (const SharedPtr< T > &rhs)
 Assign from a shared pointer.
 
WeakPtr< T > & operator= (const WeakPtr< T > &rhs)
 Assign from a weak pointer.
 
WeakPtr< T > & operator= (WeakPtr< T > &&rhs)
 Move-assign from another weak pointer.
 
template<class U >
WeakPtr< T > & operator= (const WeakPtr< U > &rhs)
 Assign from another weak pointer allowing implicit upcasting.
 
WeakPtr< T > & operator= (T *ptr)
 Assign from a raw pointer.
 
SharedPtr< T > Lock () const
 Convert to a shared pointer. If expired, return a null shared pointer.
 
T * Get () const
 Return raw pointer. If expired, return null.
 
T * operator-> () const
 Point to the object.
 
T & operator* () const
 Dereference the object.
 
T & operator[] (int index)
 Subscript the object if applicable.
 
template<class U >
bool operator== (const WeakPtr< U > &rhs) const
 Test for equality with another weak pointer.
 
template<class U >
bool operator!= (const WeakPtr< U > &rhs) const
 Test for inequality with another weak pointer.
 
template<class U >
bool operator< (const WeakPtr< U > &rhs) const
 Test for less than with another weak pointer.
 
 operator T* () const
 Convert to a raw pointer, null if the object is expired.
 
void Swap (WeakPtr< T > &rhs)
 Swap with another WeakPtr.
 
void Reset (T *ptr=nullptr)
 Reset with another pointer.
 
template<class U >
void StaticCast (const WeakPtr< U > &rhs)
 Perform a static cast from a weak pointer of another type.
 
template<class U >
void DynamicCast (const WeakPtr< U > &rhs)
 Perform a dynamic cast from a weak pointer of another type.
 
bool Null () const
 Check if the pointer is null.
 
bool NotNull () const
 Check if the pointer is not null.
 
int Refs () const
 Return the object's reference count, or 0 if null pointer or if object has expired.
 
int WeakRefs () const
 Return the object's weak reference count.
 
bool Expired () const
 Return whether the object has expired. If null pointer, always return true.
 
RefCountRefCountPtr () const
 Return pointer to the RefCount structure.
 
unsigned ToHash () const
 Return hash value for HashSet & HashMap.
 

Private Member Functions

void AddRef ()
 Add a weak reference to the object pointed to.
 
void ReleaseRef ()
 Release the weak reference. Delete the Refcount structure if necessary.
 

Private Attributes

T * ptr_
 Pointer to the object.
 
RefCountrefCount_
 Pointer to the RefCount structure.
 

Detailed Description

template<class T>
class Urho3D::WeakPtr< T >

Weak pointer template class with intrusive reference counting. Does not keep the object pointed to alive.


The documentation for this class was generated from the following file:
  • Source/Urho3D/Container/Ptr.h