scalarRange.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::scalarRange
28 
29 Description
30  Scalar bounds to be used as a unary predicate.
31 
32  The bound can be specified as an "MIN:MAX" range, as a "MIN:" or ":MAX"
33  bound or simply as a single "VALUE".
34 
35  When defined via the parse() method, the special string "none" can be
36  used to define an empty (inverse) range.
37 
38 SeeAlso
39  Foam::MinMax
40  Foam::predicates::scalars
41 
42 SourceFiles
43  scalarRange.C
44 
45 \*---------------------------------------------------------------------------*/
46 #ifndef scalarRange_H
47 #define scalarRange_H
48 
49 #include "scalar.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward Declarations
57 class scalarRange;
58 class Ostream;
59 template<class T> class MinMax;
60 
61 Ostream& operator<<(Ostream& os, const scalarRange& range);
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class scalarRange Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class scalarRange
69 {
70  //- Enumeration defining type of range test to use
71  enum testType
72  {
73  NONE = 0,
74  EQ,
75  GE,
76  GT,
77  LE,
78  LT,
79  GE_LE,
80  ALWAYS
81  };
82 
83 
84  // Private Member Data
85 
86  //- The min value of the range
87  scalar min_;
88 
89  //- The max value of the range
90  scalar max_;
91 
92  //- The type of range test
93  enum testType type_;
94 
95  //- Construct from components without sanity checking
96  inline scalarRange
97  (
98  const testType type,
99  const scalar minVal,
100  const scalar maxVal
101  ) noexcept;
102 
103 
104 public:
105 
106  // STL type definitions
107 
108  //- Type of values the range contains
109  typedef scalar value_type;
110 
111 
112  // Static Data Members
113 
114  //- An empty/inverted range that never matches
115  static const scalarRange null;
116 
117  //- A range that always matches
118  static const scalarRange always;
119 
120 
121  // Constructors
122 
123  //- Construct an empty (inverse) range
124  inline scalarRange() noexcept;
125 
126  //- Construct an exact value matcher
127  inline explicit scalarRange(const scalar value) noexcept;
128 
129  //- Construct a range from min-value to max-value
130  inline scalarRange(const scalar minVal, const scalar maxVal) noexcept;
131 
132  //- Copy construct from a min/max range.
133  // Automatically decides if this is a GE_LE or NONE range
134  explicit scalarRange(const MinMax<label>& range) noexcept;
135 
136  //- Copy construct from a min/max range.
137  // Automatically decides if this is a GE_LE or NONE range
138  explicit scalarRange(const MinMax<scalar>& range) noexcept;
139 
140 
141  // Static Constructors
142 
143  //- Construct by parsing string content.
144  // A colon (:) is used as a range marker or when specifying
145  // greater-than or less-than bounds.
146  //
147  // \note The special string "none" can be used define an empty
148  // (inverse) range
149  //
150  // \return True if no parse problems were encountered.
151  static bool parse(const std::string& str, scalarRange& range);
152 
153  //- Construct by parsing string content.
154  // Any parse problems are emitted as information and the returned
155  // range is of type empty().
156  // \return The parsed range, which is empty() on any problems
157  static scalarRange parse(const std::string& str);
158 
159 
160  //- Construct a greater-equals bound
161  inline static scalarRange ge(const scalar minVal) noexcept;
162 
163  //- Construct a greater-than bound
164  inline static scalarRange gt(const scalar minVal) noexcept;
165 
166  //- Construct a greater-equals zero bound
167  inline static scalarRange ge0() noexcept;
168 
169  //- Construct a greater-than zero bound
170  inline static scalarRange gt0() noexcept;
171 
172  //- Construct a less-equals bound
173  inline static scalarRange le(const scalar maxVal) noexcept;
174 
175  //- Construct a less-than bound
176  inline static scalarRange lt(const scalar maxVal) noexcept;
177 
178  //- Construct a greater-equals 0, less-equals 1 bound
179  inline static scalarRange zero_one() noexcept;
180 
181 
182  // Member Functions
183 
184  //- Reset to an empty (inverse) range.
185  inline void clear() noexcept;
186 
187  //- True if range is empty (eg, inverted)
188  inline bool empty() const noexcept;
189 
190  //- True if range is non-empty.
191  inline bool valid() const noexcept;
192 
193  //- True if the range bounds represent a single value.
194  inline bool single() const noexcept;
195 
196  //- The min value of the range.
197  inline scalar min() const noexcept;
198 
199  //- The max value of the range.
200  inline scalar max() const noexcept;
201 
202  //- A representative (average) value for the range.
203  // For GE, LE bounds it is the min/max value, respectively.
204  inline scalar value() const;
205 
206  //- True if the value matches the condition.
207  inline bool match(const scalar& val) const;
208 
209 
210  // Member Operators
211 
212  //- Identical to match(), for use as a predicate.
213  inline bool operator()(const scalar& val) const;
214 
215  inline bool operator==(const scalarRange& rhs) const noexcept;
216  inline bool operator!=(const scalarRange& rhs) const noexcept;
217 
218 
219  // IOstream Operators
220 
221  //- Print information about the range.
222  friend Ostream& operator<<(Ostream& os, const scalarRange& range);
223 };
224 
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 } // End namespace Foam
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 #include "scalarRangeI.H"
233 
234 #endif
235 
236 // ************************************************************************* //
Foam::scalarRange::lt
static scalarRange lt(const scalar maxVal) noexcept
Construct a less-than bound.
Definition: scalarRangeI.H:103
Foam::scalarRange::gt0
static scalarRange gt0() noexcept
Construct a greater-than zero bound.
Definition: scalarRangeI.H:92
Foam::scalarRange::match
bool match(const scalar &val) const
True if the value matches the condition.
Definition: scalarRangeI.H:178
Foam::scalarRange::ge0
static scalarRange ge0() noexcept
Construct a greater-equals zero bound.
Definition: scalarRangeI.H:86
Foam::scalarRange::always
static const scalarRange always
A range that always matches.
Definition: scalarRange.H:117
Foam::scalarRange::parse
static bool parse(const std::string &str, scalarRange &range)
Construct by parsing string content.
Definition: scalarRange.C:48
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::scalarRange::max
scalar max() const noexcept
The max value of the range.
Definition: scalarRangeI.H:149
Foam::scalarRange
Scalar bounds to be used as a unary predicate.
Definition: scalarRange.H:67
Foam::scalarRange::gt
static scalarRange gt(const scalar minVal) noexcept
Construct a greater-than bound.
Definition: scalarRangeI.H:80
Foam::scalarRange::value_type
scalar value_type
Type of values the range contains.
Definition: scalarRange.H:108
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::scalarRange::min
scalar min() const noexcept
The min value of the range.
Definition: scalarRangeI.H:143
Foam::scalarRange::empty
bool empty() const noexcept
True if range is empty (eg, inverted)
Definition: scalarRangeI.H:125
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::scalarRange::scalarRange
scalarRange() noexcept
Construct an empty (inverse) range.
Definition: scalarRangeI.H:43
Foam::scalarRange::le
static scalarRange le(const scalar maxVal) noexcept
Construct a less-equals bound.
Definition: scalarRangeI.H:98
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::scalarRange::clear
void clear() noexcept
Reset to an empty (inverse) range.
Definition: scalarRangeI.H:117
Foam::scalarRange::ge
static scalarRange ge(const scalar minVal) noexcept
Construct a greater-equals bound.
Definition: scalarRangeI.H:74
Foam::scalarRange::single
bool single() const noexcept
True if the range bounds represent a single value.
Definition: scalarRangeI.H:137
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::MinMax
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: HashSet.H:76
Foam::scalarRange::valid
bool valid() const noexcept
True if range is non-empty.
Definition: scalarRangeI.H:131
Foam::scalarRange::zero_one
static scalarRange zero_one() noexcept
Construct a greater-equals 0, less-equals 1 bound.
Definition: scalarRangeI.H:109
Foam::scalarRange::value
scalar value() const
A representative (average) value for the range.
Definition: scalarRangeI.H:155