EventManager.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-27
  6. * Changed: 2020-11-28
  7. *
  8. * */
  9. #include <ls_std/event/EventManager.hpp>
  10. ls_std::EventManager::EventManager() : ls_std::Class("EventManager")
  11. {}
  12. void ls_std::EventManager::addEventHandler(const std::shared_ptr<ls_std::EventHandler> &_eventHandler)
  13. {
  14. if(!this->_hasEventHandler(_eventHandler->getId())) {
  15. std::pair<ls_std::event_id, std::shared_ptr<ls_std::EventHandler>> element = std::make_pair(_eventHandler->getId(), _eventHandler);
  16. this->eventHandlers.insert(element);
  17. }
  18. }
  19. void ls_std::EventManager::fire(ls_std::Event _event)
  20. {
  21. if(this->_hasEventHandler(_event.getId())) {
  22. this->eventHandlers.at(_event.getId())->tell(_event);
  23. }
  24. }
  25. void ls_std::EventManager::removeEventHandler(const std::shared_ptr<ls_std::EventHandler> &_eventHandler)
  26. {
  27. this->_removeEventHandler(_eventHandler);
  28. }
  29. bool ls_std::EventManager::_hasEventHandler(const ls_std::event_id &_id)
  30. {
  31. return this->eventHandlers.find(_id) != this->eventHandlers.end();
  32. }
  33. void ls_std::EventManager::_removeEventHandler(const std::shared_ptr<ls_std::EventHandler> &_eventHandler)
  34. {
  35. this->eventHandlers.erase(_eventHandler->getId());
  36. }