libdrmconf
0.15.1
A library to program DMR radios.
Toggle main menu visibility
Loading...
Searching...
No Matches
level.hh
1
#ifndef LEVEL_HH
2
#define LEVEL_HH
3
4
#include <QString>
5
#include <QMetaType>
6
#include <limits>
7
#include <yaml-cpp/yaml.h>
8
#include "codeplug.hh"
9
10
11
14
class
Level
15
{
16
protected
:
18
inline
constexpr
Level
(
unsigned
int
value
) :
_level
(
value
) {}
19
20
public
:
22
Level
();
23
24
inline
constexpr
Level
(
const
Level
&other)
25
:
_level
(other.
_level
)
26
{
27
// pass...
28
}
29
30
inline
Level
&operator =(
const
Level
&other) =
default
;
31
32
inline
bool
isNull
()
const
{
return
0 ==
_level
; }
34
inline
bool
isInvalid
()
const
{
35
return
std::numeric_limits<unsigned int>::max() ==
_level
;
36
}
37
38
inline
bool
isFinite
()
const
{
return
(!
isNull
()) && (!
isInvalid
()); }
39
40
inline
bool
operator !=
(
const
Level
&other)
const
{
41
return
_level
!= other.
_level
;
42
}
43
inline
bool
operator ==
(
const
Level
&other)
const
{
44
return
_level
== other.
_level
;
45
}
46
inline
bool
operator<
(
const
Level
&other)
const
{
47
return
_level
< other.
_level
;
48
}
49
inline
bool
operator<=
(
const
Level
&other)
const
{
50
return
_level
<= other.
_level
;
51
}
52
inline
bool
operator>
(
const
Level
&other)
const
{
53
return
_level
> other.
_level
;
54
}
55
inline
bool
operator>=
(
const
Level
&other)
const
{
56
return
_level
>= other.
_level
;
57
}
58
60
inline
unsigned
int
value
()
const
{
return
_level
; }
61
inline
unsigned
int
mapTo(
const
Codeplug::Element::Limit::Range<unsigned int>
&range)
const
{
62
if
(
isNull
() ||
isInvalid
())
63
return
0;
64
return
Codeplug::Element::Limit::Range<unsigned int>
{1,10}.
mapTo
(range,
value
());
65
}
66
68
QString
format
()
const
;
70
bool
parse
(
const
QString &
value
);
71
72
public
:
74
inline
static
constexpr
Level
null
() {
return
Level
(0); }
76
inline
static
constexpr
Level
invalid
() {
return
Level
(std::numeric_limits<unsigned int>::max()); }
78
inline
static
constexpr
Level
fromValue
(
unsigned
int
value
,
const
Codeplug::Element::Limit::Range<unsigned int>
range={1,10}) {
79
// If 0 is not in normal range -> always may 0 -> 0 (e.g. means off).
80
if
((0 ==
value
) && (0 != range.
min
))
81
return
Level::null
();
82
return
Level
(range.
mapTo
({1,10},
value
));
83
}
84
85
protected
:
87
unsigned
int
_level
;
88
};
89
90
91
Q_DECLARE_METATYPE(
Level
)
92
93
94
namespace
YAML
95
{
97
template
<>
98
struct
convert<
Level
>
99
{
101
static
Node
encode
(
const
Level
& rhs) {
102
return
Node(rhs.
format
().toStdString());
103
}
104
106
static
bool
decode
(
const
Node& node,
Level
& rhs) {
107
// Usually means default level
108
if
(node.IsNull()) {
109
rhs =
Level::invalid
();
110
return
true
;
111
}
112
// Fails on non-scalars
113
if
(!node.IsScalar())
114
return
false
;
115
// Otherwise, parse string.
116
return
rhs.
parse
(QString::fromStdString(node.as<std::string>()));
117
}
118
};
119
}
120
121
122
#endif
// LEVEL_HH
Level
Some simple class implementing a [1-10] level setting.
Definition
level.hh:15
Level::isNull
bool isNull() const
Test for 0.
Definition
level.hh:32
Level::parse
bool parse(const QString &value)
Parses a frequency.
Definition
level.cc:22
Level::operator!=
bool operator!=(const Level &other) const
Definition
level.hh:40
Level::operator>
bool operator>(const Level &other) const
Definition
level.hh:52
Level::value
unsigned int value() const
Returns the value of the level.
Definition
level.hh:60
Level::format
QString format() const
Format the frequency.
Definition
level.cc:12
Level::isInvalid
bool isInvalid() const
Test for invalid level.
Definition
level.hh:34
Level::Level
Level()
Default constructor.
Definition
level.cc:4
Level::null
static constexpr Level null()
Constructs null level.
Definition
level.hh:74
Level::Level
constexpr Level(unsigned int value)
Constructor from value.
Definition
level.hh:18
Level::fromValue
static constexpr Level fromValue(unsigned int value, const Codeplug::Element::Limit::Range< unsigned int > range={1, 10})
Constructs a proper level.
Definition
level.hh:78
Level::invalid
static constexpr Level invalid()
Constructs an invalid level.
Definition
level.hh:76
Level::isFinite
bool isFinite() const
Test for finite values.
Definition
level.hh:38
Level::operator>=
bool operator>=(const Level &other) const
Definition
level.hh:55
Level::operator<
bool operator<(const Level &other) const
Definition
level.hh:46
Level::_level
unsigned int _level
The actual level value.
Definition
level.hh:87
Level::operator==
bool operator==(const Level &other) const
Definition
level.hh:43
Level::operator<=
bool operator<=(const Level &other) const
Definition
level.hh:49
Codeplug::Element::Limit::Range
Holds a range of values [min, max].
Definition
codeplug.hh:94
Codeplug::Element::Limit::Range::mapTo
T mapTo(const Range< T > &other, const T &value) const
Maps a value from this range to the given range.
Definition
codeplug.hh:108
Codeplug::Element::Limit::Range::min
const T min
Lower bound.
Definition
codeplug.hh:96
YAML::convert< Level >::encode
static Node encode(const Level &rhs)
Serializes the interval.
Definition
level.hh:101
YAML::convert< Level >::decode
static bool decode(const Node &node, Level &rhs)
Parses the interval.
Definition
level.hh:106
lib
level.hh
Generated by
1.17.0