libnick 2024.12.0
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::Events::Event< T > Class Template Reference

An event that can have handlers subscribe to it, which in turn will be called when the event is invoked. More...

#include <event.h>

Public Member Functions

 Event ()=default
 Constructs an Event.
 
 Event (const Event &e)
 Constructs an Event via copy.
 
 Event (Event &&e) noexcept
 Constructs an Event via move.
 
size_t count () const
 Gets the number of handlers subscribed to the event.
 
HandlerId subscribe (const std::function< void(const T &)> &handler)
 Subscribes a handler to the event.
 
void unsubscribe (HandlerId id)
 Unsubscribes a handler from the event.
 
void invoke (const T &param) const
 Invokes the event, calling all handlers.
 
HandlerId operator+= (const std::function< void(const T &)> &handler)
 Subscribes a handler to the event.
 
void operator-= (HandlerId id)
 Unsubscribes a handler from the event.
 
void operator() (const T &param)
 Invokes the event, calling all handlers.
 
Eventoperator= (const Event &e)
 Copies an Event.
 
Eventoperator= (Event &&e) noexcept
 Moves an Event.
 
 operator bool () const
 Gets whether or not the object is valid or not.
 

Detailed Description

template<DerivedEventArgs T>
class Nickvision::Events::Event< T >

An event that can have handlers subscribe to it, which in turn will be called when the event is invoked.

Template Parameters
TDerived type of EventArgs

Constructor & Destructor Documentation

◆ Event() [1/3]

template<DerivedEventArgs T>
Nickvision::Events::Event< T >::Event ( )
default

Constructs an Event.

◆ Event() [2/3]

template<DerivedEventArgs T>
Nickvision::Events::Event< T >::Event ( const Event< T > & e)
inline

Constructs an Event via copy.

Parameters
eThe object to copy

◆ Event() [3/3]

template<DerivedEventArgs T>
Nickvision::Events::Event< T >::Event ( Event< T > && e)
inlinenoexcept

Constructs an Event via move.

Parameters
eThe object to move

Member Function Documentation

◆ count()

template<DerivedEventArgs T>
size_t Nickvision::Events::Event< T >::count ( ) const
inline

Gets the number of handlers subscribed to the event.

Returns
The number of handlers

◆ invoke()

template<DerivedEventArgs T>
void Nickvision::Events::Event< T >::invoke ( const T & param) const
inline

Invokes the event, calling all handlers.

Parameters
paramThe parameter to pass to the handlers

◆ operator bool()

template<DerivedEventArgs T>
Nickvision::Events::Event< T >::operator bool ( ) const
inline

Gets whether or not the object is valid or not.

Returns
True if valid (if count() > 0), else false

◆ operator()()

template<DerivedEventArgs T>
void Nickvision::Events::Event< T >::operator() ( const T & param)
inline

Invokes the event, calling all handlers.

Parameters
paramThe parameter to pass to the handlers

◆ operator+=()

template<DerivedEventArgs T>
HandlerId Nickvision::Events::Event< T >::operator+= ( const std::function< void(const T &)> & handler)
inline

Subscribes a handler to the event.

Parameters
handlerThe handler function
Returns
The handler id

◆ operator-=()

template<DerivedEventArgs T>
void Nickvision::Events::Event< T >::operator-= ( HandlerId id)
inline

Unsubscribes a handler from the event.

Parameters
idThe handler id

◆ operator=() [1/2]

template<DerivedEventArgs T>
Event & Nickvision::Events::Event< T >::operator= ( const Event< T > & e)
inline

Copies an Event.

Parameters
eThe Event to copy
Returns
this

◆ operator=() [2/2]

template<DerivedEventArgs T>
Event & Nickvision::Events::Event< T >::operator= ( Event< T > && e)
inlinenoexcept

Moves an Event.

Parameters
eThe Event to move
Returns
this

◆ subscribe()

template<DerivedEventArgs T>
HandlerId Nickvision::Events::Event< T >::subscribe ( const std::function< void(const T &)> & handler)
inline

Subscribes a handler to the event.

Parameters
handlerThe handler function
Returns
The handler id

◆ unsubscribe()

template<DerivedEventArgs T>
void Nickvision::Events::Event< T >::unsubscribe ( HandlerId id)
inline

Unsubscribes a handler from the event.

Parameters
idThe handler id

The documentation for this class was generated from the following file: