1.1-rc3
Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes | List of all members
Object Class Reference

Base object class with fundamental properties. More...

Inheritance diagram for Object:
Inheritance graph
[legend]

Classes

struct  CallbackMeta
 Manages metadata about a registered callback. More...
 

Public Types

using EventCallback = std::function< void(Event &event)>
 Event handler callback function. More...
 
using FilterFlags = FlagsBase< EventId >
 Event handler EventId filter. More...
 
using RegisterHandle = uint64_t
 Handle type. More...
 

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. More...
 
void invoke_handlers (Event &event)
 Invoke all handlers with the specified event. More...
 
void invoke_handlers (EventId event)
 Invoke all handlers with the specified EventId. More...
 
const EGT_NODISCARD std::string & name () const
 Get the name of the Object. More...
 
void name (const std::string &name)
 Set the name of the Object. More...
 
RegisterHandle on_event (const EventCallback &handler, const FilterFlags &mask={})
 Add an event handler to be called when the widget generates an event. More...
 
Objectoperator= (const Object &)=delete
 
Objectoperator= (Object &&)=default
 
void remove_handler (RegisterHandle handle)
 Remove an event handler. More...
 

Protected Types

using CallbackArray = std::vector< CallbackMeta >
 Helper type for an array of callbacks. More...
 

Protected Attributes

detail::CopyOnWriteAllocate< CallbackArraym_callbacks
 Array of callbacks. More...
 
RegisterHandle m_handle_counter {0}
 Counter used to generate unique handles for each callback registration. More...
 
std::string m_name
 A user defined name for the Object. More...
 

Detailed Description

Base object class with fundamental properties.

Member Typedef Documentation

◆ CallbackArray

using CallbackArray = std::vector<CallbackMeta>
protected

Helper type for an array of callbacks.

◆ EventCallback

using EventCallback = std::function<void (Event& event)>

Event handler callback function.

◆ FilterFlags

Event handler EventId filter.

◆ RegisterHandle

using RegisterHandle = uint64_t

Handle type.

Constructor & Destructor Documentation

◆ Object() [1/3]

Object ( )
defaultnoexcept

◆ Object() [2/3]

Object ( const Object )
delete

◆ Object() [3/3]

Object ( Object &&  )
default

◆ ~Object()

virtual ~Object ( )
virtualdefaultnoexcept

Member Function Documentation

◆ clear_handlers()

void clear_handlers ( )

Clear all registered event handlers.

◆ invoke_handlers() [1/2]

void invoke_handlers ( Event event)

Invoke all handlers with the specified event.

Parameters
eventThe event to invoke.

◆ invoke_handlers() [2/2]

void invoke_handlers ( EventId  event)

Invoke all handlers with the specified EventId.

Parameters
eventThe EventId to invoke.

◆ name() [1/2]

const EGT_NODISCARD std::string& name ( ) const
inline

Get the name of the Object.

◆ name() [2/2]

void name ( const std::string &  name)
inline

Set the name of the Object.

Assigns a human readable name to an Object that can then be used to find timers by name or debug.

Parameters
[in]nameName to set for the Object.

◆ on_event()

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.

Parameters
handlerThe callback to invoke on event.
maskAn 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.
Returns
A handle used to identify the registration. This can then be passed to remove_handler().

◆ operator=() [1/2]

Object& operator= ( const Object )
delete

◆ operator=() [2/2]

Object& operator= ( Object &&  )
default

◆ remove_handler()

void remove_handler ( RegisterHandle  handle)

Remove an event handler.

Parameters
handleThe handle returned from on_event().

Member Data Documentation

◆ m_callbacks

Array of callbacks.

◆ m_handle_counter

RegisterHandle m_handle_counter {0}
protected

Counter used to generate unique handles for each callback registration.

◆ m_name

std::string m_name
protected

A user defined name for the Object.