XII Release 0.1.0
Loading...
Searching...
No Matches
xiiSharedPtr< T > Class Template Reference

A Shared ptr manages a shared object and destroys that object when no one references it anymore. The managed object must derive from xiiRefCounted. More...

#include <SharedPtr.h>

Public Member Functions

 XII_DECLARE_MEM_RELOCATABLE_TYPE ()
 
 xiiSharedPtr ()
 Creates an empty shared ptr.
 
template<typename U>
 xiiSharedPtr (const xiiInternal::NewInstance< U > &instance)
 Creates a shared ptr from a freshly created instance through XII_NEW or XII_DEFAULT_NEW.
 
template<typename U>
 xiiSharedPtr (U *pInstance, xiiAllocatorBase *pAllocator)
 Creates a shared ptr from a pointer and an allocator. The passed allocator will be used to destroy the instance when the shared ptr goes out of scope.
 
 xiiSharedPtr (const xiiSharedPtr< T > &other)
 Copy constructs a shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U>
 xiiSharedPtr (const xiiSharedPtr< U > &other)
 Copy constructs a shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U>
 xiiSharedPtr (xiiSharedPtr< U > &&other)
 Move constructs a shared ptr from another. The other shared ptr will be empty afterwards.
 
template<typename U>
 xiiSharedPtr (xiiUniquePtr< U > &&other)
 Move constructs a shared ptr from a unique ptr. The unique ptr will be empty afterwards.
 
 xiiSharedPtr (std::nullptr_t)
 Initialization with nullptr to be able to return nullptr in functions that return shared ptr.
 
 ~xiiSharedPtr ()
 Destroys the managed object using the stored allocator if no one else references it anymore.
 
template<typename U>
xiiSharedPtr< T > & operator= (const xiiInternal::NewInstance< U > &instance)
 Sets the shared ptr from a freshly created instance through XII_NEW or XII_DEFAULT_NEW.
 
xiiSharedPtr< T > & operator= (const xiiSharedPtr< T > &other)
 Sets the shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U>
xiiSharedPtr< T > & operator= (const xiiSharedPtr< U > &other)
 Sets the shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U>
xiiSharedPtr< T > & operator= (xiiSharedPtr< U > &&other)
 Move assigns a shared ptr from another. The other shared ptr will be empty afterwards.
 
template<typename U>
xiiSharedPtr< T > & operator= (xiiUniquePtr< U > &&other)
 Move assigns a shared ptr from a unique ptr. The unique ptr will be empty afterwards.
 
xiiSharedPtr< T > & operator= (std::nullptr_t)
 Assigns a nullptr to the shared ptr. Same as Reset.
 
T * Borrow () const
 Borrows the managed object. The shared ptr stays unmodified.
 
void Clear ()
 Destroys the managed object if no one else references it anymore and resets the shared ptr.
 
T & operator* () const
 Provides access to the managed object.
 
T * operator-> () const
 Provides access to the managed object.
 
 operator const T * () const
 Provides access to the managed object.
 
 operator T* ()
 Provides access to the managed object.
 
 operator bool () const
 Returns true if there is managed object and false if the shared ptr is empty.
 
bool operator== (const xiiSharedPtr< T > &rhs) const
 Compares the shared ptr against another shared ptr.
 
std::strong_ordering operator<=> (const xiiSharedPtr< T > &rhs) const
 Compares the shared ptr against another shared ptr.
 
bool operator== (std::nullptr_t) const
 Compares the shared ptr against nullptr.
 
std::strong_ordering operator<=> (std::nullptr_t) const
 Compares the shared ptr against nullptr.
 
template<typename DERIVED>
xiiSharedPtr< DERIVED > Downcast () const
 Returns a copy of this, as a xiiSharedPtr<DERIVED>. Downcasts the stored pointer (using static_cast).
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr (const xiiInternal::NewInstance< U > &instance)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr (U *pInstance, xiiAllocatorBase *pAllocator)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr (const xiiSharedPtr< U > &other)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr (xiiSharedPtr< U > &&other)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr (xiiUniquePtr< U > &&other)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr< T > & operator= (const xiiInternal::NewInstance< U > &instance)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr< T > & operator= (const xiiSharedPtr< U > &other)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr< T > & operator= (xiiSharedPtr< U > &&other)
 
template<typename U>
XII_ALWAYS_INLINE xiiSharedPtr< T > & operator= (xiiUniquePtr< U > &&other)
 

Detailed Description

template<typename T>
class xiiSharedPtr< T >

A Shared ptr manages a shared object and destroys that object when no one references it anymore. The managed object must derive from xiiRefCounted.

Member Function Documentation

◆ Downcast()

template<typename T>
template<typename DERIVED>
xiiSharedPtr< DERIVED > xiiSharedPtr< T >::Downcast ( ) const
inline

Returns a copy of this, as a xiiSharedPtr<DERIVED>. Downcasts the stored pointer (using static_cast).

Does not check whether the cast would be valid, that is all your responsibility.


The documentation for this class was generated from the following files: