You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
745 B

#include "EventBus.h"
void EventBus::addHandler(std::string key, void (*func)()) {
// If the bus already has this key, add a handler
auto search = this->_bus.find(key);
if ( search != this->_bus.end() ) {
std::vector<void (*)()> func_arr = this->_bus[key];
func_arr.push_back(func);
this->_bus[key] = func_arr;
} else {
std::vector<void (*)()> func_arr;
func_arr.push_back(func);
this->_bus[key] = func_arr;
}
}
void EventBus::fire(std::string key) {
auto search = this->_bus.find(key);
if ( search != this->_bus.end() ) {
std::vector<void (*)()> func_arr = this->_bus[key];
for ( void(*func)() : func_arr ) {
(*func)();
}
}
}