EventListener.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2024-05-16
  6. * Changed: 2024-05-30
  7. *
  8. * */
  9. #ifndef LS_STD_EVENT_LISTENER_HPP
  10. #define LS_STD_EVENT_LISTENER_HPP
  11. #include "Event.hpp"
  12. #include "EventParameter.hpp"
  13. #include <ls-std/core/Class.hpp>
  14. #include <ls-std/event/type/EventTypes.hpp>
  15. #include <ls-std/os/dynamic-goal.hpp>
  16. namespace ls::std::event
  17. {
  18. class LS_STD_DYNAMIC_GOAL EventListener : public ::std::enable_shared_from_this<EventListener>, public ls::std::core::Class
  19. {
  20. public:
  21. explicit EventListener();
  22. ~EventListener() noexcept override;
  23. [[nodiscard]] ls::std::event::type::listener_id getId() const;
  24. void setId(ls::std::event::type::listener_id _id);
  25. void setParameter(const ls::std::event::EventParameter &_parameter);
  26. [[maybe_unused]] bool subscribe(const ls::std::event::Event &_event, const ls::std::event::type::event_action &_action);
  27. [[maybe_unused]] bool unsubscribe(const ls::std::event::Event &_event);
  28. protected:
  29. ls::std::event::EventParameter parameter{};
  30. private:
  31. ls::std::event::type::listener_id id{};
  32. void _requestListenerId(const ::std::shared_ptr<ls::std::core::Class> &_manager);
  33. [[nodiscard]] bool _subscribe(const ls::std::event::Event &_event, const ls::std::event::type::event_action &_action);
  34. [[nodiscard]] bool _unsubscribe(const ls::std::event::Event &_event);
  35. };
  36. }
  37. #endif