Skip to main content

BasicEventManager Class

Basic implementation of the EventManager. More...

Declaration

class helios::event::BasicEventManager { ... }

Base class

classEventManager

An abstract EventManager managing the buffering and dispatching of events, acting as a central hub for event management. More...

Public Constructors Index

BasicEventManager (std::unique_ptr< EventQueue > eventQueue, std::unique_ptr< Dispatcher > dispatcher)

Constructs a new BasicEventManager, using the specified EventQueue and the Dispatcher. More...

Public Member Functions Index

EventManager &post (std::unique_ptr< const Event > event, PostPolicy policy, const std::function< bool(const std::unique_ptr< const Event > &event, const std::unique_ptr< const Event > &evt)> &func) override

Posts an event based on the specified policy to the EventQueue. More...

EventManager &dispatchAll () override

Dispatches all events of the queue, passing ownership to the underlying Dispatcher. Clears the underlying EventQueue. More...

EventManager &post (std::unique_ptr< const Event > event)

Posts the event to the queue using the APPEND policy, passing ownership of the event to the underlying queue. More...

EventManager &post (std::unique_ptr< const Event > event, PostPolicy policy)

Posts the event to the queue, passing ownership of the event to the underlying queue. More...

Description

Basic implementation of the EventManager.

This implementation provides the concrete logic for post() and dispatchAll().

Definition at line 29 of file BasicEventManager.ixx.

Public Constructors

BasicEventManager()

helios::event::BasicEventManager::BasicEventManager (std::unique_ptr< EventQueue > eventQueue, std::unique_ptr< Dispatcher > dispatcher)
inline explicit

Constructs a new BasicEventManager, using the specified EventQueue and the Dispatcher.

Parameters
eventQueue
dispatcher

Definition at line 41 of file BasicEventManager.ixx.

41 explicit BasicEventManager(std::unique_ptr<EventQueue> eventQueue,
42 std::unique_ptr<Dispatcher> dispatcher) :
43 EventManager(std::move(eventQueue), std::move(dispatcher))
44 {}

References helios::event::EventManager::dispatcher and helios::event::EventManager::EventManager.

Public Member Functions

dispatchAll()

EventManager & helios::event::BasicEventManager::dispatchAll ()
inline virtual

Dispatches all events of the queue, passing ownership to the underlying Dispatcher. Clears the underlying EventQueue.

Returns

EventManager

Definition at line 109 of file BasicEventManager.ixx.

110 while (!eventQueue_->empty()) {
111 auto e = eventQueue_->next();
112 dispatcher_->dispatch(std::move(e));
113 }
114
115 return *this;
116 }

References helios::event::EventManager::dispatcher_, helios::event::EventManager::EventManager and helios::event::EventManager::eventQueue_.

post()

EventManager & helios::event::BasicEventManager::post (std::unique_ptr< const Event > event, PostPolicy policy, const std::function< bool(const std::unique_ptr< const Event > &event, const std::unique_ptr< const Event > &evt)> & func)
inline virtual

Posts an event based on the specified policy to the EventQueue.

Parameters
event

A unique_ptr to the event that should be posted

policy

The policy to use for positing the event.

func

A comparison function for LATEST_WINS policy. If none is specified, this method will compare the events based on type and tag equality.

Returns

EventManager

Definition at line 57 of file BasicEventManager.ixx.

58 std::unique_ptr<const Event> event,
59 PostPolicy policy,
60 const std::function<bool(
61 const std::unique_ptr<const Event>& event,
62 const std::unique_ptr<const Event>& evt)>& func
63 ) override {
64
65 std::function<bool(const std::unique_ptr<const Event>& event,
66 const std::unique_ptr<const Event>& evt)> cmpFunc;
67
68 switch (policy) {
69 case APPEND:
70 eventQueue_->add(std::move(event));
71 break;
72 case LATEST_WINS:
73
74 if (!func) {
75 cmpFunc = [](
76 const std::unique_ptr<const Event>& event,
77 const std::unique_ptr<const Event>& evt) {
78 if (!event || !evt) {
79 return false;
80 }
81 return typeid(*event) == typeid(*evt) && event->tag() == evt->tag();
82 };
83 } else {
84 cmpFunc = func;
85 }
86
87 /**
88 * @todo use hashmap instead of queue for faster
89 * lookup
90 */
91 eventQueue_->addOrReplace(std::move(event), cmpFunc);
92 break;
93 default:
94 std::unreachable();
95 }
96
97
98 return *this;
99 }

References helios::event::APPEND, helios::event::EventManager::EventManager, helios::event::EventManager::eventQueue_ and helios::event::LATEST_WINS.

post()

EventManager & helios::event::EventManager::post (std::unique_ptr< const Event > event)
inline

Posts the event to the queue using the APPEND policy, passing ownership of the event to the underlying queue.

Calling this function is functionally identical to calling post() with the second argument set to APPEND.

Parameters
event

The event to post to the EventQueue.

Returns

EventManager

Declaration at line 32 of file BasicEventManager.ixx, definition at line 106 of file EventManager.ixx.

106 EventManager& post(std::unique_ptr<const Event> event) {
107 return post(std::move(event), APPEND, nullptr);
108 }

post()

EventManager & helios::event::EventManager::post (std::unique_ptr< const Event > event, PostPolicy policy)
inline

Posts the event to the queue, passing ownership of the event to the underlying queue.

Calling this function is identical to calling post() with the third argument func set to nullptr, relying on the default implementations.

Parameters
event

The event to post to the EventQueue.

policy

The policy to use for posting the event.

Returns

EventManager

Declaration at line 32 of file BasicEventManager.ixx, definition at line 123 of file EventManager.ixx.

123 EventManager& post(std::unique_ptr<const Event> event, PostPolicy policy) {
124 logger_.debug(std::format("Posting Event {0}", event->toString()));
125 return post(std::move(event), policy, nullptr);
126 }

The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.