blob: 410f3a6e72aa460723f8d3596c9998bde1756a15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#pragma once
#include "DI/auto_wirable.hpp"
#include "interfaces/input.hpp"
#include "interfaces/subscriber.hpp"
#include <array>
#include <climits>
#include <memory>
#include <termios.h>
#include <vector>
class InputHandler : public IInputHandler, public AutoWirable<IInputHandler, InputHandler>
{
public:
InputHandler() noexcept = default;
void listen() const noexcept override;
void
subscribe(const Event &event,
const std::shared_ptr<ISubscriber<Context>> &subscriber) noexcept override;
void notify_subscribers(const Event &event,
const Context &context) const noexcept override;
void enter_raw_mode() noexcept override;
void leave_raw_mode() noexcept override;
private:
std::array<std::vector<std::shared_ptr<ISubscriber<Context>>>,
static_cast<std::size_t>(CHAR_MAX * 2U)>
_subscribers;
std::shared_ptr<termios> _original_termios = nullptr;
using SubscribersSizeType = decltype(_subscribers)::size_type;
static auto _event_as_index(const Event &event) noexcept -> SubscribersSizeType;
};
|