52 namespace event_system
74 template <
typename... Args>
85 template <
typename... Args>
92 virtual void call(Args... aArgs)
const = 0;
117 switch (aTriggerResult)
128 template <
typename... Args>
131 template <
typename... Args>
139 return std::move(*
this);
145 return std::move(*
this);
149 template <
typename... Args>
190 template <
typename... Args>
197 iEventDestroyed{ aEvent },
198 iCallable{ aCallable },
199 iCallThread{
std::this_thread::get_id() }
210 if (!iEventDestroyed)
217 void call(Args... aArgs)
const final
224 return std::this_thread::get_id();
229 return iCallThread == std::nullopt;
233 if (aCallInEmitterThread)
234 iCallThread = std::nullopt;
236 iCallThread = std::this_thread::get_id();
244 iStateless = aStateless;
247 i_event<Args...>
const& iEvent;
249 std::function<void(Args...)> iCallable;
250 std::optional<std::thread::id> iCallThread;
251 bool iStateless =
false;
260 template <
typename... Args>
263 *
this = std::move(aSlot);
272 return iSlots.empty();
275 template <
typename... Args>
280 iSlots.push_back(aSlot.slot);
281 return std::move(aSlot);
283 template <
typename... Args>
287 iSlots.push_back(aSlot.slot);
288 return std::move(aSlot);
293 for (
auto&
slot : iSlots)
298 std::vector<ref_ptr<i_slot_base>> iSlots;
301 #define detail_event_subscribe( declName, ... ) \
302 neolib::slot_proxy<__VA_ARGS__> declName(const std::function<void(__VA_ARGS__)>& aCallback) const { return declName()(aCallback); }\
303 neolib::slot_proxy<__VA_ARGS__> declName(const std::function<void(__VA_ARGS__)>& aCallback) { return declName()(aCallback); }
305 #define declare_event( declName, ... ) \
306 virtual const neolib::i_event<__VA_ARGS__>& ev_##declName() const = 0;\
307 virtual neolib::i_event<__VA_ARGS__>& ev_##declName() = 0;\
308 const neolib::i_event<__VA_ARGS__>& declName() const { return ev_##declName(); }\
309 neolib::i_event<__VA_ARGS__>& declName() { return ev_##declName(); }\
310 detail_event_subscribe(declName, __VA_ARGS__)
virtual bool pump_events()=0
virtual void register_with_task(i_async_task &aTask)=0
virtual trigger_result sync_trigger(Args... aArgs) const =0
virtual void remove_slot(i_slot< Args... > &aSlot) const =0
virtual neolib::trigger_type trigger_type() const =0
virtual void add_slot(i_slot< Args... > &aSlot) const =0
virtual void set_trigger_type(neolib::trigger_type aTriggerType)=0
virtual void accept() const =0
slot_proxy< Args... > operator()(std::function< void(Args...)> const &aCallback) const
virtual ~i_event()=default
virtual void async_trigger(Args... aArgs) const =0
trigger_result trigger(Args... aArgs) const
virtual bool has_slots() const =0
i_slot_base abstract_type
virtual void set_call_in_emitter_thread(bool aCallInEmitterThread)=0
virtual i_event< Args... > const & event() const =0
virtual bool call_in_emitter_thread() const =0
virtual void call(Args... aArgs) const =0
virtual bool stateless() const =0
virtual void set_stateless(bool aStateless)=0
virtual std::thread::id call_thread() const =0
slot_proxy< Args... > && operator+=(slot_proxy< Args... > &&aSlot)
sink(slot_proxy< Args... > &&aSlot)
slot_proxy< Args... > && operator=(slot_proxy< Args... > &&aSlot)
void set_stateless(bool aStateless) final
bool stateless() const final
void call(Args... aArgs) const final
slot(i_event< Args... > const &aEvent, std::function< void(Args...)> const &aCallable)
void set_call_in_emitter_thread(bool aCallInEmitterThread) final
bool call_in_emitter_thread() const final
i_event< Args... > const & event() const final
std::thread::id call_thread() const final
void set_multi_threaded_spinlock()
void set_single_threaded()
void set_multi_threaded()
void set_single_threaded()
switchable_mutex & event_mutex()
ref_ptr< ConcreteType > make_ref(Args &&... args)
bool event_consumed(trigger_result aTriggerResult)
ref_ptr< neolib::slot< Args... > > slot
slot_proxy && operator~()
slot_proxy && operator!()