blob: f9de97a0c4afb0aee11c9ecaf008b8dbb1fa7e1a (
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 <unordered_map>
#include <vector>
#include "command.h"
#include "either.h"
using namespace std;
class KeyInputMachine{
struct TreeNode{
Command *cmd=nullptr;
unordered_map<int,TreeNode*> *m=nullptr;
~TreeNode();
};
TreeNode root;
TreeNode *current=&root;
public:
KeyInputMachine();
KeyInputMachine(const vector<pair<vector<int>,Command>> &list);
KeyInputMachine(const KeyInputMachine&) = delete;
//Overwrites if already existent; ambiguous-prefix bindings not permitted
//at the moment
void insert(const vector<int> &keys,const Command &cmd);
//If Left, then true indicates 'still possibilities'; false indicates 'no more
//possible sequences left, error'
Either<bool,Command> input(int key);
//Cancel the current input combination
void cancel();
};
extern KeyInputMachine global_keyinput;
|