Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
AeonGames::UniqueAnyPtr Class Reference

A type-erased owning smart pointer with unique ownership semantics. More...

#include <aeongames/UniqueAnyPtr.hpp>

Collaboration diagram for AeonGames::UniqueAnyPtr:
Collaboration graph

Public Member Functions

void Swap (UniqueAnyPtr &aUniqueAnyPtr) noexcept
 Swaps the contents of this pointer with another.
Creation and Destruction.
 UniqueAnyPtr () noexcept=default
 Default constructor.
 UniqueAnyPtr (std::nullptr_t) noexcept
 Constructs an empty UniqueAnyPtr from nullptr.
 UniqueAnyPtr (const UniqueAnyPtr &aUniqueResource)=delete
UniqueAnyPtroperator= (const UniqueAnyPtr &aUniqueResource)=delete
 UniqueAnyPtr (UniqueAnyPtr &&aUniqueAnyPtr) noexcept
 Move constructor.
template<class T>
 UniqueAnyPtr (std::unique_ptr< T > &&aUniquePointer) noexcept
 Constructs from a std::unique_ptr, taking ownership.
template<class T>
 UniqueAnyPtr (T *aPointer) noexcept
 Constructs from a raw pointer, taking ownership.
template<class T>
 UniqueAnyPtr (T &&aValue) noexcept
 Constructs by moving a value into a new heap allocation.
 ~UniqueAnyPtr ()
 Destructor.

Assignment

UniqueAnyPtroperator= (UniqueAnyPtr &&aUniqueAnyPtr) noexcept
 Move assignment operator.
template<class T>
UniqueAnyPtroperator= (std::unique_ptr< T > &&aUniquePointer) noexcept
 Assigns from a std::unique_ptr, taking ownership.
template<class T>
UniqueAnyPtroperator= (T *aPointer) noexcept
 Assigns from a raw pointer, taking ownership.
const void * GetRaw () const
 Returns a const void pointer to the owned object.
template<class T>
T * Get () const
 Returns a typed pointer to the owned object (const overload).
template<class T>
T * Get ()
 Returns a typed pointer to the owned object (non-const overload).
void * ReleaseRaw ()
 Releases ownership and returns the raw void pointer.
template<class T>
T * Release ()
 Releases ownership and returns a typed pointer.
template<class T>
std::unique_ptr< T > UniquePointer ()
 Releases ownership and returns a std::unique_ptr.
void Reset ()
 Destroys the owned object and resets to empty state.
const std::type_info & GetTypeInfo () const
 Returns the std::type_info of the stored type.
template<class T>
bool HasType () const
 Checks whether the stored object is of type T.

Detailed Description

A type-erased owning smart pointer with unique ownership semantics.

Stores a pointer to any type along with a deleter, providing type-safe access and automatic cleanup. Similar to std::unique_ptr but can hold any type.

Definition at line 30 of file UniqueAnyPtr.hpp.

Constructor & Destructor Documentation

◆ UniqueAnyPtr() [1/6]

AeonGames::UniqueAnyPtr::UniqueAnyPtr ( )
defaultnoexcept

Default constructor.

Creates an empty UniqueAnyPtr.

◆ UniqueAnyPtr() [2/6]

AeonGames::UniqueAnyPtr::UniqueAnyPtr ( std::nullptr_t )
inlinenoexcept

Constructs an empty UniqueAnyPtr from nullptr.

Definition at line 51 of file UniqueAnyPtr.hpp.

◆ UniqueAnyPtr() [3/6]

AeonGames::UniqueAnyPtr::UniqueAnyPtr ( UniqueAnyPtr && aUniqueAnyPtr)
inlinenoexcept

Move constructor.

Transfers ownership from another UniqueAnyPtr.

Parameters
aUniqueAnyPtrThe source pointer to move from.

Definition at line 60 of file UniqueAnyPtr.hpp.

◆ UniqueAnyPtr() [4/6]

template<class T>
AeonGames::UniqueAnyPtr::UniqueAnyPtr ( std::unique_ptr< T > && aUniquePointer)
inlinenoexcept

Constructs from a std::unique_ptr, taking ownership.

Template Parameters
TThe pointed-to type.
Parameters
aUniquePointerThe unique_ptr to take ownership from.

Definition at line 73 of file UniqueAnyPtr.hpp.

◆ UniqueAnyPtr() [5/6]

template<class T>
AeonGames::UniqueAnyPtr::UniqueAnyPtr ( T * aPointer)
inlinenoexcept

Constructs from a raw pointer, taking ownership.

Template Parameters
TThe pointed-to type.
Parameters
aPointerRaw pointer to take ownership of.

Definition at line 81 of file UniqueAnyPtr.hpp.

◆ UniqueAnyPtr() [6/6]

template<class T>
AeonGames::UniqueAnyPtr::UniqueAnyPtr ( T && aValue)
inlinenoexcept

Constructs by moving a value into a new heap allocation.

