EventListener.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2024-05-16
  6. * Changed: 2024-09-11
  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. /*
  17. * @doc: class(name: 'EventListener', package: 'event')
  18. * @doc: event.EventListener.description('An instance of this class can listen to any event. Usually, this class is used as base class of any class that must listen to an event.')
  19. * */
  20. namespace ls::std::event
  21. {
  22. class LS_STD_DYNAMIC_GOAL EventListener : public ::std::enable_shared_from_this<EventListener>, public ls::std::core::Class
  23. {
  24. public:
  25. explicit EventListener();
  26. ~EventListener() noexcept override;
  27. [[nodiscard]] ls::std::event::type::listener_id getId() const;
  28. void setId(ls::std::event::type::listener_id _id);
  29. void setParameter(const ls::std::event::EventParameter &_parameter);
  30. [[maybe_unused]] bool subscribe(const ls::std::event::Event &_event, const ls::std::event::type::event_action &_action);
  31. [[maybe_unused]] bool unsubscribe(const ls::std::event::Event &_event);
  32. protected:
  33. ls::std::event::EventParameter parameter{};
  34. private:
  35. ls::std::event::type::listener_id id{};
  36. void _requestListenerId(const ::std::shared_ptr<ls::std::core::Class> &_manager);
  37. [[nodiscard]] bool _subscribe(const ls::std::event::Event &_event, const ls::std::event::type::event_action &_action);
  38. [[nodiscard]] bool _unsubscribe(const ls::std::event::Event &_event);
  39. };
  40. }
  41. #endif