CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::CountedPtr< T > Class Template Referencefinal

A retain-release type of smart pointer. More...

#include <CeresEngine/Foundation/SmartPtr.hpp>

Public Types

using ElementType = T
 The element type contained by the pointer.
 
using Pointer = T *
 A pointer to the reference counted object.
 
using Reference = T &
 A reference to the reference counted object.
 
using Counted = RefCounted< T >
 A compatible reference counter that calls delete after the reference counter reaches 0.
 

Public Member Functions

 CountedPtr () noexcept=default
 Creates a new null CountedPtr
 
 CountedPtr (const Pointer ptr) noexcept
 Creates a new CountedPtr from an existing reference counted object.
 
 CountedPtr (std::nullptr_t) noexcept
 Creates a new empty CountedPtr object.
 
 CountedPtr (AdoptPtrT, const Pointer aPtr) noexcept
 Creates a new CountedPtr from an existing reference counted object.
 
 CountedPtr (const CountedPtr &other) noexcept
 Creates a new CountedPtr by copying another.
 
template<typename U >
 CountedPtr (const CountedPtr< U > &other) noexcept
 Creates a new CountedPtr by copying another.
 
CountedPtroperator= (const CountedPtr &other) noexcept
 Assigns the CountedPtr by copying another.
 
template<typename U >
CountedPtroperator= (const CountedPtr< U > &other) noexcept
 Assigns the CountedPtr by copying another.
 
 CountedPtr (CountedPtr &&other) noexcept
 Creates a new CountedPtr by moving another.
 
template<typename U >
 CountedPtr (CountedPtr< U > &&other) noexcept
 Creates a new CountedPtr by copying another.
 
CountedPtroperator= (CountedPtr &&other) noexcept
 Assigns the CountedPtr by moving another.
 
template<typename U >
CountedPtroperator= (CountedPtr< U > &&other) noexcept
 Assigns the CountedPtr by copying another.
 
template<typename U >
CountedPtroperator= (U *aPtr) noexcept
 Assigns the CountedPtr by assigning a new pointer.
 
 ~CountedPtr () noexcept
 Destroys the CountedPtr.
 
Pointer get () const noexcept
 
Pointer operator-> () const noexcept
 
Reference operator* () const noexcept
 
 operator bool () const noexcept
 Checks if the pointer is not nullptr.
 
void reset () noexcept
 Resets the pointer by setting it to nullptr.
 
Pointer release () noexcept
 Releases the pointer from the CountedPtr.
 

Static Public Member Functions

static CountedPtr< Tadopt (T *const ptr)
 Creates a new CountedPtr from an existing reference counted object.
 

Private Types

using Trait = CountedPtrTrait< T >
 The CountedPtrTrait specialization for type T.
 

Private Member Functions

void set (Pointer newPtr) noexcept
 Sets a new value for the pointer.
 

Private Attributes

Pointer ptr = nullptr
 The raw-pointer to the reference counted object.
 

Friends

template<typename TT >
class CountedPtr
 
template<typename U1 , typename U2 >
bool operator== (const CountedPtr< U1 > &a, const CountedPtr< U2 > &b) noexcept
 Checks if both intrusive pointers represent the same object.
 
template<typename U1 , typename U2 >
bool operator!= (const CountedPtr< U1 > &a, const CountedPtr< U2 > &b) noexcept
 Checks if both intrusive pointers not represent the same object.
 
template<typename U1 , typename U2 >
bool operator== (const CountedPtr< U1 > &a, const U2 *b) noexcept
 Checks if both intrusive pointers represent the same object.
 
template<typename U1 , typename U2 >
bool operator!= (const CountedPtr< U1 > &a, const U2 *b) noexcept
 Checks if both intrusive pointers not represent the same object.
 
template<typename U1 , typename U2 >
bool operator== (const U1 *a, const CountedPtr< U2 > &b) noexcept
 Checks if both intrusive pointers represent the same object.
 
template<typename U1 , typename U2 >
bool operator!= (const U1 *a, const CountedPtr< U2 > &b) noexcept
 Checks if both intrusive pointers not represent the same object.
 
template<typename U >
bool operator== (const CountedPtr< U > &a, std::nullptr_t) noexcept
 Checks if the intrusive pointer a is nullptr.
 
