blob: 6a9edfd5da83f94a655326d2a8a466cf72cd40e7 (
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
|
#pragma once
#include "DI/auto_wirable.hpp"
#include "interfaces/input.hpp"
#include "interfaces/subscriber.hpp"
#include <climits>
#include <memory>
#include <termios.h>
#include <unordered_map>
#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>>>, CHAR_MAX> _subscribers;
std::shared_ptr<termios> _original_termios = nullptr;
using _SubscribersSizeType = decltype(_subscribers)::size_type;
static _SubscribersSizeType _event_as_index(const Event &event) noexcept;
};
|