Loading...
Searching...
No Matches
Instant.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-2025 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::Instant
28
29Description
30 A tuple of scalar value and key.
31 The value often corresponds to a time value, thus the naming of the class.
32 The key will usually be a time name or a file name etc.
33
34\*---------------------------------------------------------------------------*/
35
36#ifndef Foam_Instant_H
37#define Foam_Instant_H
38
39#include "scalar.H"
40#include <utility> // std::move
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44namespace Foam
46
47/*---------------------------------------------------------------------------*\
48 Class Instant Declaration
49\*---------------------------------------------------------------------------*/
50
51template<class T>
52class Instant
53{
54 // Private Data
55
56 //- The value (eg, time)
57 scalar val_;
58
59 //- The name/key
60 T key_;
61
62
63public:
64
65 // Public Classes
66
67 //- Less function for sorting. Compares values only
68 struct less
69 {
70 template<class T1, class T2>
71 bool operator()
72 (
73 const Instant<T1>& a,
74 const Instant<T2>& b
75 ) const noexcept
76 {
77 return (a.value() < b.value());
78 }
79 };
80
81
82 // Generated Methods
83
84 //- Copy construct
85 Instant(const Instant&) = default;
87 //- Move construct
88 Instant(Instant&&) = default;
89
90 //- Copy assignment
91 Instant& operator=(const Instant&) = default;
92
93 //- Move assignment
94 Instant& operator=(Instant&&) = default;
95
97 // Constructors
98
99 //- Default construct, with value = 0 and empty name
100 Instant()
102 val_(0),
103 key_()
104 {}
105
106 //- Copy construct from components
107 Instant(scalar val, const T& key)
108 :
109 val_(val),
110 key_(key)
111 {}
112
113 //- Move construct from components
114 Instant(scalar val, T&& key)
115 :
116 val_(val),
117 key_(std::move(key))
118 {}
119
120
121 // Member Functions
122
123 //- The value (const access)
124 scalar value() const noexcept { return val_; }
125
126 //- The value (non-const access)
127 scalar& value() noexcept { return val_; }
128
129 //- The name/key (const access)
130 const T& name() const noexcept { return key_; }
131
132 //- The name/key (non-const access)
133 T& name() noexcept { return key_; }
134
135
136 // Comparison Methods (Static)
137
138 //- Are values equal within (SMALL) rounding tolerance?
139 static constexpr bool equal_to(scalar a, scalar b) noexcept
140 {
141 return ((a > b - SMALL) && (a < b + SMALL));
142 }
143
144 //- Are values less-equal within (SMALL) rounding tolerance?
145 static constexpr bool less_equal(scalar a, scalar b) noexcept
146 {
147 return (a < b + SMALL);
148 }
150 //- Are values greater_equal within (SMALL) rounding tolerance?
151 static constexpr bool greater_equal(scalar a, scalar b) noexcept
152 {
153 return (a > b - SMALL);
155
156
157 // Comparison Methods
158
159 //- Is instant value equal to \p val within (SMALL) rounding?
160 bool equal(scalar val) const noexcept
161 {
162 return equal_to(this->value(), val);
163 }
164
165 //- Is instant value equal to \p other within (SMALL) rounding?
166 template<class T2>
167 bool equal(const Instant<T2>& other) const noexcept
168 {
169 return equal_to(this->value(), other.value());
171
172 //- Is instant less-equal than \p val within (SMALL) rounding?
173 bool less_equal(scalar val) const noexcept
174 {
175 return less_equal(this->value(), val);
176 }
177
178 //- Is instant less-equal than \p other within (SMALL) rounding?
179 template<class T2>
180 bool less_equal(const Instant<T2>& other) const noexcept
181 {
182 return less_equal(this->value(), other.value());
183 }
184
185 //- Is instant greater-equal than \p val within (SMALL) rounding?
186 bool greater_equal(scalar val) const noexcept
187 {
188 return less_equal(val, this->value());
190
191 //- Is instant greater-equal than \p other within (SMALL) rounding?
192 template<class T2>
193 bool greater_equal(const Instant<T2>& other) const noexcept
194 {
195 return less_equal(other.value(), this->value());
196 }
197
199 // Member Operators
200
201 //- Is instant less-equal than \p val within (SMALL) rounding?
202 bool operator<=(scalar val) const noexcept
203 {
204 return less_equal(this->value(), val);
205 }
207 //- Is instant less-equal than \p other within (SMALL) rounding?
208 template<class T2>
209 bool operator<=(const Instant<T2>& other) const noexcept
210 {
211 return less_equal(this->value(), other.value());
212 }
213
214 //- Is instant greater-equal than \p val within (SMALL) rounding?
215 bool operator>=(scalar val) const noexcept
216 {
217 return greater_equal(this->value(), val);
218 }
219
220 //- Is instant greater-equal than \p other within (SMALL) rounding?
221 template<class T2>
222 bool operator>=(const Instant<T2>& other) const noexcept
224 return greater_equal(this->value(), other.value());
225 }
226};
227
228
229// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
230
231//- True if instant values are equal within rounding tolerance
232template<class T1, class T2>
233inline bool operator==(const Instant<T1>& a, const Instant<T2>& b) noexcept
234{
235 return a.equal(b.value());
236}
237
238
239//- True if instant values are not equal within rounding tolerance
240template<class T1, class T2>
241inline bool operator!=(const Instant<T1>& a, const Instant<T2>& b) noexcept
242{
243 return !a.equal(b.value());
244}
245
246
247template<class T1, class T2>
248inline bool operator<(const Instant<T1>& a, const Instant<T2>& b) noexcept
249{
250 return (a.value() < b.value());
251}
253
254template<class T1, class T2>
255inline bool operator>(const Instant<T1>& a, const Instant<T2>& b) noexcept
256{
257 return (b.value() < a.value());
258}
259
261// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
262
263//- Read instant tuple from Istream
264template<class T>
265inline Istream& operator>>(Istream& is, Instant<T>& inst)
266{
267 is >> inst.value() >> inst.name();
268 return is;
270
271
272//- Write instant tuple to Ostream
273template<class T>
274inline Ostream& operator<<(Ostream& os, const Instant<T>& inst)
275{
276 os << inst.value() << '\t' << inst.name();
277 return os;
278}
279
280
281// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283} // End namespace Foam
284
285// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286
287#endif
288
289// ************************************************************************* //
A tuple of scalar value and key. The value often corresponds to a time value, thus the naming of the ...
Definition Instant.H:46
Instant(scalar val, T &&key)
Move construct from components.
Definition Instant.H:127
bool greater_equal(const Instant< T2 > &other) const noexcept
Is instant greater-equal than other within (SMALL) rounding?
Definition Instant.H:232
Instant & operator=(Instant &&)=default
Move assignment.
static constexpr bool equal_to(scalar a, scalar b) noexcept
Are values equal within (SMALL) rounding tolerance?
Definition Instant.H:162
Instant(const Instant &)=default
Copy construct.
T & name() noexcept
The name/key (non-const access).
Definition Instant.H:154
scalar value() const noexcept
The value (const access).
Definition Instant.H:139
Instant()
Default construct, with value = 0 and empty name.
Definition Instant.H:109
static constexpr bool less_equal(scalar a, scalar b) noexcept
Are values less-equal within (SMALL) rounding tolerance?
Definition Instant.H:170
const T & name() const noexcept
The name/key (const access).
Definition Instant.H:149
Instant(scalar val, const T &key)
Copy construct from components.
Definition Instant.H:118
scalar & value() noexcept
The value (non-const access).
Definition Instant.H:144
bool less_equal(const Instant< T2 > &other) const noexcept
Is instant less-equal than other within (SMALL) rounding?
Definition Instant.H:215
bool operator>=(const Instant< T2 > &other) const noexcept
Is instant greater-equal than other within (SMALL) rounding?
Definition Instant.H:269
Instant(Instant &&)=default
Move construct.
bool greater_equal(scalar val) const noexcept
Is instant greater-equal than val within (SMALL) rounding?
Definition Instant.H:223
bool operator<=(scalar val) const noexcept
Is instant less-equal than val within (SMALL) rounding?
Definition Instant.H:243
bool operator<=(const Instant< T2 > &other) const noexcept
Is instant less-equal than other within (SMALL) rounding?
Definition Instant.H:252
bool equal(const Instant< T2 > &other) const noexcept
Is instant value equal to other within (SMALL) rounding?
Definition Instant.H:198
bool operator>=(scalar val) const noexcept
Is instant greater-equal than val within (SMALL) rounding?
Definition Instant.H:260
bool less_equal(scalar val) const noexcept
Is instant less-equal than val within (SMALL) rounding?
Definition Instant.H:206
static constexpr bool greater_equal(scalar a, scalar b) noexcept
Are values greater_equal within (SMALL) rounding tolerance?
Definition Instant.H:178
Instant & operator=(const Instant &)=default
Copy assignment.
bool equal(scalar val) const noexcept
Is instant value equal to val within (SMALL) rounding?
Definition Instant.H:189
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition eddy.H:297
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Istream & operator>>(Istream &, directionInfo &)
const direction noexcept
Definition scalarImpl.H:265
bool operator<(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A older than B.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
bool operator>(const IOstreamOption::versionNumber &a, const IOstreamOption::versionNumber &b) noexcept
Version A newer than B.
volScalarField & b
Less function for sorting. Compares values only.
Definition Instant.H:68