Skip to main content

DequeEventQueue.ixx File

Double-ended event queue implementation. More...

Included Headers

#include <deque> #include <functional> #include <memory> #include <algorithm> #include <helios.event.Event> #include <helios.event.EventQueue>

Namespaces Index

namespacehelios
namespaceevent

Event system. More...

Classes Index

classDequeEventQueue

Concrete implementation of an EventQueue that uses a Deque as its underlying queue strategy. Adding and removing events follows a FIFO strategy. More...

Description

Double-ended event queue implementation.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DequeEventQueue.ixx
3 * @brief Double-ended event queue implementation.
4 */
5module;
6
7#include <deque>
8#include <functional>
9#include <memory>
10#include <algorithm>
11
12export module helios.event.DequeEventQueue;
13
14import helios.event.EventQueue;
15import helios.event.Event;
16
17
18using namespace helios::event;
19
20export namespace helios::event {
21
22 /**
23 * @brief Concrete implementation of an EventQueue that uses a Deque
24 * as its underlying queue strategy.
25 * Adding and removing events follows a FIFO strategy.
26 *
27 */
28 class DequeEventQueue : public EventQueue{
29
30 private:
31 /**
32 * @brief The internal deque for storing the events.
33 */
34 std::deque<std::unique_ptr<const Event>> events;
35
36 public:
37
38 /**
39 * @brief Takes ownership of the event and moves it at the end of the queue.
40 *
41 * @param event A unique_ptr to the event that should be managed by this class.
42 *
43 * @return
44 */
45 EventQueue& add(std::unique_ptr<const Event> event) override {
46 events.push_back(std::move(event));
47 return *this;
48 }
49
50
51 /**
52 * @brief Adds an event to the queue or replaces an existing one.
53 *
54 * @param event A unique_ptr to the event this queue takes the ownership of.
55 * @param cmpFunc The cmp function that is used for looking up and replacing an existing
56 * event with the soecified event.
57 *
58 * @return EventQueue
59 */
61 std::unique_ptr<const Event> event,
62 const std::function<bool(const std::unique_ptr<const Event>& evt,
63 const std::unique_ptr<const Event>& e)>& cmpFunc) override {
64
65 std::erase_if(events, [&event, cmpFunc](const std::unique_ptr<const Event>& e) {
66 return cmpFunc(event, e);
67 });
68 events.push_back(std::move(event));
69 return *this;
70 }
71
72
73 /**
74 * @brief Returns true if the queue is empty, otherwise false.
75 *
76 * @return True if the queue is empty, otherwise false.
77 */
78 [[nodiscard]] bool empty() const noexcept override {
79 return events.empty();
80 }
81
82
83 /**
84 * @brief Retrieves and returns the next event from the front of the queue.
85 *
86 * @return A unique_ptr to the next event in teh queue, i.e. from the front
87 * position of the queue.
88 */
89 std::unique_ptr<const Event> next() override {
90 if (events.empty()) {
91 return nullptr;
92 }
93
94 auto event = std::move(events.front());
95 events.pop_front();
96
97 return event;
98 }
99
100 };
101
102}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.