DUDS
Distributed Update of Data from Something
EventTypeCode.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #ifndef EVENTTYPECODE_HPP
11 #define EVENTTYPECODE_HPP
12 
13 #include <libevdev/libevdev.h>
14 #include <cstdint>
15 #include <string>
16 
17 #ifdef linux
18 // !@?!#?!#?
19 #undef linux
20 #endif
21 
22 namespace duds { namespace os { namespace linux {
23 
30  struct {
34  std::uint16_t type;
38  std::uint16_t code;
39  };
43  std::uint32_t typecode;
47  EventTypeCode() = default;
53  constexpr EventTypeCode(std::uint16_t t, std::uint16_t c) : type(t), code(c) { }
62  std::string typeName() const noexcept;
70  std::string typeName(const std::string &unknown) const noexcept;
79  std::string codeName() const noexcept;
87  std::string codeName(const std::string &unknown) const noexcept;
92  constexpr bool operator < (EventTypeCode etc) const {
93  return typecode < etc.typecode;
94  }
98  constexpr bool operator == (EventTypeCode etc) const {
99  return typecode == etc.typecode;
100  }
104  constexpr bool operator != (EventTypeCode etc) const {
105  return typecode != etc.typecode;
106  }
107 };
108 
109 } } }
110 
111 // hash implementation
112 namespace std {
113  template<> struct hash<duds::os::linux::EventTypeCode> {
114  std::size_t operator()(const duds::os::linux::EventTypeCode &etc) const noexcept {
115  return etc.typecode;
116  }
117  };
118 }
119 
120 #endif // #ifndef EVENTTYPECODE_HPP
constexpr bool operator!=(EventTypeCode etc) const
Obvious inequality operator.
constexpr EventTypeCode(std::uint16_t t, std::uint16_t c)
Constructs an EventTypeCode pre-filled with an event type and code.
STL namespace.
std::string codeName() const noexcept
Returns a string of the macro name for the event code, such as "REL_Y", or an empty string if the cod...
std::uint16_t code
An event code, such as KEY_A, ABS_X, or REL_Y.
constexpr bool operator<(EventTypeCode etc) const
Less-than comparison for EventTypeCode to allow it to be used as a key in a container class...
Combines an event type and an event code, as defined by libevdev, for the purpose of using a combinat...
std::uint16_t type
An event type, such as EV_KEY, EV_ABS, or EV_REL.
std::uint32_t typecode
The combined event type and code.
std::size_t operator()(const duds::os::linux::EventTypeCode &etc) const noexcept
constexpr bool operator==(EventTypeCode etc) const
Obvious equality operator.
EventTypeCode()=default
Makes this type trivially constructable.
std::string typeName() const noexcept
Returns a string of the macro name for the event type, such as "EV_KEY", or an empty string if the ty...