1#ifndef UVW_EMITTER_INCLUDE_H
2#define UVW_EMITTER_INCLUDE_H
10#include <unordered_map>
14#include "type_info.hpp"
24 template<
typename U,
typename = std::enable_if_t<std::is_
integral_v<U>>>
26 : ec{
static_cast<int>(val)} {}
49 const char *
what() const noexcept;
58 const
char *
name() const noexcept;
70 explicit operator
bool() const noexcept;
82template<typename T, typename... E>
86 using listener_t = std::function<void(U &, T &)>;
90 const auto &handler()
const noexcept {
91 return std::get<listener_t<U>>(handlers);
95 auto &handler()
noexcept {
96 return std::get<listener_t<U>>(handlers);
101 void publish(U event) {
102 if(
auto &listener = handler<U>(); listener) {
103 listener(event, *
static_cast<T *
>(
this));
109 static_assert(std::is_base_of_v<
emitter<T, E...>, T>);
123 void on(listener_t<U> f) {
124 handler<U>() = std::move(f);
130 handler<U>() =
nullptr;
135 reset<error_event>();
145 bool has() const noexcept {
146 return static_cast<bool>(handler<U>());
150 std::tuple<listener_t<error_event>, listener_t<E>...> handlers{};
156# include "emitter.cpp"
Event emitter base class.
void reset() noexcept
Disconnects all listeners.
void on(listener_t< U > f)
Registers a long-lived listener with the event emitter.
bool has() const noexcept
Checks if there is a listener registered for the specific event.
void reset() noexcept
Disconnects the listener for the given event type.
static int translate(int sys) noexcept
Returns the libuv error code equivalent to the given platform dependent error code.
int code() const noexcept
Gets the underlying error code, that is an error constant of libuv.
const char * what() const noexcept
Returns the error message for the given error code.
const char * name() const noexcept
Returns the error name for the given error code.