Loading...
Searching...
No Matches
IOobjectOption.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) 2011 OpenFOAM Foundation
9 Copyright (C) 2016-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::IOobjectOption
29
30Description
31 A simple container of IOobject preferences.
32 Can also be used for general handling of read/no-read/read-if-present
33 logic outside of an IOobject.
34
35See also
36 Foam::IOobject
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_IOobjectOption_H
41#define Foam_IOobjectOption_H
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48/*---------------------------------------------------------------------------*\
49 Class IOobjectOption Declaration
50\*---------------------------------------------------------------------------*/
51
53{
54public:
55
56 // Public Data Types
58 //- Enumeration defining read preferences
59 // Lowest bit encodes 'must read'.
60 // Possible (future) named variants (none | normal | modified | lazy)
61 enum readOption : unsigned char
62 {
64 NO_READ = 0,
65
67 MUST_READ = 0x1,
68
72
76
78 LAZY_READ = 0x4,
79
81 READ_IF_PRESENT = 0x4
82 };
84 //- Enumeration defining write preferences
85 enum writeOption : unsigned char
86 {
88 NO_WRITE = 0,
91 AUTO_WRITE = 0x10
92 };
93
94 //- Enumeration for use with registerObject().
95 //- Values map to bool (false/true)
96 enum registerOption : unsigned char
97 {
100
103
106 };
107
108 //- The layout of the case structure
109 enum class Layout : unsigned char
110 {
111 //! Regular case layout, eg processor-local locations
112 regular,
115 };
117private:
118
119 // Private Data
120
121 //- Read option
122 readOption readOpt_;
123
124 //- Write option
125 writeOption writeOpt_;
126
127 //- Should created objects be registered?
128 bool registerObject_;
129
130 //- Is object same for all processors?
131 bool globalObject_;
132
133
134public:
135
136 // Constructors
137
138 //- Default construct (NO_READ, NO_WRITE, REGISTER, non-global)
139 //- or construct with specified options
140 constexpr IOobjectOption
141 (
145 bool globalObject = false
146 ) noexcept
147 :
148 readOpt_(rOpt),
149 writeOpt_(wOpt),
150 registerObject_(registerObject),
151 globalObject_(globalObject)
152 {}
153
154 //- Construct NO_WRITE with specified read/register options
155 constexpr IOobjectOption
156 (
157 readOption rOpt,
159 bool globalObject = false
160 ) noexcept
161 :
162 readOpt_(rOpt),
163 writeOpt_(writeOption::NO_WRITE),
164 registerObject_(registerObject),
165 globalObject_(globalObject)
166 {}
167
168 //- Construct NO_READ with specified write/register options
170 (
171 writeOption wOpt,
173 bool globalObject = false
174 ) noexcept
175 :
176 readOpt_(readOption::NO_READ),
177 writeOpt_(wOpt),
178 registerObject_(registerObject),
179 globalObject_(globalObject)
180 {}
181
182 //- Construct (NO_READ, NO_WRITE) with specified register option
183 constexpr IOobjectOption
184 (
186 bool globalObject = false
187 ) noexcept
188 :
189 readOpt_(readOption::NO_READ),
190 writeOpt_(writeOption::NO_WRITE),
191 registerObject_(registerObject),
192 globalObject_(globalObject)
193 {}
194
195 //- Construct from components
196 //- with specified register option as bool
197 constexpr IOobjectOption
198 (
199 readOption rOpt,
200 writeOption wOpt,
202 bool globalObject = false
203 ) noexcept
204 :
205 readOpt_(rOpt),
206 writeOpt_(wOpt),
207 registerObject_(registerObject ? REGISTER : NO_REGISTER),
208 globalObject_(globalObject)
209 {}
210
211 //- Construct (NO_READ, NO_WRITE)
212 //- with specified register option as bool
213 explicit constexpr IOobjectOption
214 (
215 bool registerObject,
216 bool globalObject = false
218 :
219 readOpt_(readOption::NO_READ),
220 writeOpt_(writeOption::NO_WRITE),
221 registerObject_(registerObject ? REGISTER : NO_REGISTER),
222 globalObject_(globalObject)
223 {}
224
225
226 // Member Functions
227
228 //- Get the read option
229 readOption readOpt() const noexcept { return readOpt_; }
230
231 //- Set the read option \return the previous value
232 readOption readOpt(readOption opt) noexcept
233 {
234 readOption old(readOpt_);
235 readOpt_ = opt;
236 return old;
237 }
238
239 //- Get the write option
240 writeOption writeOpt() const noexcept { return writeOpt_; }
241
242 //- Set the write option \return the previous value
243 writeOption writeOpt(writeOption opt) noexcept
244 {
245 writeOption old(writeOpt_);
246 writeOpt_ = opt;
247 return old;
248 }
249
250 //- Should objects created with this IOobject be registered?
251 bool registerObject() const noexcept { return registerObject_; }
252
253 //- Change registration preference \return previous value
254 bool registerObject(bool on) noexcept
255 {
256 bool old(registerObject_);
257 registerObject_ = on;
258 return old;
259 }
260
261 //- True if object is treated the same for all processors
262 bool globalObject() const noexcept { return globalObject_; }
263
264 //- Change global-object status \return previous value
265 bool globalObject(bool on) noexcept
266 {
267 bool old(globalObject_);
268 globalObject_ = on;
269 return old;
270 }
271
272
273 // Checks
274
275 //- True if any reading may be required (ie, != NO_READ)
276 static bool isAnyRead(readOption opt) noexcept
277 {
278 return (opt != readOption::NO_READ);
279 }
280
281 //- True if any reading may be required (ie, != NO_READ)
282 bool isAnyRead() const noexcept
284 return (readOpt_ != readOption::NO_READ);
285 }
286
287 //- True if (MUST_READ | READ_MODIFIED) bits are set
288 static bool isReadRequired(readOption opt) noexcept
289 {
290 return (opt & readOption::MUST_READ);
291 }
292
293 //- True if (MUST_READ | READ_MODIFIED) bits are set
294 bool isReadRequired() const noexcept
295 {
296 return (readOpt_ & readOption::MUST_READ);
297 }
299 //- True if (LAZY_READ) bits are set [same as READ_IF_PRESENT]
300 static bool isReadOptional(readOption opt) noexcept
301 {
302 return (opt == readOption::LAZY_READ);
304
305 //- True if (LAZY_READ) bits are set [same as READ_IF_PRESENT]
306 bool isReadOptional() const noexcept
307 {
308 return (readOpt_ == readOption::LAZY_READ);
309 }
310
311 //- Downgrade readOption optional (LAZY_READ), leaves NO_READ intact.
312 static readOption lazierRead(readOption opt) noexcept
313 {
314 return (opt == readOption::NO_READ ? opt : readOption::LAZY_READ);
315 }
317
318 // Housekeeping
319
320 //- Access to the read option
321 // \deprecated(2021-03) - use readOpt(readOption)
322 readOption& readOpt() noexcept { return readOpt_; }
323
324 //- Access to the write option
325 // \deprecated(2021-03) - use writeOpt(writeOption)
326 writeOption& writeOpt() noexcept { return writeOpt_; }
327
328 //- Access to the register object option
329 // \deprecated(2021-03) - use registerObject(bool)
330 bool& registerObject() noexcept { return registerObject_; }
331
332 //- Access to the global object option
333 // \deprecated(2021-03) - use globalObject(bool)
334 bool& globalObject() noexcept { return globalObject_; }
335};
336
337
338// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339
340} // End namespace Foam
341
342// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
343
344#endif
345
346// ************************************************************************* //
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ NO_REGISTER
Do not request registration (bool: false).
@ LEGACY_REGISTER
Legacy/default registration request (bool: true).
@ REGISTER
Request registration (bool: true).
writeOption writeOpt(writeOption opt) noexcept
Set the write option.
constexpr IOobjectOption(readOption rOpt=readOption::NO_READ, writeOption wOpt=writeOption::NO_WRITE, registerOption registerObject=registerOption::REGISTER, bool globalObject=false) noexcept
Default construct (NO_READ, NO_WRITE, REGISTER, non-global) or construct with specified options.
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
constexpr IOobjectOption(writeOption wOpt, registerOption registerObject=registerOption::REGISTER, bool globalObject=false) noexcept
Construct NO_READ with specified write/register options.
bool globalObject() const noexcept
True if object is treated the same for all processors.
bool registerObject(bool on) noexcept
Change registration preference.
static bool isReadOptional(readOption opt) noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isAnyRead() const noexcept
True if any reading may be required (ie, != NO_READ).
readOption readOpt() const noexcept
Get the read option.
bool & registerObject() noexcept
Access to the register object option.
writeOption writeOpt() const noexcept
Get the write option.
readOption & readOpt() noexcept
Access to the read option.
bool registerObject() const noexcept
Should objects created with this IOobject be registered?
Layout
The layout of the case structure.
@ global
Global case layout (serial locations).
@ regular
Regular case layout, eg processor-local locations.
static readOption lazierRead(readOption opt) noexcept
Downgrade readOption optional (LAZY_READ), leaves NO_READ intact.
constexpr IOobjectOption(bool registerObject, bool globalObject=false) noexcept
Construct (NO_READ, NO_WRITE) with specified register option as bool.
constexpr IOobjectOption(readOption rOpt, writeOption wOpt, bool registerObject, bool globalObject=false) noexcept
Construct from components with specified register option as bool.
static bool isReadRequired(readOption opt) noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
constexpr IOobjectOption(readOption rOpt, registerOption registerObject=registerOption::REGISTER, bool globalObject=false) noexcept
Construct NO_WRITE with specified read/register options.
bool & globalObject() noexcept
Access to the global object option.
readOption readOpt(readOption opt) noexcept
Set the read option.
writeOption
Enumeration defining write preferences.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
writeOption & writeOpt() noexcept
Access to the write option.
constexpr IOobjectOption(registerOption registerObject, bool globalObject=false) noexcept
Construct (NO_READ, NO_WRITE) with specified register option.
bool globalObject(bool on) noexcept
Change global-object status.
static bool isAnyRead(readOption opt) noexcept
True if any reading may be required (ie, != NO_READ).
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265