libevdevxx 0.4.0
A C++ wrapper for libevdev.
Loading...
Searching...
No Matches
Type.hpp
Go to the documentation of this file.
1/*
2 * libevdevxx - a C++ wrapper for libevdev
3 *
4 * Copyright (C) 2021-2023 Daniel K. O.
5 * SPDX-License-Identifier: MIT
6 */
7
8
9#ifndef LIBEVDEVXX_TYPE_HPP
10#define LIBEVDEVXX_TYPE_HPP
11
12
13#include <cstddef>
14#include <cstdint>
15#include <iosfwd>
16#include <stdexcept>
17#include <string>
18#include <string_view>
19
20#include <libevdev/libevdev.h>
21
22#include "detail/NumberBase.hpp"
23
24
25namespace evdev {
26
27 class Type :
28 public detail::NumberBase<std::uint16_t, Type> {
29
30 using Base = detail::NumberBase<std::uint16_t, Type>;
31
32
33 public:
34
35
36 constexpr
38 noexcept = default;
39
40
41 explicit
42 constexpr
43 Type(std::uint16_t number) :
44 Base{number}
45 {
46 if (number > EV_MAX)
47 throw std::invalid_argument{"invalid event type number"};
48 }
49
50
51 // named constructors
52
53 static
54 Type
55 parse(std::string_view name,
56 std::size_t* pos = nullptr);
57
58
59 static
60 constexpr
61 Type
63 noexcept
64 {
65 return Type{EV_MAX};
66 }
67
68
69 static
70 constexpr
71 std::uint16_t
73 noexcept
74 {
75 return EV_CNT;
76 }
77
78
79
80
81 static const Type syn;
82 static const Type key;
83 static const Type rel;
84 static const Type abs;
85 static const Type msc;
86 static const Type sw;
87 static const Type led;
88 static const Type snd;
89 static const Type rep;
90 static const Type ff;
91 static const Type pwr;
92 static const Type ff_status;
93
94
95 };
96
97
98#define DEFINE(x, y) \
99 inline constexpr const Type Type::x{EV_ ## y}
100
101 DEFINE(syn, SYN);
102 DEFINE(key, KEY);
103 DEFINE(rel, REL);
104 DEFINE(abs, ABS);
105 DEFINE(msc, MSC);
106 DEFINE(sw, SW);
107 DEFINE(led, LED);
108 DEFINE(snd, SND);
109 DEFINE(rep, REP);
110 DEFINE(ff, FF);
111 DEFINE(pwr, PWR);
112 DEFINE(ff_status, FF_STATUS);
113
114#undef DEFINE
115
116
117 std::string
119
120
121 std::ostream&
122 operator <<(std::ostream& out,
123 Type type);
124
125
126} // namespace evdev
127
128
129#endif
#define DEFINE(x, y)
Definition: Type.hpp:98
Definition: Type.hpp:28
static const Type syn
Definition: Type.hpp:81
static const Type rep
Definition: Type.hpp:89
static const Type rel
Definition: Type.hpp:83
constexpr Type() noexcept=default
static constexpr Type max() noexcept
Definition: Type.hpp:62
static const Type pwr
Definition: Type.hpp:91
static const Type key
Definition: Type.hpp:82
static Type parse(std::string_view name, std::size_t *pos=nullptr)
static const Type msc
Definition: Type.hpp:85
static const Type sw
Definition: Type.hpp:86
static const Type ff_status
Definition: Type.hpp:92
static const Type led
Definition: Type.hpp:87
static const Type ff
Definition: Type.hpp:90
static const Type abs
Definition: Type.hpp:84
static const Type snd
Definition: Type.hpp:88
static constexpr std::uint16_t count() noexcept
Definition: Type.hpp:72
The namespace of libevdevxx.
Definition: AbsInfo.hpp:20
std::string to_string(const AbsInfo &info)
std::ostream & operator<<(std::ostream &out, const AbsInfo &info)