-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValueRange.h
70 lines (55 loc) · 1.35 KB
/
ValueRange.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef VALUERANGE_H
#define VALUERANGE_H
#include <sstream>
#include <iomanip>
template <class T>
class ValueRange
{
public:
ValueRange(T initialValue)
{
myCurrentValue = initialValue;
myMinValue = initialValue;
myMaxValue = initialValue;
myRecordValue = initialValue;
}
virtual ~ValueRange() {}
void updateValue(T value)
{
myCurrentValue = value;
if (value < myMinValue)
{
myMinValue = value;
}
if (value > myMaxValue)
{
myMaxValue = value;
}
if (value > myRecordValue)
{
myRecordValue = value;
}
}
void newPeriod()
{
myMinValue = myCurrentValue;
myMaxValue = myCurrentValue;
}
T getCurrentValue() const { return myCurrentValue; }
T getMinValue() const { return myMinValue; }
T getMaxValue() const { return myMaxValue; }
T getRecordValue() const { return myRecordValue; }
std::string getRange() const
{
std::stringstream result;
result << std::setprecision(3) << std::fixed;
result << myMinValue << "-" << myMaxValue;
return result.str();
}
private:
T myCurrentValue;
T myMinValue;
T myMaxValue;
T myRecordValue;
};
#endif /* VALUERANGE_H */