LiteFX 0.4.1.2025
Computer Graphics Engine
|
A class that is used to declare an event, which a number of listeners can subscribe to. More...
#include <app.hpp>
Public Types | |
using | event_args_type = TEventArgs |
using | delegate_type = Delegate<void, const void*, TEventArgs> |
using | function_type = typename delegate_type::function_type |
using | event_token_type = typename delegate_type::token_type |
Public Member Functions | |
constexpr | Event ()=default |
Initializes a new event. | |
constexpr | Event (const Event &_other) |
Creates a copy of a event. | |
constexpr | Event (Event &&_other) noexcept=default |
Takes over another instance of a event. | |
constexpr Event & | operator= (const Event &_other) |
Assigns a event by copying it. | |
constexpr Event & | operator= (Event &&_other) noexcept=default |
Assigns a event by taking it over. | |
constexpr | ~Event () noexcept=default |
Releases the event instance. | |
event_token_type | add (const function_type &subscriber) |
Subscribes an event handler to the event. | |
bool | remove (const delegate_type &subscriber) noexcept |
Unsubscribes an event handler from the event. | |
bool | remove (event_token_type token) noexcept |
Unsubscribes an event handler from the event. | |
void | clear () noexcept |
Clears the event handlers. | |
void | invoke (const void *sender, const TEventArgs &args) const |
Invokes all event handlers of the event. | |
bool | contains (event_token_type token) const noexcept |
Returns true , if the event contains a subscriber with the provided token . | |
const delegate_type & | handler (event_token_type token) const |
Returns the delegate associated with token . | |
operator bool () const noexcept | |
Returns true , if any event handler is attached to the event, false otherwise. | |
event_token_type | operator+= (const function_type &subscriber) |
Subscribes an event handler to the event. | |
bool | operator-= (const delegate_type &subscriber) noexcept |
Unsubscribes an event handler from the event. | |
bool | operator-= (event_token_type token) noexcept |
Unsubscribes an event handler from the event. | |
void | operator() (const void *sender, const TEventArgs &args) const |
Invokes all event handlers of the event. | |
const delegate_type & | operator[] (event_token_type token) const |
Returns the delegate associated with token . | |
A class that is used to declare an event, which a number of listeners can subscribe to.
A listener that subscribes to the event is called event handler. The event handler needs to be invokable and identifiable. Because of this, a Delegate is created for the event handler. A delegate stores the event handler, as well as a token to identify the event handler. Event handlers must expose the a common signature: they do not return anything and accept two parameters. The first parameter is an unformatted pointer to the event sender (i.e., the object that invoked the event handlers). The second parameter contains additional arguments (TEventArgs ), that are passed to all handlers. Note that the sender can also be nullptr
.
TEventArgs | The type of the additional event arguments. |
using LiteFX::Event< TEventArgs >::delegate_type = Delegate<void, const void*, TEventArgs> |
using LiteFX::Event< TEventArgs >::event_args_type = TEventArgs |
using LiteFX::Event< TEventArgs >::event_token_type = typename delegate_type::token_type |
using LiteFX::Event< TEventArgs >::function_type = typename delegate_type::function_type |
|
constexprdefault |
Initializes a new event.
|
inlineconstexpr |
Creates a copy of a event.
This constructor is implemented in order to support copying of types that contain events. Subscribers are not copied!
_other | The event instance to copy. |
|
constexprdefaultnoexcept |
Takes over another instance of a event.
_other | The event instance to take over. |
|
constexprdefaultnoexcept |
Releases the event instance.
|
inline |
Subscribes an event handler to the event.
subscriber | A delegate for the event handler. |
|
inlinenoexcept |
Clears the event handlers.
|
inlinenoexcept |
Returns true
, if the event contains a subscriber with the provided token .
token | The token of an event. |
true
, if the event contains a subscriber with the provided token , false
otherwise.
|
inline |
Returns the delegate associated with token .
token | The token to query for. |
InvalidArgumentException | Thrown, if the event does not have a subscriber with the provided token. |
|
inline |
Invokes all event handlers of the event.
sender | The source of the event. |
args | The additional event arguments. |
|
inlineexplicitnoexcept |
Returns true
, if any event handler is attached to the event, false
otherwise.
true
, if any event handler is attached to the event, false
otherwise.
|
inline |
Invokes all event handlers of the event.
sender | The source of the event. |
args | The additional event arguments. |
|
inline |
Subscribes an event handler to the event.
subscriber | A delegate for the event handler. |
|
inlinenoexcept |
Unsubscribes an event handler from the event.
subscriber | A delegate for the event handler. |
true
, if the event handler has been removed, false
otherwise.
|
inlinenoexcept |
Unsubscribes an event handler from the event.
toke | The unique token of the event handler. |
true
, if the event handler has been removed, false
otherwise.
|
inlineconstexpr |
Assigns a event by copying it.
This operator is implemented in order to support copying of types that contain events. Subscribers are not copied and previous subscriptions are cleared!
_other | The event instance to copy. |
|
constexprdefaultnoexcept |
Assigns a event by taking it over.
_other | The event to take over. |
|
inline |
Returns the delegate associated with token .
token | The token to query for. |
InvalidArgumentException | Thrown, if the event does not have a subscriber with the provided token. |
|
inlinenoexcept |
Unsubscribes an event handler from the event.
subscriber | A delegate for the event handler. |
true
, if the event handler has been removed, false
otherwise.
|
inlinenoexcept |
Unsubscribes an event handler from the event.
toke | The unique token of the event handler. |
true
, if the event handler has been removed, false
otherwise.