17#include "ksEventInterface.h"
18#include "ksEventHandle.h"
25#define DECLARE_KS_EVENT(evtName, ...) \
26 std::shared_ptr<ksf::evt::ksEvent<__VA_ARGS__>> evtName {std::make_shared<ksf::evt::ksEvent<__VA_ARGS__>>()};
34 template <
typename... Params>
38 std::vector<std::pair<std::size_t, std::function<void(Params...)>>>
callbacks;
56 void registerEvent(std::unique_ptr<ksf::evt::ksEventHandle>& outHandle, std::function<
void(Params...)>&& function)
59 outHandle = std::make_unique<ksf::evt::ksEventHandle>(weak_from_this(),
lastCallbackUID);
71 void unbind(std::size_t callbackUID)
override
73 auto predicate = [callbackUID](
const auto& cb) {
74 auto& [uid, function] = cb;
75 return uid == callbackUID;
87 for (
const auto& [uid, function] :
callbacks)
Base class for multicasting events.
Definition ksEvent.h:36
void registerEvent(std::unique_ptr< ksf::evt::ksEventHandle > &outHandle, std::function< void(Params...)> &&function)
Registers event (binds to callback list).
Definition ksEvent.h:56
std::vector< std::pair< std::size_t, std::function< void(Params...)> > > callbacks
List of bond callbacks.
Definition ksEvent.h:38
void unbind(std::size_t callbackUID) override
Unbinds event callback by specified unique ID.
Definition ksEvent.h:71
std::size_t lastCallbackUID
Last unique callback ID for this event (used as counter).
Definition ksEvent.h:39
bool isBound() const
Returns whether any callback is bound to this event.
Definition ksEvent.h:46
void broadcast(Params... params) const
Broadcasts event to all bound callbacks.
Definition ksEvent.h:85
Implements interface for multicasting events.
Definition ksEventInterface.h:21