EventHandler.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-27
  6. * Changed: 2020-11-27
  7. *
  8. * */
  9. #ifndef LS_STD_EVENT_HANDLER_HPP
  10. #define LS_STD_EVENT_HANDLER_HPP
  11. #include <ls_std/base/Class.hpp>
  12. #include <list>
  13. #include <memory>
  14. #include <ls_std/logic/IListener.hpp>
  15. #include "Event.hpp"
  16. namespace ls_std {
  17. class EventHandler : public ls_std::Class {
  18. public:
  19. explicit EventHandler(ls_std::event_id _id);
  20. ~EventHandler() override = default;
  21. ls_std::event_id getId();
  22. void notify(const ls_std::Event& _event);
  23. void subscribe(const std::shared_ptr<ls_std::IListener>& _listener);
  24. void unsubscribe(const std::shared_ptr<ls_std::IListener>& _listener);
  25. private:
  26. ls_std::event_id id {};
  27. std::list<std::shared_ptr<ls_std::IListener>> listeners {};
  28. void _addListener(const std::shared_ptr<ls_std::IListener>& _listener);
  29. bool _hasListener(const std::shared_ptr<ls_std::IListener>& _listener);
  30. void _removeListener(const std::shared_ptr<ls_std::IListener>& _listener);
  31. };
  32. }
  33. #endif