|
CeresEngine 0.2.0
A game development framework
|
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. | |
| CountedPtr & | operator= (const CountedPtr &other) noexcept |
Assigns the CountedPtr by copying another. | |
| template<typename U > | |
| CountedPtr & | operator= (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. | |
| CountedPtr & | operator= (CountedPtr &&other) noexcept |
Assigns the CountedPtr by moving another. | |
| template<typename U > | |
| CountedPtr & | operator= (CountedPtr< U > &&other) noexcept |
Assigns the CountedPtr by copying another. | |
| template<typename U > | |
| CountedPtr & | operator= (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< T > | adopt (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. | |
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>.
| T | the object type managed by the smart pointer |
| using CeresEngine::CountedPtr< T >::Counted = RefCounted<T> |
A compatible reference counter that calls delete after the reference counter reaches 0.
The element type contained by the pointer.
A pointer to the reference counted object.
A reference to the reference counted object.
|
private |
The CountedPtrTrait specialization for type T.
|
defaultnoexcept |
Creates a new null CountedPtr
Creates a new CountedPtr from an existing reference counted object.
| ptr | The pointer to create a new ref from |
|
inlinenoexcept |
Creates a new empty CountedPtr object.
|
inlinenoexcept |
Creates a new CountedPtr from an existing reference counted object.
| aPtr | The pointer to create a new ref from |
|
inlinenoexcept |
Creates a new CountedPtr by copying another.
| other | The ref to copy from |
|
inlinenoexcept |
Creates a new CountedPtr by copying another.
| other | The ref to copy from |
|
inlinenoexcept |
Creates a new CountedPtr by moving another.
| other | The ref to move from |
|
inlinenoexcept |
Creates a new CountedPtr by copying another.
| other | The ref to copy from |
|
inlinenoexcept |
Destroys the CountedPtr.
|
inlinestatic |
Creates a new CountedPtr from an existing reference counted object.
|
inlinenoexcept |
|
inlineexplicitnoexcept |
Checks if the pointer is not nullptr.
true if the reference is not nullptr.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Assigns the CountedPtr by assigning a new pointer.
| aPtr | The pointer to be assigned |
*this
|
inlinenoexcept |
Releases the pointer from the CountedPtr.
Resets the pointer without decrementing the reference count and returns the pointer.
|
inlinenoexcept |
Resets the pointer by setting it to nullptr.
|
inlineprivatenoexcept |
Sets a new value for the pointer.
| newPtr | The new pointer to be set |
|
friend |
Checks if the intrusive pointer a is not nullptr.
| U | the object type |
| a | The first operand |
true if a is not nullptr
|
friend |
Checks if both intrusive pointers not represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b do not represent the same object Checks if both intrusive pointers not represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b do not represent the same object Checks if both intrusive pointers not represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b do not represent the same object
|
friend |
Checks if the intrusive pointer a is nullptr.
| U | the object type |
| a | The first operand |
true if a is nullptr
|
friend |
Checks if both intrusive pointers represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b represent the same object Checks if both intrusive pointers represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b represent the same object Checks if both intrusive pointers represent the same object.
| U1 | the first object type |
| U2 | the second object type |
| a | The first operand |
| b | The second operand |
true if both a and b represent the same object The raw-pointer to the reference counted object.