| File Mode.cpp changed (mode: 100644) (index 88d58b7..4711dc9) |
| ... |
... |
Shortcut::Shortcut(std::wstring shortcut, std::function<void(int)> handler, |
| 39 |
39 |
descr(std::move(descr)) |
descr(std::move(descr)) |
| 40 |
40 |
{ } |
{ } |
| 41 |
41 |
|
|
| 42 |
|
Mode::Mode(std::string id) : id(std::move(id)) |
|
|
42 |
|
Mode::Mode(std::string id) : id(std::move(id)), useCount(false) |
| 43 |
43 |
{ } |
{ } |
| 44 |
44 |
|
|
| 45 |
45 |
void |
void |
| |
| ... |
... |
Mode::addShortcut(Shortcut shortcut) |
| 48 |
48 |
if (shortcut.shortcut.length() > 4U) { |
if (shortcut.shortcut.length() > 4U) { |
| 49 |
49 |
throw std::invalid_argument("Shortcut value is too long"); |
throw std::invalid_argument("Shortcut value is too long"); |
| 50 |
50 |
} |
} |
|
51 |
|
|
|
52 |
|
if (!seenShortcuts.emplace(shortcut.shortcut).second) { |
|
53 |
|
throw std::invalid_argument("Duplicated shortcut"); |
|
54 |
|
} |
|
55 |
|
|
| 51 |
56 |
shortcuts.emplace_back(std::move(shortcut)); |
shortcuts.emplace_back(std::move(shortcut)); |
| 52 |
57 |
} |
} |
| File Mode.hpp changed (mode: 100644) (index 21322f0..e95ec1b) |
| 22 |
22 |
#include <deque> |
#include <deque> |
| 23 |
23 |
#include <functional> |
#include <functional> |
| 24 |
24 |
#include <string> |
#include <string> |
|
25 |
|
#include <unordered_set> |
| 25 |
26 |
|
|
| 26 |
27 |
namespace vle { |
namespace vle { |
| 27 |
28 |
|
|
| |
| ... |
... |
public: |
| 69 |
70 |
{ return useCount; } |
{ return useCount; } |
| 70 |
71 |
|
|
| 71 |
72 |
// Registers a shortcut. Throws `std::invalid_argument` if shortcut is too |
// Registers a shortcut. Throws `std::invalid_argument` if shortcut is too |
| 72 |
|
// long. |
|
|
73 |
|
// long or a duplicate. |
| 73 |
74 |
void addShortcut(Shortcut shortcut); |
void addShortcut(Shortcut shortcut); |
| 74 |
75 |
// Retrieves shortcuts of this mode. |
// Retrieves shortcuts of this mode. |
| 75 |
76 |
const std::deque<Shortcut> & getShortcuts() const |
const std::deque<Shortcut> & getShortcuts() const |
| 76 |
77 |
{ return shortcuts; } |
{ return shortcuts; } |
| 77 |
78 |
|
|
| 78 |
79 |
private: |
private: |
| 79 |
|
std::string id; // Identifier of the mode. |
|
| 80 |
|
std::deque<Shortcut> shortcuts; // Shortcuts of this mode. |
|
| 81 |
|
bool useCount = false; // Whether count is used by shortcuts. |
|
|
80 |
|
// Identifier of the mode. |
|
81 |
|
std::string id; |
|
82 |
|
// Known hortcut values of this mode. |
|
83 |
|
std::unordered_set<std::wstring> seenShortcuts; |
|
84 |
|
// Shortcuts of this mode. |
|
85 |
|
std::deque<Shortcut> shortcuts; |
|
86 |
|
// Whether count is used by shortcuts. |
|
87 |
|
bool useCount; |
| 82 |
88 |
}; |
}; |
| 83 |
89 |
|
|
| 84 |
90 |
} |
} |