OPALX (Object Oriented Parallel Accelerator Library for Exascal)
MINIorX
OPALX
ValueRange.h
Go to the documentation of this file.
1
//
2
// Class ValueRange
3
//
4
// This class provides functionality to compute the limits of a range of double values.
5
//
6
// Copyright (c) 2021, Christof Metzger-Kraus
7
//
8
// All rights reserved
9
//
10
// This file is part of OPAL.
11
//
12
// OPAL is free software: you can redistribute it and/or modify
13
// it under the terms of the GNU General Public License as published by
14
// the Free Software Foundation, either version 3 of the License, or
15
// (at your option) any later version.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
19
//
20
#ifndef VALUERANGE_H
21
#define VALUERANGE_H
22
23
#include "Utility/Inform.h"
24
25
#include <algorithm>
26
#include <limits>
27
28
template
<
class
T>
29
class
ValueRange
{
30
public
:
31
ValueRange
():
32
minValue_m
(
std
::numeric_limits<
T
>::max()),
33
maxValue_m
(
std
::numeric_limits<
T
>::lowest())
34
{}
35
36
void
enlargeIfOutside
(
T
value)
37
{
38
minValue_m
= std::min(
minValue_m
, value);
39
maxValue_m
= std::max(
maxValue_m
, value);
40
}
41
bool
isInside
(
T
value)
const
42
{
43
return
minValue_m
< value && value <
maxValue_m
;
44
}
45
46
bool
isOutside
(
T
value)
const
47
{
48
return
!
isInside
(value);
49
}
50
51
void
print
(Inform& out)
const
52
{
53
out <<
"Value range between "
<<
minValue_m
<<
" and "
<<
maxValue_m
;
54
}
55
private
:
56
T
minValue_m
;
57
T
maxValue_m
;
58
};
59
60
template
<
class
T>
61
Inform&
operator<<
(Inform& out,
ValueRange<T>
const
& range)
62
{
63
range.
print
(out);
64
return
out;
65
}
66
67
#endif
operator<<
Inform & operator<<(Inform &out, ValueRange< T > const &range)
Definition
ValueRange.h:61
T
double T
Definition
datatypes.h:7
std
STL namespace.
ValueRange
Definition
ValueRange.h:29
ValueRange::print
void print(Inform &out) const
Definition
ValueRange.h:51
ValueRange::maxValue_m
T maxValue_m
Definition
ValueRange.h:57
ValueRange::isOutside
bool isOutside(T value) const
Definition
ValueRange.h:46
ValueRange::enlargeIfOutside
void enlargeIfOutside(T value)
Definition
ValueRange.h:36
ValueRange::isInside
bool isInside(T value) const
Definition
ValueRange.h:41
ValueRange::ValueRange
ValueRange()
Definition
ValueRange.h:31
ValueRange::minValue_m
T minValue_m
Definition
ValueRange.h:56