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 <algernon@madhouse-project.org>
pull/79/head
Gergely Nagy 8 years ago
parent 910b9db948
commit 0cfa1f7adb

@ -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;

Loading…
Cancel
Save