template<typename U >
bool operator!= (const CountedPtr< U > &a, std::nullptr_t) noexcept
 Checks if the intrusive pointer a is not nullptr.
 

Detailed Description

template<typename T>
class CeresEngine::CountedPtr< T >

A retain-release type of smart pointer.

When creating a new CountedPtr the pointer is retained and when destructing the CountedPtr it is released.

It is responsibility of the implementation of T to release the memory once all retain calls have been released. This behaviour can be be automatically applied by inheriting from RefCounted<T>.

By default, CountedPtr invokes T::retain() and T::release(). This behaviour can be changed by specializing CountedPtrTrait<T>.

Template Parameters
Tthe object type managed by the smart pointer

Member Typedef Documentation

◆ Counted

template<typename T >
using CeresEngine::CountedPtr< T >::Counted = RefCounted<T>

A compatible reference counter that calls delete after the reference counter reaches 0.

◆ ElementType

template<typename T >
using CeresEngine::CountedPtr< T >::ElementType = T

The element type contained by the pointer.

◆ Pointer

template<typename T >
using CeresEngine::CountedPtr< T >::Pointer = T*

A pointer to the reference counted object.

◆ Reference

template<typename T >
using CeresEngine::CountedPtr< T >::Reference = T&

A reference to the reference counted object.

◆ Trait

template<typename T >
using CeresEngine::CountedPtr< T >::Trait = CountedPtrTrait<T>
private

The CountedPtrTrait specialization for type T.

Constructor & Destructor Documentation

