blob: f17472b1afc3839f121648f5d3215b9ef68c0fc5 (
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
42
43
44
|
#pragma once
#include "interfaces/input.hpp"
#include "interfaces/subscriber.hpp"
#include <yacppdic/auto_wirable.hpp>
#include <array>
#include <climits>
#include <memory>
#include <termios.h>
#include <vector>
class InputHandler : public IInputHandler,
public yacppdic::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;
};
|