AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
aui::ptr Struct Reference

Member Function Documentation

◆ fake_shared()

template<typename T>
_< T > aui::ptr::fake_shared ( T * raw)
static
Template Parameters
Tany type.
Parameters
rawraw pointer to manage memory of.
Returns
shared pointer.
Examples
examples/7guis/circle_drawer/src/main.cpp, and examples/app/game_of_life/src/main.cpp.

◆ manage_shared() [1/2]

template<typename T>
_< T > aui::ptr::manage_shared ( T * raw)
static
Template Parameters
Tany type
Parameters
rawraw pointer to manage memory of
Returns
shared pointer
Examples
examples/7guis/crud/src/main.cpp, and examples/app/notes/src/main.cpp.

◆ manage_shared() [2/2]

template<typename T, typename Deleter>
_< T > aui::ptr::manage_shared ( T * raw,
Deleter deleter )
static
Template Parameters
Tany type
Deleterobject implementing operator()(T*)
Parameters
rawraw pointer to manage memory of
deleter
Returns
shared pointer

◆ manage_unique()

template<typename T, typename Deleter = std::default_delete<T>>
static _unique< T, Deleter > aui::ptr::manage_unique ( T * ptr,
Deleter deleter = Deleter{} )
inlinestatic
Template Parameters
TThe type of the object to manage.
DeleterThe type of the custom deleter function or functor.
Parameters
ptrA raw pointer to the object that the unique pointer will manage.
deleterA custom deleter that will be used to destroy the managed object.
Returns
A unique pointer that takes ownership of the raw pointer using the specified deleter.

Creates a unique pointer with a custom deleter.

unique_ptr could not deduce T and Deleter by itself. Use this function to avoid this restriction. By using this function, the lifetime of the pointer is delegated to std::unique_ptr. Specified Deleter will free the wrapped pointer. The default deleter is std::default_delete. You may want to specialize std::default_delete<T> struct to specify a default deleter for T, in this case you can omit the deleter argument of this function.

◆ shared_from_this()

template<typename T>
static _< T > aui::ptr::shared_from_this ( T * raw)
inlinestatic
Template Parameters
Tclass which derived from a class that implements std::enable_shared_from_this.
Parameters
rawpointer to the T class.
Returns
Shared pointer.

std::enable_shared_from_this provides a shared pointer to itself, however, if inheritance takes place, type is lost, requiring manual downcasting.

Downcasts std::enable_shared_from_this<base class> to the derived class T by the aliasing constructor of the shared pointer. This eliminates the need of expensive downcasting, maintaining memory safety.

◆ weak_from_this()

template<typename T>
static _weak< T > aui::ptr::weak_from_this ( T * raw)
inlinestatic
Template Parameters
Tclass which derived from a class that implements std::enable_shared_from_this.
Parameters
rawpointer to the T class.
Returns
Weak pointer.

std::enable_shared_from_this provides a shared pointer to itself, however, if inheritance takes place, type is lost, requiring manual downcasting.

Downcasts std::enable_shared_from_this<base class> to the derived class T by the aliasing constructor of the shared pointer. This eliminates the need of expensive downcasting, maintaining memory safety.