libdrmconf
0.15.1
A library to program DMR radios.
Toggle main menu visibility
Loading...
Searching...
No Matches
ranges.hh
1
#ifndef RANGES_HH
2
#define RANGES_HH
3
4
#include <initializer_list>
5
#include "interval.hh"
6
#include "frequency.hh"
7
12
template
<
class
T>
13
class
Range
14
{
15
public
:
17
inline
T
map
(
const
T &n)
const
{
18
if
(n <
lower
)
19
return
lower
;
20
if
(
upper
< n)
21
return
upper
;
22
return
n;
23
}
24
26
inline
bool
contains
(
const
T &n)
const
{
27
return
((
lower
<n) || (
lower
==n)) && ((n<
upper
) || (n==
upper
));
28
}
29
30
public
:
31
T
lower
;
32
T
upper
;
33
};
34
35
37
template
<
class
T>
38
class
Ranges
39
{
40
public
:
42
inline
bool
contains
(
const
T &n)
const
{
43
for
(
auto
range:
ranges
) {
44
if
(range.contains(n))
45
return
true
;
46
}
47
return
false
;
48
}
49
50
public
:
52
QSet<Range<T>>
ranges
;
53
};
54
55
57
typedef
Range<unsigned int>
IntRange;
59
typedef
Range<Interval>
TimeRange;
61
typedef
Range<Frequency>
FrequencyRange;
62
63
#endif
// RANGES_HH
Range
Simple range class representing some range in some data type.
Definition
ranges.hh:14
Range< unsigned int >::upper
unsigned int upper
Definition
ranges.hh:32
Range< unsigned int >::lower
unsigned int lower
Definition
ranges.hh:31
Range::contains
bool contains(const T &n) const
Checks, if the given value lays within the range.
Definition
ranges.hh:26
Range::map
T map(const T &n) const
Maps a given value onto the range.
Definition
ranges.hh:17
Ranges
Implements a set of possibly overlapping ranges.
Definition
ranges.hh:39
Ranges::contains
bool contains(const T &n) const
Checks, if the given value lays within the range.
Definition
ranges.hh:42
Ranges::ranges
QSet< Range< T > > ranges
The set of ranges.
Definition
ranges.hh:52
lib
ranges.hh
Generated by
1.17.0