OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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
28template <class T>
30public:
32 : minValue_m(std::numeric_limits<T>::max()), maxValue_m(std::numeric_limits<T>::lowest()) {}
33
34 void enlargeIfOutside(T value) {
35 minValue_m = std::min(minValue_m, value);
36 maxValue_m = std::max(maxValue_m, value);
37 }
38 bool isInside(T value) const { return minValue_m < value && value < maxValue_m; }
39
40 bool isOutside(T value) const { return !isInside(value); }
41
42 void print(Inform& out) const {
43 out << "Value range between " << minValue_m << " and " << maxValue_m;
44 }
45
46private:
49};
50
51template <class T>
52Inform& operator<<(Inform& out, ValueRange<T> const& range) {
53 range.print(out);
54 return out;
55}
56
57#endif
double T
Definition OPALTypes.h:8
Inform & operator<<(Inform &out, ValueRange< T > const &range)
Definition ValueRange.h:52
void print(Inform &out) const
Definition ValueRange.h:42
bool isOutside(T value) const
Definition ValueRange.h:40
void enlargeIfOutside(T value)
Definition ValueRange.h:34
bool isInside(T value) const
Definition ValueRange.h:38
STL namespace.