OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
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:
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:
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
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
bool isInside(T value) const
Definition: ValueRange.h:41
Definition: Inform.h:42
void enlargeIfOutside(T value)
Definition: ValueRange.h:36
bool isOutside(T value) const
Definition: ValueRange.h:46
void print(Inform &out) const
Definition: ValueRange.h:51