From 078fc099f378bdbc4283cce6715c0ac8c341aaaf Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sat, 9 May 2015 19:42:57 +0200 Subject: bindings: implement Key and Command in terms of std::tuple --- src/bindings.h | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) (limited to 'src/bindings.h') 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 m_impl; }; /// Represents either single action or chain of actions bound to a certain key @@ -108,14 +89,13 @@ struct Command { template Command(ArgT &&binding_, bool immediate_) - : m_binding(std::forward(binding_)), m_immediate(immediate_) { } + : m_impl(std::forward(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 m_impl; }; /// Keybindings configuration -- cgit v1.2.3