summaryrefslogtreecommitdiff
path: root/src/bindings.h
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2015-05-09 19:42:57 +0200
committerAndrzej Rybczak <electricityispower@gmail.com>2015-05-09 19:42:57 +0200
commit078fc099f378bdbc4283cce6715c0ac8c341aaaf (patch)
tree23ad9383dec225488e2fac0dc7666ddbf26c9db6 /src/bindings.h
parent11735b42b3ad263379980380affbeca2b6a1e18f (diff)
bindings: implement Key and Command in terms of std::tuple
Diffstat (limited to 'src/bindings.h')
-rw-r--r--src/bindings.h52
1 files changed, 16 insertions, 36 deletions
diff --git a/src/bindings.h b/src/bindings.h
index f76132f8..06401469 100644
--- a/src/bindings.h
+++ b/src/bindings.h
@@ -33,42 +33,23 @@ struct Key
{
enum Type { Standard, NCurses };
- Key(wchar_t ch, Type ct) : m_char(ch), m_type(ct) { }
+ Key(wchar_t ch, Type ct) : m_impl(ch, ct) { }
- wchar_t getChar() const {
- return m_char;
- }
- Type getType() const {
- return m_type;
- }
-
-# define KEYS_DEFINE_OPERATOR(CMP) \
- bool operator CMP (const Key &k) const { \
- if (m_char CMP k.m_char) \
- return true; \
- if (m_char != k.m_char) \
- return false; \
- return m_type CMP k.m_type; \
- }
- KEYS_DEFINE_OPERATOR(<);
- KEYS_DEFINE_OPERATOR(<=);
- KEYS_DEFINE_OPERATOR(>);
- KEYS_DEFINE_OPERATOR(>=);
-# undef KEYS_DEFINE_OPERATOR
-
- bool operator==(const Key &k) const {
- return m_char == k.m_char && m_type == k.m_type;
- }
- bool operator!=(const Key &k) const {
- return !(*this == k);
- }
+ wchar_t getChar() const { return std::get<0>(m_impl); }
+ Type getType() const { return std::get<1>(m_impl); }
+ bool operator< (const Key &rhs) const { return m_impl < rhs.m_impl; }
+ bool operator<=(const Key &rhs) const { return m_impl <= rhs.m_impl; }
+ bool operator> (const Key &rhs) const { return m_impl > rhs.m_impl; }
+ bool operator>=(const Key &rhs) const { return m_impl >= rhs.m_impl; }
+ bool operator==(const Key &rhs) const { return m_impl == rhs.m_impl; }
+ bool operator!=(const Key &rhs) const { return m_impl != rhs.m_impl; }
+
static Key read(NC::Window &w);
static Key noOp;
- private:
- wchar_t m_char;
- Type m_type;
+private:
+ std::tuple<wchar_t, Type> m_impl;
};
/// Represents either single action or chain of actions bound to a certain key
@@ -108,14 +89,13 @@ struct Command
{
template <typename ArgT>
Command(ArgT &&binding_, bool immediate_)
- : m_binding(std::forward<ArgT>(binding_)), m_immediate(immediate_) { }
+ : m_impl(std::forward<ArgT>(binding_), immediate_) { }
- const Binding &binding() const { return m_binding; }
- bool immediate() const { return m_immediate; }
+ const Binding &binding() const { return std::get<0>(m_impl); }
+ bool immediate() const { return std::get<1>(m_impl); }
private:
- Binding m_binding;
- bool m_immediate;
+ std::tuple<Binding, bool> m_impl;
};
/// Keybindings configuration