EventManager.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-27
  6. * Changed: 2022-06-29
  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. #include <ls_std/os/dynamic_goal.hpp>
  18. namespace ls
  19. {
  20. namespace std
  21. {
  22. namespace event
  23. {
  24. class DYNAMIC_GOAL EventManager : public ls::std::core::Class, public ls::std::core::interface_type::IEventSubscriber
  25. {
  26. public:
  27. explicit EventManager();
  28. ~EventManager() override = default;
  29. // implementation
  30. void subscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener) override;
  31. void unsubscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener) override;
  32. // additional functionality
  33. bool addEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  34. void fire(ls::std::event::Event _event);
  35. bool hasEventHandler(const ls::std::core::type::event_id &_id);
  36. bool removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  37. private:
  38. ::std::map<ls::std::core::type::event_id, ::std::shared_ptr<ls::std::event::EventHandler>> eventHandlers{};
  39. bool _hasEventHandler(const ls::std::core::type::event_id &_id);
  40. bool _removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler);
  41. };
  42. }
  43. }
  44. }
  45. #endif