◆ CountedPtr() [1/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( )
defaultnoexcept

Creates a new null CountedPtr

◆ CountedPtr() [2/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( const Pointer  ptr)
inlinenoexcept

Creates a new CountedPtr from an existing reference counted object.

Parameters
ptrThe pointer to create a new ref from

◆ CountedPtr() [3/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( std::nullptr_t  )
inlinenoexcept

Creates a new empty CountedPtr object.

◆ CountedPtr() [4/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( AdoptPtrT  ,
const Pointer  aPtr 
)
inlinenoexcept

Creates a new CountedPtr from an existing reference counted object.

Parameters
aPtrThe pointer to create a new ref from

◆ CountedPtr() [5/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( const CountedPtr< T > &  other)
inlinenoexcept

Creates a new CountedPtr by copying another.

Parameters
otherThe ref to copy from

◆ CountedPtr() [6/8]

template<typename T >
template<typename U >
CeresEngine::CountedPtr< T >::CountedPtr ( const CountedPtr< U > &  other)
inlinenoexcept

Creates a new CountedPtr by copying another.

Parameters
otherThe ref to copy from

◆ CountedPtr() [7/8]

template<typename T >
CeresEngine::CountedPtr< T >::CountedPtr ( CountedPtr< T > &&  other)
inlinenoexcept

Creates a new CountedPtr by moving another.

Parameters
otherThe ref to move from

◆ CountedPtr() [8/8]

template<typename T >
template<typename U >
CeresEngine::CountedPtr< T >::CountedPtr ( CountedPtr< U > &&  other)
inlinenoexcept

Creates a new CountedPtr by copying another.

Parameters
otherThe ref to copy from

◆ ~CountedPtr()

template<typename T >
CeresEngine::CountedPtr< T >::~CountedPtr ( )
inlinenoexcept

Destroys the CountedPtr.

Member Function Documentation

◆ adopt()

template<typename T >
static CountedPtr< T > CeresEngine::CountedPtr< T >::adopt ( T *const  ptr)
inlinestatic

Creates a new CountedPtr from an existing reference counted object.

◆ get()

template<typename T >
Pointer CeresEngine::CountedPtr< T >::get ( ) const
inlinenoexcept
Returns
A raw pointer to the object

◆ operator bool()

template<typename T >
CeresEngine::CountedPtr< T >::operator bool ( ) const
inlineexplicitnoexcept

Checks if the pointer is not nullptr.

Returns
true if the reference is not nullptr.

◆ operator*()

template<typename T >
Reference CeresEngine::CountedPtr< T >::operator* ( ) const
inlinenoexcept
Returns
A reference to the object

◆ operator->()

template<typename T >
Pointer CeresEngine::CountedPtr< T >::operator-> ( ) const
inlinenoexcept
Returns
A raw pointer to the object

◆ operator=() [1/5]

template<typename T >
CountedPtr & CeresEngine::CountedPtr< T >::operator= ( const CountedPtr< T > &  other)
inlinenoexcept

Assigns the CountedPtr by copying another.

Parameters
otherThe ref to copy from
Returns
*this

◆ operator=() [2/5]

template<typename T >
template<typename U >
CountedPtr & CeresEngine::CountedPtr< T >::operator= ( const CountedPtr< U > &  other)
inlinenoexcept

Assigns the CountedPtr by copying another.

Parameters
otherThe ref to copy from
Returns
*this

◆ operator=() [3/5]

template<typename T >
CountedPtr & CeresEngine::CountedPtr< T >::operator= ( CountedPtr< T > &&  other)
inlinenoexcept

Assigns the CountedPtr by moving another.

Parameters
otherThe ref to move from
Returns
*this

◆ operator=() [4/5]

template<typename T >
template<typename U >
CountedPtr & CeresEngine::CountedPtr< T >::operator= ( CountedPtr< U > &&  other)
inlinenoexcept

Assigns the CountedPtr by copying another.

Parameters
otherThe ref to copy from
Returns
*this

◆ operator=() [5/5]

template<typename T >
template<typename U >
CountedPtr & CeresEngine::CountedPtr< T >::operator= ( U aPtr)
inlinenoexcept

Assigns the CountedPtr by assigning a new pointer.

Parameters
aPtrThe pointer to be assigned
Returns
*this

◆ release()

template<typename T >
Pointer CeresEngine::CountedPtr< T >::release ( )
inlinenoexcept

Releases the pointer from the CountedPtr.

Resets the pointer without decrementing the reference count and returns the pointer.

Returns
The previous pointer value

◆ reset()

template<typename T >
void CeresEngine::CountedPtr< T >::reset ( )
inlinenoexcept

Resets the pointer by setting it to nullptr.

◆ set()

template<typename T >
void CeresEngine::CountedPtr< T >::set ( Pointer  newPtr)
inlineprivatenoexcept

Sets a new value for the pointer.

Parameters
newPtrThe new pointer to be set

Friends And Related Symbol Documentation

◆ CountedPtr

template<typename T >
template<typename TT >
friend class CountedPtr
friend

◆ operator!= [1/4]

template<typename T >
template<typename U >
bool operator!= ( const CountedPtr< U > &  a,
std::nullptr_t   
)
friend

Checks if the intrusive pointer a is not nullptr.

Template Parameters
Uthe object type
Parameters
aThe first operand
Returns
true if a is not nullptr

◆ operator!= [2/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator!= ( const CountedPtr< U1 > &  a,
const CountedPtr< U2 > &  b 
)
friend

Checks if both intrusive pointers not represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b do not represent the same object

◆ operator!= [3/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator!= ( const CountedPtr< U1 > &  a,
const U2 b 
)
friend

Checks if both intrusive pointers not represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b do not represent the same object

◆ operator!= [4/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator!= ( const U1 a,
const CountedPtr< U2 > &  b 
)
friend

Checks if both intrusive pointers not represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b do not represent the same object

◆ operator== [1/4]

template<typename T >
template<typename U >
bool operator== ( const CountedPtr< U > &  a,
std::nullptr_t   
)
friend

Checks if the intrusive pointer a is nullptr.

Template Parameters
Uthe object type
Parameters
aThe first operand
Returns
true if a is nullptr

◆ operator== [2/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator== ( const CountedPtr< U1 > &  a,
const CountedPtr< U2 > &  b 
)
friend

Checks if both intrusive pointers represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b represent the same object

◆ operator== [3/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator== ( const CountedPtr< U1 > &  a,
const U2 b 
)
friend

Checks if both intrusive pointers represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b represent the same object

◆ operator== [4/4]

template<typename T >
template<typename U1 , typename U2 >
bool operator== ( const U1 a,
const CountedPtr< U2 > &  b 
)
friend

Checks if both intrusive pointers represent the same object.

Template Parameters
U1the first object type
U2the second object type
Parameters
aThe first operand
bThe second operand
Returns
true if both a and b represent the same object

Member Data Documentation

◆ ptr

template<typename T >
Pointer CeresEngine::CountedPtr< T >::ptr = nullptr
private

The raw-pointer to the reference counted object.


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