TermOx
event_queue.hpp
1 #ifndef TERMOX_SYSTEM_EVENT_QUEUE_HPP
2 #define TERMOX_SYSTEM_EVENT_QUEUE_HPP
3 #include <cstddef>
4 #include <utility>
5 #include <vector>
6 
7 #include <termox/common/unique_queue.hpp>
8 #include <termox/system/event_fwd.hpp>
9 
10 namespace ox {
11 
12 [[nodiscard]] auto operator<(Paint_event const& x, Paint_event const& y)
13  -> bool;
14 
15 [[nodiscard]] auto operator==(Paint_event const& a, Paint_event const& b)
16  -> bool;
17 
18 } // namespace ox
19 
20 namespace ox::detail {
21 
22 class Paint_queue {
23  public:
24  void append(Paint_event e);
25 
27  auto send_all() -> bool;
28 
29  [[nodiscard]] auto size() const -> std::size_t;
30 
31  private:
33 };
34 
35 class Delete_queue {
36  public:
37  void append(Delete_event e);
38 
39  void send_all();
40 
41  [[nodiscard]] auto size() const -> std::size_t;
42 
43  private:
44  std::vector<Delete_event> deletes_;
45 };
46 
47 class Basic_queue {
48  public:
49  void append(Event e);
50 
51  auto send_all() -> bool;
52 
53  [[nodiscard]] auto size() const -> std::size_t;
54 
55  private:
56  std::vector<Event> basics_;
57 };
58 
59 } // namespace ox::detail
60 
61 namespace ox {
62 
63 class Event_queue {
64  public:
66  void append(Event e);
67 
69  void send_all();
70 
71  private:
72  detail::Basic_queue basics_;
73  detail::Paint_queue paints_;
74  detail::Delete_queue deletes_;
75 
76  private:
77  template <typename T>
78  void add_to_a_queue(T e)
79  {
80  basics_.append(std::move(e));
81  }
82 
83  void add_to_a_queue(Paint_event e);
84 
85  void add_to_a_queue(Delete_event e);
86 };
87 
88 } // namespace ox
89 #endif // TERMOX_SYSTEM_EVENT_QUEUE_HPP
Definition: event_queue.hpp:63
void send_all()
Send all events, then flush the screen if any events were actually sent.
Definition: event_queue.cpp:84
void append(Event e)
Adds the given event with priority for the underlying event type.
Definition: event_queue.cpp:75
A Queue like container holding only unique values.
Definition: unique_queue.hpp:19
Definition: event_queue.hpp:47
Definition: event_queue.hpp:35
void send_all()
Definition: event_queue.cpp:47
Definition: event_queue.hpp:22
auto send_all() -> bool
Return true if any events are actually sent.
Definition: event_queue.cpp:32
Definition: event.hpp:72
Definition: event.hpp:23