12#ifndef MAXOS_COMMON_EVENTHANDLER_H
13#define MAXOS_COMMON_EVENTHANDLER_H
19namespace MaxOS::common {
31 template<
typename EventType>
class Event {
123 if (m_handlers.find(handler) != m_handlers.end()) {
127 m_handlers.push_back(handler);
139 if (m_handlers.find(handler) == m_handlers.end()) {
143 m_handlers.erase(handler);
158 for (
auto& handler : m_handlers) {
159 results.
push_back(handler->on_event(event));
virtual Event< EventType > * on_event(Event< EventType > *event)
This function is called when an event is raised.
Manages the m_handlers for a type of event, raises events and calls the m_handlers.
Vector< Event< EventType > * > raise_event(Event< EventType > *event)
Calls the on_event function of all the event m_handlers connected to the event manager and returns a ...
void disconnect_event_handler(EventHandler< EventType > *handler)
disconnect an event handler from the event manager if it is connected
void connect_event_handler(EventHandler< EventType > *handler)
connect an event handler to the event manager if it is not already connected
Vector< EventHandler< EventType > * > m_handlers
Used to store information about an event, has a type and a return value.
union MaxOS::common::Event::@0 return_value
Event(EventType type)
Constructs a new Event object.
Dynamically stores an array of elements.
iterator push_back(Type)
Adds an element to the end of the vector and returns the iterator of the element.
Defines a Vector class for dynamically storing an array of elements.