EventListener.hpp 1.3 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-31
  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/definition.hpp>
  14. #include <ls-std/core/Class.hpp>
  15. #include <ls-std/event/type/EventTypes.hpp>
  16. namespace ls::std::event
  17. {
  18. ls_std_class EventListener : public ::std::enable_shared_from_this<EventListener>, public core::Class
  19. {
  20. public:
  21. explicit EventListener();
  22. ~EventListener() noexcept override;
  23. [[nodiscard]] type::listener_id getId() const;
  24. void setId(type::listener_id _id);
  25. void setParameter(const EventParameter &_parameter);
  26. [[maybe_unused]] bool subscribe(const Event &_event, const type::event_action &_action);
  27. [[maybe_unused]] bool unsubscribe(const Event &_event);
  28. protected:
  29. EventParameter parameter{};
  30. private:
  31. type::listener_id id{};
  32. void _requestListenerId(const ::std::shared_ptr<Class> &_manager);
  33. [[nodiscard]] bool _subscribe(const Event &_event, const type::event_action &_action);
  34. [[nodiscard]] bool _unsubscribe(const Event &_event);
  35. };
  36. }
  37. #endif