From 0cfa1f7adb9d8b7e334b07f37b2183f6b4fdf092 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 4 Jan 2017 14:26:16 +0100 Subject: [PATCH] key_defs: Add some operators Makes some code not only easier to follow (by not having to use `.raw` all the time), but for some odd reason, smaller too, in many cases. Signed-off-by: Gergely Nagy --- src/key_defs.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/key_defs.h b/src/key_defs.h index e6ee583e..d3c9447f 100644 --- a/src/key_defs.h +++ b/src/key_defs.h @@ -2,13 +2,26 @@ #include "HIDTables.h" -typedef union { +typedef union Key_ { struct { uint8_t flags; uint8_t rawKey; }; uint16_t raw; + + inline bool operator==(uint16_t rhs) { return this->raw == rhs; }; + inline bool operator==(const Key_ rhs) { return this->raw == rhs.raw; }; + inline Key_& operator=(uint16_t raw) { this->raw = raw; return *this; }; + inline bool operator!=(const Key_& rhs) { return !(*this == rhs); }; + inline bool operator>=(uint16_t raw) { return this->raw >= raw; }; + inline bool operator<=(uint16_t raw) { return this->raw <= raw; }; + inline bool operator>(uint16_t raw) { return this->raw > raw; }; + inline bool operator<(uint16_t raw) { return this->raw < raw; }; + inline bool operator>=(const Key_& other) { return this->raw >= other.raw; }; + inline bool operator<=(const Key_& other) { return this->raw <= other.raw; }; + inline bool operator>(const Key_& other) { return this->raw > other.raw; }; + inline bool operator<(const Key_& other) { return this->raw < other.raw; }; } Key;