8#include "DSCEngine/debug/assert.hpp"
16 typedef void (*StaticEventHandler)(
void* sender,
void* args);
34 virtual void execute(
void* sender,
void* args)
const;
47 virtual void execute(
void* sender,
void* args)
const override;
62 virtual void execute(
void* sender,
void* args)
const override;
119 : __handler(handler), __instance(instance)
125 void NonStaticEventHandlerContainer<C>::execute(
void* sender,
void* args)
const
127 nds_assert(__handler!=
nullptr);
130 (__instance->*__handler)(sender, args);
136 bool NonStaticEventHandlerContainer<C>::operator == (
const EventHandlerContainer& other)
const
138 if(!this->has_same_type(other))
140 const NonStaticEventHandlerContainer<C>* p_other
141 = (
const NonStaticEventHandlerContainer<C>*)(&other);
142 return this->__handler == p_other->__handler && this->__instance == p_other->__instance;
148 void Event::add_event(
const NonStaticEventHandler<C> e, C* instance)
150 nds_assert(e !=
nullptr);
151 actions.push_back(
new NonStaticEventHandlerContainer<C>(e, instance));
155 void Event::remove_event(
const NonStaticEventHandler<C> e, C* instance)
157 NonStaticEventHandlerContainer<C> eh(e, instance);
158 for(
int i=0;i<actions.size();i++)
160 if(*actions[i] == eh)
162 EventHandlerContainer* target = actions[i];
163 actions.remove_at(i);
Class responsible with event registration and execution.
Definition: event.hpp:76
Event()
Creates a new Event instance.
void trigger(void *sender, void *args) const
Fires the event.
Event & operator+=(const StaticEventHandler &e)
Adds a new event handler to this event.
Event & operator-=(const StaticEventHandler &e)
Removes an event handler from this event.
Generic dynamic vector.
Definition: vector.hpp:23
void(* StaticEventHandler)(void *sender, void *args)
Function type to be executed when event fires
Definition: event.hpp:16
void(C::*)(void *sender, void *args) NonStaticEventHandler
Class method type to be executed when event fires.
Definition: event.hpp:24
Generic dynamic vector definition.