EventManager.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-27
  6. * Changed: 2022-05-16
  7. *
  8. * */
  9. #ifndef LS_STD_EVENT_MANAGER_HPP
  10. #define LS_STD_EVENT_MANAGER_HPP
  11. #include <ls_std/core/Class.hpp>
  12. #include <map>
  13. #include <ls_std/core/types/EventTypes.hpp>
  14. #include <memory>
  15. #include "EventHandler.hpp"
  16. #include <ls_std/core/interface/IEventSubscriber.hpp>
  17. namespace ls
  18. {
  19. namespace std
  20. {
  21. namespace event
  22. {
  23. class EventManager : public ls::std::core::Class, public ls::std::core::interface::IEventSubscriber
  24. {
  25. public:
  26. explicit EventManager();
  27. ~EventManager() override = default;
  28. // implementation
  29. void subscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface::IListener> &_listener) override;
  30. void unsubscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface::IListener> &_listener) override;
  31. // additional functionality
  32. bool addEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  33. void fire(ls::std::event::Event _event);
  34. bool hasEventHandler(const ls::std::core::type::event_id &_id);
  35. bool removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  36. private:
  37. ::std::map<ls::std::core::type::event_id, ::std::shared_ptr<ls::std::event::EventHandler>> eventHandlers{};
  38. bool _hasEventHandler(const ls::std::core::type::event_id &_id);
  39. bool _removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  40. };
  41. }
  42. }
  43. }
  44. #endif