UraniumCompute 0.1.0
A GPU accelerated parallel task scheduler
UN::Ptr< T > Class Template Referencefinal

Shared smart pointer implementation that uses reference counting. More...

#include <Ptr.h>

Public Types

using ObjectType = T
 

Public Member Functions

 Ptr () noexcept
 Create a null reference counted pointer.
 
 Ptr (T *pObject) noexcept
 Create a pointer that points to the specified object. More...
 
 Ptr (const Ptr &other) noexcept
 Copy a pointer (adds a strong reference to underlying object). More...
 
template<class T1 >
 Ptr (const Ptr< T1 > &other) noexcept
 Copy a pointer (adds a strong reference to underlying object). More...
 
 Ptr (Ptr &&other) noexcept
 Move a pointer (doesn't add a strong reference to underlying object). More...
 
void Swap (Ptr &other)
 Swap raw pointers of two objects without incrementing and decrementing ref-counters.
 
Ptroperator= (const Ptr &other)
 Copy a pointer (adds a strong reference to underlying object). More...
 
Ptroperator= (Ptr &&other) noexcept
 Move a pointer (doesn't add a strong reference to underlying object). More...
 
void Reset ()
 Set a pointer to null.
 
T *const * GetAddressOf () const
 Get pointer to the underlying pointer.
 
T ** GetAddressOf ()
 Get pointer to the underlying pointer.
 
T ** ReleaseAndGetAddressOf ()
 Release a strong reference and get pointer to the stored pointer. More...
 
void Attach (T *pObject)
 Attach a pointer and do not add strong reference.
 
T * Detach ()
 Forget object and don't free it automatically. More...
 
T * Get () const
 Get underlying raw pointer.
 
template<class TDest >
std::enable_if_t< std::is_base_of_v< TDest, T >, TDest * > As () const
 Get underlying raw pointer and cast it.
 
template<class TDest >
std::enable_if_t< std::is_base_of_v< T, TDest > &&!std::is_same_v< T, TDest >, TDest * > As () const
 Get underlying raw pointer and cast it.
 
Internal::PtrRef< Ptr< T > > operator& ()
 
T & operator* ()
 
T * operator-> ()
 
const T & operator* () const
 
const T * operator-> () const
 
 operator bool () const
 

Detailed Description

template<class T>
class UN::Ptr< T >

Shared smart pointer implementation that uses reference counting.

See ReferenceCounter for more information.

Template Parameters
T- Type of object to hold.
Note
T must inherit from IObject.
See also
ReferenceCounter

Constructor & Destructor Documentation

◆ Ptr() [1/4]

template<class T >
UN::Ptr< T >::Ptr ( T *  pObject)
inlinenoexcept

Create a pointer that points to the specified object.

Parameters
pObject- The pointer to object.
Note
It is valid to use this constructor on a raw object since the object itself stores The pointer to ReferenceCounter instance.

◆ Ptr() [2/4]

template<class T >
UN::Ptr< T >::Ptr ( const Ptr< T > &  other)
inlinenoexcept

Copy a pointer (adds a strong reference to underlying object).

Parameters
other- Pointer to copy.

◆ Ptr() [3/4]

template<class T >
template<class T1 >
UN::Ptr< T >::Ptr ( const Ptr< T1 > &  other)
inlinenoexcept

Copy a pointer (adds a strong reference to underlying object).

Parameters
other- Pointer to copy.

◆ Ptr() [4/4]

template<class T >
UN::Ptr< T >::Ptr ( Ptr< T > &&  other)
inlinenoexcept

Move a pointer (doesn't add a strong reference to underlying object).

Parameters
other- Pointer to move.

Member Function Documentation

◆ Detach()

template<class T >
T * UN::Ptr< T >::Detach ( )
inline

Forget object and don't free it automatically.

Can be useful to send an object to managed program.

◆ operator=() [1/2]

template<class T >
Ptr & UN::Ptr< T >::operator= ( const Ptr< T > &  other)
inline

Copy a pointer (adds a strong reference to underlying object).

Parameters
other- Pointer to copy.

◆ operator=() [2/2]

template<class T >
Ptr & UN::Ptr< T >::operator= ( Ptr< T > &&  other)
inlinenoexcept

Move a pointer (doesn't add a strong reference to underlying object).

Parameters
other- Pointer to move.

◆ ReleaseAndGetAddressOf()

template<class T >
T ** UN::Ptr< T >::ReleaseAndGetAddressOf ( )
inline

Release a strong reference and get pointer to the stored pointer.

It is the same as using unary '&' operator.


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