SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
sdrbase
util
max2d.h
Go to the documentation of this file.
1
// Copyright (C) 2018 F4EXB //
3
// written by Edouard Griffiths //
4
// //
5
// This program is free software; you can redistribute it and/or modify //
6
// it under the terms of the GNU General Public License as published by //
7
// the Free Software Foundation as version 3 of the License, or //
8
// (at your option) any later version. //
9
// //
10
// This program is distributed in the hope that it will be useful, //
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13
// GNU General Public License V3 for more details. //
14
// //
15
// You should have received a copy of the GNU General Public License //
16
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
18
19
#ifndef SDRBASE_UTIL_MAX2D_H_
20
#define SDRBASE_UTIL_MAX2D_H_
21
22
#include <algorithm>
23
24
template
<
typename
T>
25
class
Max2D
26
{
27
public
:
28
Max2D
() :
m_max
(0),
m_maxSize
(0),
m_width
(0),
m_size
(0),
m_maxIndex
(0) {}
29
30
~Max2D
()
31
{
32
if
(
m_max
) {
33
delete
[]
m_max
;
34
}
35
}
36
37
void
resize
(
unsigned
int
width,
unsigned
int
size)
38
{
39
if
(width >
m_maxSize
)
40
{
41
m_maxSize
= width;
42
if
(
m_max
) {
43
delete
[]
m_max
;
44
}
45
m_max
=
new
T[
m_maxSize
];
46
}
47
48
m_width
= width;
49
m_size
= size;
50
51
std::fill(
m_max
,
m_max
+
m_width
, 0);
52
m_maxIndex
= 0;
53
}
54
55
bool
storeAndGetMax
(T&
max
, T v,
unsigned
int
index)
56
{
57
if
(
m_size
<= 1)
58
{
59
max = v;
60
return
true
;
61
}
62
63
if
(
m_maxIndex
== 0)
64
{
65
m_max
[index] = v;
66
return
false
;
67
}
68
else
if
(
m_maxIndex
==
m_size
- 1)
69
{
70
m_max
[index] =
std::max
(
m_max
[index], v);
71
max =
m_max
[index];
72
return
true
;
73
}
74
else
75
{
76
m_max
[index] =
std::max
(
m_max
[index], v);
77
return
false
;
78
}
79
}
80
81
bool
nextMax
()
82
{
83
if
(
m_size
<= 1) {
84
return
true
;
85
}
86
87
if
(
m_maxIndex
==
m_size
- 1)
88
{
89
m_maxIndex
= 0;
90
std::fill(
m_max
,
m_max
+
m_width
, 0);
91
return
true
;
92
}
93
else
94
{
95
m_maxIndex
++;
96
return
false
;
97
}
98
}
99
100
private
:
101
T *
m_max
;
102
unsigned
int
m_maxSize
;
103
unsigned
int
m_width
;
104
unsigned
int
m_size
;
105
unsigned
int
m_maxIndex
;
106
};
107
108
#endif
/* SDRBASE_UTIL_MAX2D_H_ */
Max2D::m_maxIndex
unsigned int m_maxIndex
Definition:
max2d.h:105
Max2D::m_size
unsigned int m_size
Definition:
max2d.h:104
Max2D
Definition:
max2d.h:25
Max2D::storeAndGetMax
bool storeAndGetMax(T &max, T v, unsigned int index)
Definition:
max2d.h:55
Max2D::resize
void resize(unsigned int width, unsigned int size)
Definition:
max2d.h:37
Max2D::~Max2D
~Max2D()
Definition:
max2d.h:30
Max2D::Max2D
Max2D()
Definition:
max2d.h:28
Max2D::m_max
T * m_max
Definition:
max2d.h:101
Max2D::nextMax
bool nextMax()
Definition:
max2d.h:81
Max2D::m_width
unsigned int m_width
Definition:
max2d.h:103
Max2D::m_maxSize
unsigned int m_maxSize
Definition:
max2d.h:102
leansdr::max
T max(const T &x, const T &y)
Definition:
framework.h:446
Generated on Fri Aug 2 2019 17:56:33 for SDRAngel by
1.8.13