uvw 2.12.1
Loading...
Searching...
No Matches
uvw::Emitter< T > Class Template Reference

Event emitter base class. More...

#include <emitter.h>

Inheritance diagram for uvw::Emitter< T >:

Classes

struct  Connection
 Connection type for a given event type. More...
 

Public Member Functions

template<typename E >
Connection< E > on (Listener< E > f)
 Registers a long-lived listener with the event emitter.
 
template<typename E >
Connection< E > once (Listener< E > f)
 Registers a short-lived listener with the event emitter.
 
template<typename E >
void erase (Connection< E > conn) noexcept
 Disconnects a listener from the event emitter.
 
template<typename E >
void clear () noexcept
 Disconnects all the listeners for the given event type.
 
void clear () noexcept
 Disconnects all the listeners.
 
template<typename E >
bool empty () const noexcept
 Checks if there are listeners registered for the specific event.
 
bool empty () const noexcept
 Checks if there are listeners registered with the event emitter.
 

Detailed Description

template<typename T>
class uvw::Emitter< T >

Event emitter base class.

Almost everything in uvw is an event emitter.
This is the base class from which resources and loops inherit.

Definition at line 83 of file emitter.h.

Member Function Documentation

◆ empty() [1/2]

template<typename T >
template<typename E >
bool uvw::Emitter< T >::empty ( ) const
inlinenoexcept

Checks if there are listeners registered for the specific event.

Returns
True if there are no listeners registered for the specific event, false otherwise.

Definition at line 274 of file emitter.h.

◆ empty() [2/2]

template<typename T >
bool uvw::Emitter< T >::empty ( ) const
inlinenoexcept

Checks if there are listeners registered with the event emitter.

Returns
True if there are no listeners registered with the event emitter, false otherwise.

Definition at line 285 of file emitter.h.

◆ erase()

template<typename T >
template<typename E >
void uvw::Emitter< T >::erase ( Connection< E > conn)
inlinenoexcept

Disconnects a listener from the event emitter.

Parameters
connA valid Connection object

Definition at line 249 of file emitter.h.

◆ on()

template<typename T >
template<typename E >
Connection< E > uvw::Emitter< T >::on ( Listener< E > f)
inline

Registers a long-lived listener with the event emitter.

This method can be used to register a listener that is meant to be invoked more than once for the given event type.
The Connection object returned by the method can be freely discarded. It can be used later to disconnect the listener, if needed.

Listener is usually defined as a callable object assignable to a std::function<void(const E &, T &), where E is the type of the event and T is the type of the resource.

Parameters
fA valid listener to be registered.
Returns
Connection object to be used later to disconnect the listener.

Definition at line 220 of file emitter.h.

◆ once()

template<typename T >
template<typename E >
Connection< E > uvw::Emitter< T >::once ( Listener< E > f)
inline

Registers a short-lived listener with the event emitter.

This method can be used to register a listener that is meant to be invoked only once for the given event type.
The Connection object returned by the method can be freely discarded. It can be used later to disconnect the listener, if needed.

Listener is usually defined as a callable object assignable to a std::function<void(const E &, T &), where E is the type of the event and T is the type of the resource.

Parameters
fA valid listener to be registered.
Returns
Connection object to be used later to disconnect the listener.

Definition at line 240 of file emitter.h.


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