Template Parameters
TThe value type.
Parameters
aValueThe value to move.

Definition at line 89 of file UniqueAnyPtr.hpp.

◆ ~UniqueAnyPtr()

AeonGames::UniqueAnyPtr::~UniqueAnyPtr ( )
inline

Destructor.

Deletes the owned object if present.

Definition at line 93 of file UniqueAnyPtr.hpp.

Member Function Documentation

◆ Get() [1/2]

template<class T>
T * AeonGames::UniqueAnyPtr::Get ( )
inline

Returns a typed pointer to the owned object (non-const overload).

Template Parameters
TThe expected type.
Returns
Pointer to the object, or nullptr if empty.
Exceptions
std::runtime_errorIf the stored type does not match T.

Definition at line 182 of file UniqueAnyPtr.hpp.

◆ Get() [2/2]

template<class T>
T * AeonGames::UniqueAnyPtr::Get ( ) const
inline

Returns a typed pointer to the owned object (const overload).

Template Parameters
TThe expected type.
Returns
Pointer to the object, or nullptr if empty.
Exceptions
std::runtime_errorIf the stored type does not match T.

Definition at line 162 of file UniqueAnyPtr.hpp.

◆ GetRaw()

const void * AeonGames::UniqueAnyPtr::GetRaw ( ) const
inline

Returns a const void pointer to the owned object.

Returns
Const void pointer to the stored object.

Definition at line 152 of file UniqueAnyPtr.hpp.

◆ GetTypeInfo()

const std::type_info & AeonGames::UniqueAnyPtr::GetTypeInfo ( ) const
inline

Returns the std::type_info of the stored type.

Returns
Reference to the type_info, or typeid(nullptr) if empty.

Definition at line 235 of file UniqueAnyPtr.hpp.

◆ HasType()

template<class T>
bool AeonGames::UniqueAnyPtr::HasType ( ) const
inline

Checks whether the stored object is of type T.

Template Parameters
TThe type to check against.
Returns
True if the stored type matches T.

Definition at line 249 of file UniqueAnyPtr.hpp.

◆ operator=() [1/3]

template<class T>
UniqueAnyPtr & AeonGames::UniqueAnyPtr::operator= ( std::unique_ptr< T > && aUniquePointer)
inlinenoexcept

Assigns from a std::unique_ptr, taking ownership.

Template Parameters
TThe pointed-to type.
Parameters
aUniquePointerThe unique_ptr to take ownership from.
Returns
Reference to this.

Definition at line 120 of file UniqueAnyPtr.hpp.

◆ operator=() [2/3]

template<class T>
UniqueAnyPtr & AeonGames::UniqueAnyPtr::operator= ( T * aPointer)
inlinenoexcept

Assigns from a raw pointer, taking ownership.

Template Parameters
TThe pointed-to type.
Parameters
aPointerRaw pointer to take ownership of.
Returns
Reference to this.

Definition at line 137 of file UniqueAnyPtr.hpp.

◆ operator=() [3/3]

UniqueAnyPtr & AeonGames::UniqueAnyPtr::operator= ( UniqueAnyPtr && aUniqueAnyPtr)
inlinenoexcept

Move assignment operator.

Transfers ownership from another UniqueAnyPtr.

Parameters
aUniqueAnyPtrThe source pointer to move from.
Returns
Reference to this.

Definition at line 108 of file UniqueAnyPtr.hpp.

◆ Release()

template<class T>
T * AeonGames::UniqueAnyPtr::Release ( )
inline

Releases ownership and returns a typed pointer.

Template Parameters
TThe expected type.
Returns
The previously owned pointer cast to T*.
Exceptions
std::runtime_errorIf the stored type does not match T.

Definition at line 204 of file UniqueAnyPtr.hpp.

◆ ReleaseRaw()

void * AeonGames::UniqueAnyPtr::ReleaseRaw ( )
inline

Releases ownership and returns the raw void pointer.

Returns
The previously owned pointer.

Definition at line 191 of file UniqueAnyPtr.hpp.

◆ Reset()

void AeonGames::UniqueAnyPtr::Reset ( )
inline

Destroys the owned object and resets to empty state.

Definition at line 226 of file UniqueAnyPtr.hpp.

◆ Swap()

void AeonGames::UniqueAnyPtr::Swap ( UniqueAnyPtr & aUniqueAnyPtr)
inlinenoexcept

Swaps the contents of this pointer with another.

Parameters
aUniqueAnyPtrThe other UniqueAnyPtr to swap with.

Definition at line 41 of file UniqueAnyPtr.hpp.

◆ UniquePointer()

template<class T>
std::unique_ptr< T > AeonGames::UniqueAnyPtr::UniquePointer ( )
inline

Releases ownership and returns a std::unique_ptr.

Template Parameters
TThe expected type.
Returns
A std::unique_ptr owning the released object.
Exceptions
std::runtime_errorIf the stored type does not match T.

Definition at line 220 of file UniqueAnyPtr.hpp.


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