Skip to main content

EventQueue.ixx File

Thread-safe queue for Event objects. More...

Included Headers

#include <functional> #include <memory> #include <helios.event.Event>

Namespaces Index

namespacehelios
namespaceevent

Event system. More...

Classes Index

classEventQueue

Abstract base class defining an interface for an EventQueue. More...

Description

Thread-safe queue for Event objects.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file EventQueue.ixx
3 * @brief Thread-safe queue for Event objects.
4 */
5module;
6
7#include <functional>
8#include <memory>
9
10export module helios.event.EventQueue;
11
12import helios.event.Event;
13
14export namespace helios::event {
15
16 /**
17 * @brief Abstract base class defining an interface for an EventQueue.
18 *
19 * The `EventQueue` provides mechanism to buffer and retrieve events in
20 * a structured manner. Implementing classes must define how events
21 * are stored and processed.
22 *
23 * All events managed by this queue must derive from `Event`
24 */
25 class EventQueue {
26
27 public:
28
29 virtual ~EventQueue() = default;
30
31
32 /**
33 * @brief Adds a new event to the queue.
34 * The queue will take ownership of the provided event.
35 * The concrete position in the queue for the event will depend on the concrete
36 * implementation.
37 *
38 * @param event A unique_ptr to the event this queue should buffer.
39 *
40 * @return EventQueue
41 */
42 virtual EventQueue& add(std::unique_ptr<const Event> event) = 0;
43
44
45 /**
46 * @brief Adds a new Event to the queue or replaces an existing one.
47 *
48 * This method allows for event management of events that should only be buffered
49 * once, but are added to the queue from different sources in the application, such
50 * that controlling the addition of events is not possible.
51 *
52 * Implementing classes ar responsible for treating the specified cmpFunc, provided
53 * by the caller.
54 *
55 * @param event A unique_ptr to a new or existing event that should be replaced.
56 * @param cmpFunc A compare function that provides the logic for looking up the event
57 * that should be replaced with the specified event. The compFunc must accept
58 * two event arguments, whereas the first argument is the Event to add, and the second
59 * event is an existing event of the queue.
60 *
61 *
62 * @return EventQueue
63 */
65 std::unique_ptr<const Event> event,
66 const std::function<bool(const std::unique_ptr<const Event>& evt,
67 const std::unique_ptr<const Event>& e)>& cmpFunc) = 0;
68
69 /**
70 * @brief Returns true if the queue is empty, otherwise false.
71 *
72 * @return True if the queue is empty, otherwise false.
73 */
74 [[nodiscard]] virtual bool empty() const noexcept = 0;
75
76
77 /**
78 * @brief Retrieves and removes the "next" event in the queue.
79 * Implementing classes are responsible for defining the meaning of "next",
80 * i.e., FIFO, LIFO, ordered after a particular criteria etc.
81 *
82 * The ownership of the event is transferred to the caller.
83 *
84 * @return a unique_ptr to the next event.
85 */
86 virtual std::unique_ptr<const Event> next() = 0;
87
88 };
89
90}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.