|
CPP-TOOLBOX
|
A type-safe signal emitter that allows different signal types (represented as structs). More...
#include <signal_emitter.hpp>
Public Member Functions | |
| template<typename Signal> | |
| void | connect (std::function< void(const Signal &)> listener) |
| template<typename Signal> | |
| void | emit (const Signal &signal) |
A type-safe signal emitter that allows different signal types (represented as structs).
Each signal type is a distinct struct that defines the data associated with that event. Listeners can register callbacks for a specific signal type, and when that signal is emitted, all corresponding callbacks are invoked with the signal instance.
This design avoids string-based dispatch and leverages compile-time type safety.
Example:
T and a listener is connected to it. Since signals are emitted within a specific instance of SignalEmitter, other SignalEmitter instances even if they use the same signal type T will not trigger listeners connected to a different object.
|
inline |
|
inline |