EventManager.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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-29
  7. *
  8. * */
  9. #ifndef LS_STD_EVENT_MANAGER_HPP
  10. #define LS_STD_EVENT_MANAGER_HPP
  11. #include <ls_std/base/Class.hpp>
  12. #include <map>
  13. #include <ls_std/event/EventTypes.hpp>
  14. #include <memory>
  15. #include "EventHandler.hpp"
  16. #include "IEventSubscriber.hpp"
  17. namespace ls_std {
  18. class EventManager : public ls_std::Class, public ls_std::IEventSubscriber {
  19. public:
  20. explicit EventManager();
  21. ~EventManager() override = default;
  22. // implementation
  23. void subscribe(const ls_std::event_id& _id, const std::shared_ptr<IListener>& _listener) override;
  24. void unsubscribe(const ls_std::event_id& _id, const std::shared_ptr<IListener>& _listener) override;
  25. // additional functionality
  26. void addEventHandler(const std::shared_ptr<ls_std::EventHandler>& _eventHandler);
  27. void fire(ls_std::Event _event);
  28. void removeEventHandler(const std::shared_ptr<ls_std::EventHandler>& _eventHandler);
  29. private:
  30. std::map<ls_std::event_id, std::shared_ptr<ls_std::EventHandler>> eventHandlers {};
  31. bool _hasEventHandler(const ls_std::event_id& _id);
  32. void _removeEventHandler(const std::shared_ptr<ls_std::EventHandler>& _eventHandler);
  33. };
  34. }
  35. #endif