Skip to main content

ErasedUnique Struct

Type-erased unique ownership wrapper. More...

Declaration​

struct helios::engine::core::memory::ErasedUnique { ... }

Public Constructors Index​

ErasedUnique ()=default

Default constructor. Creates an empty (non-owning) instance. More...

template <class T>
ErasedUnique (std::unique_ptr< T > p) noexcept

Constructs from a unique_ptr, taking ownership. More...

ErasedUnique (ErasedUnique &&obj) noexcept

Move constructor. Transfers ownership. More...

Public Destructor Index​

~ErasedUnique ()

Destructor. Destroys the owned object if present. More...

Public Operators Index​

ErasedUnique &operator= (ErasedUnique &&obj) noexcept

Move assignment. Transfers ownership after releasing current. More...

Public Member Functions Index​

voidreset () noexcept

Destroys the owned object and resets to empty. More...

Public Member Attributes Index​

void *ptr = nullptr

Raw pointer to the owned object. More...

void(*destroy)(void *) noexcept = nullptr

Stateless deleter that knows the concrete type. More...

Description​

Type-erased unique ownership wrapper.

ErasedUnique provides unique_ptr-like ownership semantics without requiring a common base class or virtual destructor. It stores a void* and a stateless deleter function pointer, totaling 16 bytes.

Used by ResourceRegistry to store heterogeneous resource types (Managers, CommandBuffers) in a single owning collection without vtable overhead for destruction.

Definition at line 31 of file ErasedUnique.ixx.

Public Constructors​

ErasedUnique()​

helios::engine::core::memory::ErasedUnique::ErasedUnique ()
default

Default constructor. Creates an empty (non-owning) instance.

Definition at line 46 of file ErasedUnique.ixx.

ErasedUnique()​

template <class T>
helios::engine::core::memory::ErasedUnique::ErasedUnique (std::unique_ptr< T > p)
inline explicit noexcept

Constructs from a unique_ptr, taking ownership.

Releases the unique_ptr and captures a typed deleter.

Template Parameters
T

The owned type.

Parameters
p

The unique_ptr to take ownership from.

Definition at line 58 of file ErasedUnique.ixx.

58 explicit ErasedUnique(std::unique_ptr<T> p) noexcept
59 : ptr(p.release()),
60 destroy([](void* q) noexcept { delete static_cast<T*>(q); })
61 {}

Reference helios::engine::core::registerComponents.

ErasedUnique()​

helios::engine::core::memory::ErasedUnique::ErasedUnique (ErasedUnique && obj)
inline noexcept

Move constructor. Transfers ownership.

Parameters
obj

The source instance (nulled after move).

Definition at line 68 of file ErasedUnique.ixx.

69 obj.ptr = nullptr;
70 obj.destroy = nullptr;
71 }

Reference helios::engine::core::registerComponents.

Public Destructor​

~ErasedUnique()​

helios::engine::core::memory::ErasedUnique::~ErasedUnique ()
inline

Destructor. Destroys the owned object if present.

Definition at line 93 of file ErasedUnique.ixx.

Reference reset.

Public Operators​

operator=()​

ErasedUnique & helios::engine::core::memory::ErasedUnique::operator= (ErasedUnique && obj)
inline noexcept

Move assignment. Transfers ownership after releasing current.

Parameters
obj

The source instance (nulled after move).

Returns

Reference to this instance.

Definition at line 80 of file ErasedUnique.ixx.

81 if (this != &obj) {
82 reset();
83 ptr = obj.ptr; destroy = obj.destroy;
84 obj.ptr = nullptr;
85 obj.destroy = nullptr;
86 }
87 return *this;
88 }

References destroy, ptr, helios::engine::core::registerComponents and reset.

Public Member Functions​

reset()​

void helios::engine::core::memory::ErasedUnique::reset ()
inline noexcept

Destroys the owned object and resets to empty.

Definition at line 98 of file ErasedUnique.ixx.

98 void reset() noexcept {
99 if (ptr && destroy) {
100 destroy(ptr);
101 }
102 ptr = nullptr;
103 destroy = nullptr;
104 }

References destroy and ptr.

Referenced by operator= and ~ErasedUnique.

Public Member Attributes​

destroy​

void(* helios::engine::core::memory::ErasedUnique::destroy) (void *) noexcept = nullptr

Stateless deleter that knows the concrete type.

Definition at line 41 of file ErasedUnique.ixx.

41 void (*destroy)(void*) noexcept = nullptr;

Referenced by operator= and reset.

ptr​

void* helios::engine::core::memory::ErasedUnique::ptr = nullptr

Raw pointer to the owned object.

Definition at line 36 of file ErasedUnique.ixx.

36 void* ptr = nullptr;

Referenced by operator= and reset.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.