/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2024-05-16 * Changed: 2024-05-31 * * */ #ifndef LS_STD_EVENT_MANAGER_HPP #define LS_STD_EVENT_MANAGER_HPP #include "Event.hpp" #include "EventListener.hpp" #include "EventParameter.hpp" #include #include #include #include #include #include namespace ls::std::event::type { using event_listeners = ::std::list<::std::pair<::std::shared_ptr, event_action>>; using event_observability_inventory = ::std::unordered_map<::std::string, event_listeners>; } namespace ls::std::event { ls_std_class EventManager final : public core::Class { public: explicit EventManager(); ~EventManager() noexcept override; [[nodiscard]] type::listener_id getNextProvisionId() const; [[nodiscard]] bool holdsListenerForEvent(type::listener_id _id, const Event &_event); void invoke(const Event &_event); void invoke(const Event &_event, const EventParameter &_parameter); [[nodiscard]] type::listener_id requestListenerId(); void subscribeListenerForEvent(::std::shared_ptr _listener, const Event &_event, type::event_action _action); void unsubscribeListenerForEvent(const ::std::shared_ptr &_listener, const Event &_event); private: type::event_observability_inventory inventory{}; type::listener_id provisionId = 1; static void _giveListenersParameter(const type::event_listeners &_listeners, const EventParameter &_parameter); static void _notifyListeners(const type::event_listeners &_listeners); [[nodiscard]] bool _observesEvent(const Event &_event) const; }; } #endif