1.10 |
Base object class with fundamental properties. More...
#include <object.h>
Classes | |
struct | CallbackMeta |
Manages metadata about a registered callback. More... | |
Public Types | |
using | EventCallback = std::function< void(Event &event)> |
Event handler callback function. | |
using | FilterFlags = FlagsBase< EventId > |
Event handler EventId filter. | |
using | RegisterHandle = uint64_t |
Handle type. | |
Public Member Functions | |
Object () noexcept=default | |
Object (const Object &)=delete | |
Object (Object &&)=default | |
virtual | ~Object () noexcept=default |
void | clear_handlers () |
Clear all registered event handlers. | |
void | invoke_handlers (Event &event) |
Invoke all handlers with the specified event. | |
void | invoke_handlers (EventId event) |
Invoke all handlers with the specified EventId. | |
EGT_NODISCARD const std::string & | name () const |
Get the name of the Object. | |
void | name (const std::string &name) |
Set the name of the Object. | |
RegisterHandle | on_event (const EventCallback &handler, const FilterFlags &mask={}) |
Add an event handler to be called when the widget generates an event. | |
Object & | operator= (const Object &)=delete |
Object & | operator= (Object &&)=default |
void | remove_handler (RegisterHandle handle) |
Remove an event handler. | |
Protected Types | |
using | CallbackArray = std::vector< CallbackMeta > |
Helper type for an array of callbacks. | |
Protected Attributes | |
detail::CopyOnWriteAllocate< CallbackArray > | m_callbacks |
Array of callbacks. | |
RegisterHandle | m_handle_counter {0} |
Counter used to generate unique handles for each callback registration. | |
std::string | m_name |
A user defined name for the Object. | |
Base object class with fundamental properties.
|
protected |
Helper type for an array of callbacks.
using EventCallback = std::function<void (Event& event)> |
Event handler callback function.
using FilterFlags = FlagsBase<EventId> |
Event handler EventId filter.
using RegisterHandle = uint64_t |
Handle type.
|
defaultnoexcept |
|
virtualdefaultnoexcept |
void clear_handlers | ( | ) |
Clear all registered event handlers.
void invoke_handlers | ( | Event & | event | ) |
Invoke all handlers with the specified event.
event | The event to invoke. |
void invoke_handlers | ( | EventId | event | ) |
Invoke all handlers with the specified EventId.
event | The EventId to invoke. |
|
inline |
Get the name of the Object.
|
inline |
RegisterHandle on_event | ( | const EventCallback & | handler, |
const FilterFlags & | mask = {} |
||
) |
Add an event handler to be called when the widget generates an event.
Any number of handlers (callbacks) can be registered. Also, the same handler function can be registered multiple times, optionally with different masks.
handler | The callback to invoke on event. |
mask | An optional EventId mask specifying what events to invoke the handler with. If no mask is supplied, any EventId will cause the handler to be invoked. |
void remove_handler | ( | RegisterHandle | handle | ) |
Remove an event handler.
handle | The handle returned from on_event(). |
|
protected |
Array of callbacks.
|
protected |
Counter used to generate unique handles for each callback registration.
|
protected |
A user defined name for the Object.