template<typename Derived>
class entt::emitter< Derived >
General purpose event emitter.
The emitter class template follows the CRTP idiom. To create a custom emitter type, derived classes must inherit directly from the base class as:
struct my_emitter:
emitter<my_emitter> {
}
Handlers for the type of events are created internally on the fly. It's not required to specify in advance the full list of accepted types.
Moreover, whenever an event is published, an emitter provides the listeners with a reference to itself along with a const reference to the event. Therefore listeners have an handy way to work with it without incurring in the need of capturing a reference to the emitter.
- Template Parameters
-
Derived | Actual type of emitter that extends the class template. |
template<typename Derived >
template<typename Event >
Disconnects a listener from the event emitter.
Do not use twice the same connection to disconnect a listener, it results in undefined behavior. Once used, discard the connection object.
- Template Parameters
-
Event | Type of event of the connection. |
- Parameters
-
template<typename Derived >
template<typename Event >
Registers a long-lived listener with the event emitter.
This method can be used to register a listener designed to be invoked more than once for the given event type.
The connection returned by the method can be freely discarded. It's meant to be used later to disconnect the listener if required.
The listener is as a callable object that can be moved and the type of which is void(const Event &, Derived &)
.
- Note
- Whenever an event is emitted, the emitter provides the listener with a reference to the derived class. Listeners don't have to capture those instances for later uses.
- Template Parameters
-
Event | Type of event to which to connect the listener. |
- Parameters
-
instance | The listener to register. |
- Returns
- Connection object that can be used to disconnect the listener.
template<typename Derived >
template<typename Event >
Registers a short-lived listener with the event emitter.
This method can be used to register a listener designed to be invoked only once for the given event type.
The connection returned by the method can be freely discarded. It's meant to be used later to disconnect the listener if required.
The listener is as a callable object that can be moved and the type of which is void(const Event &, Derived &)
.
- Note
- Whenever an event is emitted, the emitter provides the listener with a reference to the derived class. Listeners don't have to capture those instances for later uses.
- Template Parameters
-
Event | Type of event to which to connect the listener. |
- Parameters
-
instance | The listener to register. |
- Returns
- Connection object that can be used to disconnect the listener.