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-------------------------------------------------------------------------------
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.C
44
45\*---------------------------------------------------------------------------*/
46
47#ifndef scalarRange_H
48#define scalarRange_H
49
50#include "scalar.H"
51
52// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53
54namespace Foam
55{
56
57// Forward Declarations
58class scalarRange;
59class Ostream;
60template<class T> class MinMax;
61
62Ostream& operator<<(Ostream& os, const scalarRange& range);
63
64
65/*---------------------------------------------------------------------------*\
66 Class scalarRange Declaration
67\*---------------------------------------------------------------------------*/
69class scalarRange
70{
71 //- Enumeration defining type of range test to use
72 enum testType
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 type of range test
94 enum testType type_;
95
96 //- Construct from components, no checks
97 inline constexpr scalarRange
98 (
99 const testType 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;
117
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 //- Reset to an empty (inverse, NONE) range.
184 inline void clear() noexcept;
185
186 //- True if range is empty (eg, inverted, NONE)
187 inline bool empty() const noexcept;
188
189 //- True if range is non-empty.
190 inline bool valid() const noexcept;
191
192 //- True if the range bounds represent a single value.
193 inline bool single() const noexcept;
194
195 //- The min value of the range.
196 inline scalar min() const noexcept;
197
198 //- The max value of the range.
199 inline scalar max() const noexcept;
200
201 //- A representative (average) value for the range.
202 // For GE, LE bounds it is the min/max value, respectively.
203 inline scalar value() const;
204
205 //- True if the value matches the condition.
206 inline bool match(const scalar& val) const;
207
208
209 // Member Operators
210
211 //- Identical to match(), for use as a predicate.
212 inline bool operator()(const scalar& val) const;
213
214 inline constexpr bool operator==(const scalarRange& rhs) const noexcept;
215 inline constexpr bool operator!=(const scalarRange& rhs) const noexcept;
216
217
218 // IOstream Operators
219
220 //- Print information about the range.
221 friend Ostream& operator<<(Ostream& os, const scalarRange& range);
222};
223
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226
227} // End namespace Foam
228
229// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230
231#include "scalarRangeI.H"
232
233#endif
234
235// ************************************************************************* //
scalar range
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: MinMax.H:128
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Scalar bounds to be used as a unary predicate.
Definition: scalarRange.H:69
void clear() noexcept
Reset to an empty (inverse, NONE) range.
Definition: scalarRangeI.H:124
bool single() const noexcept
True if the range bounds represent a single value.
Definition: scalarRangeI.H:144
static constexpr scalarRange ge0() noexcept
A greater-equals zero bound.
Definition: scalarRangeI.H:89
scalar value() const
A representative (average) value for the range.
Definition: scalarRangeI.H:162
static constexpr scalarRange le(const scalar maxVal) noexcept
A less-equals bound.
Definition: scalarRangeI.H:103
bool match(const scalar &val) const
True if the value matches the condition.
Definition: scalarRangeI.H:185
bool empty() const noexcept
True if range is empty (eg, inverted, NONE)
Definition: scalarRangeI.H:132
static bool parse(const std::string &str, scalarRange &range)
Construct by parsing string content.
Definition: scalarRange.C:46
scalar min() const noexcept
The min value of the range.
Definition: scalarRangeI.H:150
scalar value_type
Type of values the range contains.
Definition: scalarRange.H:109
static constexpr scalarRange ge(const scalar minVal) noexcept
A greater-equals bound.
Definition: scalarRangeI.H:75
bool valid() const noexcept
True if range is non-empty.
Definition: scalarRangeI.H:138
static constexpr scalarRange gt0() noexcept
A greater-than zero bound.
Definition: scalarRangeI.H:96
static constexpr scalarRange lt(const scalar maxVal) noexcept
A less-than bound.
Definition: scalarRangeI.H:109
static const scalarRange always
A range that always matches.
Definition: scalarRange.H:115
scalar max() const noexcept
The max value of the range.
Definition: scalarRangeI.H:156
constexpr scalarRange() noexcept
Construct an empty (inverse, NONE) range - never matches.
Definition: scalarRangeI.H:43
static constexpr scalarRange gt(const scalar minVal) noexcept
A greater-than bound.
Definition: scalarRangeI.H:82
static constexpr scalarRange zero_one() noexcept
A greater-equals 0, less-equals 1 bound.
Definition: scalarRangeI.H:116
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223