Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::common::EventManager< EventType > Class Template Reference

Manages the m_handlers for a type of event, raises events and calls the m_handlers. More...

#include <eventHandler.h>

Public Member Functions

void connect_event_handler (EventHandler< EventType > *handler)
 connect an event handler to the event manager if it is not already connected
 
void disconnect_event_handler (EventHandler< EventType > *handler)
 disconnect an event handler from the event manager if it is connected
 
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 list of the results.
 

Protected Attributes

Vector< EventHandler< EventType > * > m_handlers
 

Detailed Description

template<typename EventType>
class MaxOS::common::EventManager< EventType >

Manages the m_handlers for a type of event, raises events and calls the m_handlers.

Deprecated:
Will Remove Soon
Template Parameters
EventTypeThe type of event

Definition at line 66 of file eventHandler.h.

Member Function Documentation

◆ connect_event_handler()

template<typename EventType >
void MaxOS::common::EventManager< EventType >::connect_event_handler ( EventHandler< EventType > *  handler)

connect an event handler to the event manager if it is not already connected

Template Parameters
EventTypeThe type of event
Parameters
handlerThe event handler to connect

Definition at line 121 of file eventHandler.h.

121 {
122 // If the handler is already connected, return
123 if (m_handlers.find(handler) != m_handlers.end()) {
124 return;
125 }
126
127 m_handlers.push_back(handler);
128
129 }
Vector< EventHandler< EventType > * > m_handlers

Referenced by MaxOS::net::TransmissionControlProtocolHandler::bind().

◆ disconnect_event_handler()

template<typename EventType >
void MaxOS::common::EventManager< EventType >::disconnect_event_handler ( EventHandler< EventType > *  handler)

disconnect an event handler from the event manager if it is connected

Template Parameters
EventTypeThe type of event
Parameters
handlerThe event handler to disconnect

Definition at line 137 of file eventHandler.h.

137 {
138 // If the handler is not connected, return
139 if (m_handlers.find(handler) == m_handlers.end()) {
140 return;
141 }
142
143 m_handlers.erase(handler);
144 }

◆ raise_event()

template<typename EventType >
Vector< Event< EventType > * > MaxOS::common::EventManager< 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 list of the results.

Template Parameters
EventTypeThe type of event
Parameters
eventThe event to raise
Returns
A list of the results of the event m_handlers

Definition at line 153 of file eventHandler.h.

153 {
154
155
156 // Store a list of the results of the event handlers
157 Vector<Event<EventType>*> results;
158 for (auto& handler : m_handlers) {
159 results.push_back(handler->on_event(event));
160 }
161
162 // Free the memory used by the event
163 delete event;
164
165 return results;
166 }

References MaxOS::common::Vector< Type >::push_back().

Member Data Documentation

◆ m_handlers


The documentation for this class was generated from the following file: