Loading...
Searching...
No Matches
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-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::scalarRange
28
29Description
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
38SeeAlso
39 Foam::MinMax
40 Foam::predicates::scalars
41
42SourceFiles
43 scalarRange.cxx
44 scalarRangeI.H
45
46\*---------------------------------------------------------------------------*/
47
48#ifndef Foam_scalarRange_H
49#define Foam_scalarRange_H
50
51#include "scalar.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
58// Forward Declarations
59class scalarRange;
60template<class T> class MinMax;
61
63
65/*---------------------------------------------------------------------------*\
66 Class scalarRange Declaration
67\*---------------------------------------------------------------------------*/
68
69class scalarRange
70{
71 //- The type of range
72 enum rangeTypes : unsigned char
73 {
74 NONE = 0,
75 EQ,
76 GE,
77 GT,
78 LE,
79 LT,
80 GE_LE,
81 ALWAYS
82 };
83
84
85 // Private Member Data
86
87 //- The min value of the range
88 scalar min_;
89
90 //- The max value of the range
91 scalar max_;
92
93 //- The range type
94 enum rangeTypes type_;
95
96 //- Construct from components, no checks
97 inline constexpr scalarRange
98 (
99 const rangeTypes type,
100 const scalar minVal,
101 const scalar maxVal
102 ) noexcept;
103
104
105public:
106
107 // STL type definitions
108
109 //- Type of values the range contains
110 typedef scalar value_type;
111
112
113 // Static Data Members
114
115 //- A range that always matches
116 static const scalarRange always;
118
119 // Constructors
120
121 //- Construct an empty (inverse, NONE) range - never matches
122 inline constexpr scalarRange() noexcept;
123
124 //- Construct an exact value matcher
125 inline explicit constexpr scalarRange(const scalar val) noexcept;
126
127 //- Construct a range from min-value to max-value
128 // Check validity of the range and sets to NONE or EQ if required.
129 inline scalarRange(const scalar minVal, const scalar maxVal) noexcept;
130
131 //- Copy construct from a min/max range.
132 // Automatically decides if this is a GE_LE or NONE range
133 explicit scalarRange(const MinMax<label>& range) noexcept;
134
135 //- Copy construct from a min/max range.
136 // Automatically decides if this is a GE_LE or NONE range
137 explicit scalarRange(const MinMax<scalar>& range) noexcept;
138
139
140 // Static Constructors
141
142 //- Construct by parsing string content.
143 // A colon (:) is used as a range marker or when specifying
144 // greater-than or less-than bounds.
145 //
146 // \note The special string "none" can be used define an empty
147 // (inverse) range
148 //
149 // \return True if no parse problems were encountered.
150 static bool parse(const std::string& str, scalarRange& range);
151
152 //- Construct by parsing string content.
153 // Any parse problems are emitted as information and the returned
154 // range is of type empty().
155 // \return The parsed range, which is empty() on any problems
156 static scalarRange parse(const std::string& str);
157
158
159 //- A greater-equals bound
160 inline static constexpr scalarRange ge(const scalar minVal) noexcept;
161
162 //- A greater-than bound
163 inline static constexpr scalarRange gt(const scalar minVal) noexcept;
164
165 //- A greater-equals zero bound
166 inline static constexpr scalarRange ge0() noexcept;
167
168 //- A greater-than zero bound
169 inline static constexpr scalarRange gt0() noexcept;
170
171 //- A less-equals bound
172 inline static constexpr scalarRange le(const scalar maxVal) noexcept;
173
174 //- A less-than bound
175 inline static constexpr scalarRange lt(const scalar maxVal) noexcept;
176
177 //- A greater-equals 0, less-equals 1 bound
178 inline static constexpr scalarRange zero_one() noexcept;
179
180
181 // Member Functions
182
183 //- True if range is empty (eg, inverted, NONE)
184 inline bool empty() const noexcept;
185
186 //- True if range is non-empty.
187 inline bool good() const noexcept;
188
189 //- True if the range bounds represent a single value.
190 inline bool single() const noexcept;
191
192 //- The min value of the range.
193 scalar min() const noexcept { return min_; }
194
195 //- The max value of the range.
196 scalar max() const noexcept { return max_; }
197
198 //- Reset to an empty (inverse, NONE) range.
199 inline void reset() noexcept;
200
201 //- Same as reset() - reset to an empty (inverse, NONE) range.
202 void clear() noexcept { reset(); }
203
204
205 //- A representative (average) value for the range.
206 // For GE, LE bounds it is the min/max value, respectively.
207 inline scalar value() const;
208
209 //- True if the value is matched by the condition
210 inline bool contains(const scalar val) const;
211
212 //- True if the value is matched by the condition
213 bool match(const scalar value) const { return contains(value); }
214
215
216 // Member Operators
217
218 //- For use as a predicate, same as contains(), match()
219 bool operator()(const scalar value) const { return contains(value); }
220
221 inline constexpr bool operator==(const scalarRange& rhs) const noexcept;
222 inline constexpr bool operator!=(const scalarRange& rhs) const noexcept;
223
224
225 // IOstream Operators
226
227 //- Print information about the range
228 void print(Ostream& os) const;
229
230 //- Print information about the range
231 friend Ostream& operator<<(Ostream& os, const scalarRange& range);
232
233
234 // Housekeeping
235
236 //- Same as good() or !empty()
237 bool valid() const noexcept { return good(); }
238};
239
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243} // End namespace Foam
244
245// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246
247#include "scalarRangeI.H"
249#endif
250
251// ************************************************************************* //
scalar range
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition MinMax.H:106
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Scalar bounds to be used as a unary predicate.
Definition scalarRange.H:65
void clear() noexcept
Same as reset() - reset to an empty (inverse, NONE) range.
bool single() const noexcept
True if the range bounds represent a single value.
void reset() noexcept
Reset to an empty (inverse, NONE) range.
scalar min() const noexcept
The min value of the range.
bool operator()(const scalar value) const
For use as a predicate, same as contains(), match().
static constexpr scalarRange ge0() noexcept
A greater-equals zero bound.
scalar value() const
A representative (average) value for the range.
static constexpr scalarRange le(const scalar maxVal) noexcept
A less-equals bound.
bool empty() const noexcept
True if range is empty (eg, inverted, NONE).
bool good() const noexcept
True if range is non-empty.
bool contains(const scalar val) const
True if the value is matched by the condition.
void print(Ostream &os) const
Print information about the range.
static bool parse(const std::string &str, scalarRange &range)
Construct by parsing string content.
scalar value_type
Type of values the range contains.
constexpr bool operator!=(const scalarRange &rhs) const noexcept
static constexpr scalarRange ge(const scalar minVal) noexcept
A greater-equals bound.
bool valid() const noexcept
Same as good() or !empty().
static constexpr scalarRange gt0() noexcept
A greater-than zero bound.
static constexpr scalarRange lt(const scalar maxVal) noexcept
A less-than bound.
friend Ostream & operator<<(Ostream &os, const scalarRange &range)
Print information about the range.
scalar max() const noexcept
The max value of the range.
bool match(const scalar value) const
True if the value is matched by the condition.
constexpr scalarRange() noexcept
Construct an empty (inverse, NONE) range - never matches.
static const scalarRange always
A range that always matches.
static constexpr scalarRange gt(const scalar minVal) noexcept
A greater-than bound.
constexpr bool operator==(const scalarRange &rhs) const noexcept
static constexpr scalarRange zero_one() noexcept
A greater-equals 0, less-equals 1 bound.
OBJstream os(runTime.globalPath()/outputName)
surface1 clear()
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265