EventManager.hpp 1.7 KB

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