Louvre v2.14.0-1
C++ library for Wayland compositors
|
Weak reference to an LObject. More...
#include <LWeak.h>
Public Types | |
using | OnDestroyCallback = std::function< void(T *)> |
Public Member Functions | |
LWeak () noexcept=default | |
Creates an empty LWeak. | |
LWeak (T *object) noexcept | |
Creates a reference for the given LObject, or initializes an empty LWeak if nullptr is passed. | |
~LWeak () noexcept | |
Destructor, removes the LWeak from the LObject references. | |
LWeak (const LWeak< T > &other) noexcept | |
Copy constructor, assigns the LObject of another LWeak. | |
LWeak< T > & | operator= (const LWeak< T > &other) noexcept |
Assignment operator, assigns the LObject of another LWeak. | |
T * | get () const noexcept |
Gets a pointer to the LObject or nullptr if not set or the object has been destroyed. | |
operator T* () const noexcept | |
Implicit conversion to raw pointer. | |
T * | operator-> () const noexcept |
Access underlying object via pointer semantics. | |
UInt64 | count () const noexcept |
Return the number of existing references to the current LObject. | |
void | reset (T *object=nullptr) noexcept |
Replace the reference with another object. | |
void | setOnDestroyCallback (const OnDestroyCallback &callback) noexcept |
Set the onDestroy callback function. | |
Weak reference to an LObject.
The LWeak class template provides a mechanism for creating weak pointer references to subclasses of LObject.
It is conceptually similar to std::weak_ptr
but is specifically tailored for LObject subclasses, avoiding the pointer indirection and associated performance overhead of the std::weak_ptr
thread-safe mechanisms.
When the object being referenced is destroyed, an optional on destroy callback event is emitted, and get() returns nullptr
.
using OnDestroyCallback = std::function<void(T*)> |
Callback function type used to handle the OnDestroy()
event.
|
inlinenoexcept |
Implicit conversion to raw pointer.
Provides access to the underlying raw pointer through an implicit conversion.
Access underlying object via pointer semantics.
Allows accessing members of the underlying object using pointer semantics.
Replace the reference with another object.
object | The LObject to set as the new reference, or nullptr to unset the reference. |
|
inlinenoexcept |
Set the onDestroy callback function.
callback | The callback function to be called when the referenced object is destroyed. Passing nullptr disables the callback. |