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