Plasma Engine  2.0
Loading...
Searching...
No Matches
plSharedPtr< 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 plRefCounted. More...

#include <SharedPtr.h>

Public Member Functions

 PL_DECLARE_MEM_RELOCATABLE_TYPE ()
 
 plSharedPtr ()
 Creates an empty shared ptr.
 
template<typename U >
 plSharedPtr (const plInternal::NewInstance< U > &instance)
 Creates a shared ptr from a freshly created instance through PL_NEW or PL_DEFAULT_NEW.
 
template<typename U >
 plSharedPtr (U *pInstance, plAllocator *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.
 
 plSharedPtr (const plSharedPtr< T > &other)
 Copy constructs a shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U >
 plSharedPtr (const plSharedPtr< U > &other)
 Copy constructs a shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U >
 plSharedPtr (plSharedPtr< U > &&other)
 Move constructs a shared ptr from another. The other shared ptr will be empty afterwards.
 
template<typename U >
 plSharedPtr (plUniquePtr< U > &&other)
 Move constructs a shared ptr from a unique ptr. The unique ptr will be empty afterwards.
 
 plSharedPtr (std::nullptr_t)
 Initialization with nullptr to be able to return nullptr in functions that return shared ptr.
 
 ~plSharedPtr ()
 Destroys the managed object using the stored allocator if no one else references it anymore.
 
template<typename U >
plSharedPtr< T > & operator= (const plInternal::NewInstance< U > &instance)
 Sets the shared ptr from a freshly created instance through PL_NEW or PL_DEFAULT_NEW.
 
plSharedPtr< T > & operator= (const plSharedPtr< T > &other)
 Sets the shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U >
plSharedPtr< T > & operator= (const plSharedPtr< U > &other)
 Sets the shared ptr from another. Both will hold a reference to the managed object afterwards.
 
template<typename U >
plSharedPtr< T > & operator= (plSharedPtr< U > &&other)
 Move assigns a shared ptr from another. The other shared ptr will be empty afterwards.
 
template<typename U >
plSharedPtr< T > & operator= (plUniquePtr< U > &&other)
 Move assigns a shared ptr from a unique ptr. The unique ptr will be empty afterwards.
 
plSharedPtr< 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 plSharedPtr< T > &rhs) const
 Compares the shared ptr against another shared ptr.
 
bool operator!= (const plSharedPtr< T > &rhs) const
 
bool operator< (const plSharedPtr< T > &rhs) const
 
bool operator<= (const plSharedPtr< T > &rhs) const
 
bool operator> (const plSharedPtr< T > &rhs) const
 
bool operator>= (const plSharedPtr< T > &rhs) const
 
bool operator== (std::nullptr_t) const
 Compares the shared ptr against nullptr.
 
bool operator!= (std::nullptr_t) const
 
bool operator< (std::nullptr_t) const
 
bool operator<= (std::nullptr_t) const
 
bool operator> (std::nullptr_t) const
 
bool operator>= (std::nullptr_t) const
 
template<typename DERIVED >
plSharedPtr< DERIVED > Downcast () const
 Returns a copy of this, as an plSharedPtr<DERIVED>. Downcasts the stored pointer (using static_cast).
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr (const plInternal::NewInstance< U > &instance)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr (U *pInstance, plAllocator *pAllocator)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr (const plSharedPtr< U > &other)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr (plSharedPtr< U > &&other)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr (plUniquePtr< U > &&other)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr< T > & operator= (const plInternal::NewInstance< U > &instance)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr< T > & operator= (const plSharedPtr< U > &other)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr< T > & operator= (plSharedPtr< U > &&other)
 
template<typename U >
PL_ALWAYS_INLINE plSharedPtr< T > & operator= (plUniquePtr< U > &&other)
 

Detailed Description

template<typename T>
class plSharedPtr< T >

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

Member Function Documentation

◆ Downcast()

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

Returns a copy of this, as an plSharedPtr<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: