Loading...
Searching...
No Matches
IOobjectI.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) 2017-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
26\*---------------------------------------------------------------------------*/
27
28// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
29
31{
32 return
33 (
36 );
37}
38
39
40template<class StringType>
42(
43 StringType base,
44 const word& group
45)
46{
47 if (group.empty())
48 {
49 return base;
50 }
51
52 return base + ('.' + group);
53}
54
55
57(
58 const std::string& scope,
59 const word& name
60)
61{
62 if (scope.empty())
63 {
64 return name;
65 }
66
67 word output;
68 output.reserve(scope.size() + name.size() + 1);
69
70 output += scope;
72 output += name;
73 return output;
74}
75
76
78(
79 const std::string& scope,
80 const word& name1,
81 const word& name2
82)
83{
84 if (scope.empty())
85 {
86 return IOobject::scopedName(name1, name2);
87 }
88
89 word output;
90 output.reserve(scope.size() + name1.size() + name2.size() + 2);
91
92 output += scope;
94 output += name1;
95 if (!name2.empty())
96 {
98 output += name2;
99 }
100 return output;
101}
102
103
104// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
105
106inline Foam::IOobject::IOobject
107(
108 const word& name,
109 const fileName& instance,
110 const objectRegistry& registry,
113 bool registerObject,
114 bool globalObject
115)
116:
117 IOobject
118 (
119 name,
121 registry,
123 )
124{}
125
126
127inline Foam::IOobject::IOobject
128(
129 const word& name,
130 const fileName& instance,
131 const fileName& local,
132 const objectRegistry& registry,
135 bool registerObject,
136 bool globalObject
137)
138:
140 (
141 name,
142 instance,
144 registry,
146 )
147{}
148
149
150inline Foam::IOobject::IOobject
151(
152 const fileName& path,
153 const objectRegistry& registry,
156 bool registerObject,
157 bool globalObject
158)
159:
161 (
163 registry,
165 )
166{}
167
168
169inline Foam::IOobject::IOobject
170(
171 const IOobject& io,
172 const word& name,
173 const fileName& local
174)
176 IOobject(io, name)
177{
178 local_ = local;
179}
180
181
182inline Foam::IOobject::IOobject
183(
184 const IOobject& io,
187)
188:
189 IOobject(io)
190{
193}
194
195
196inline Foam::IOobject::IOobject
197(
198 const IOobject& io,
200)
201:
202 IOobject(io)
203{
206
207
208// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
209
210// General access
212inline const Foam::word& Foam::IOobject::name() const noexcept
213{
214 return name_;
215}
216
219{
220 return name_.ext();
221}
222
225{
226 return name_.lessExt();
227}
228
231{
232 return headerClassName_;
233}
234
237{
238 return headerClassName_;
239}
240
242inline const Foam::string& Foam::IOobject::note() const noexcept
243{
244 return note_;
245}
246
249{
250 return note_;
251}
252
254inline unsigned Foam::IOobject::labelByteSize() const noexcept
255{
256 return static_cast<unsigned>(sizeofLabel_);
257}
258
259
260inline unsigned Foam::IOobject::scalarByteSize() const noexcept
262 return static_cast<unsigned>(sizeofScalar_);
263}
264
265
266// Checks
269{
270 return !headerClassName_.empty();
271}
272
273
274inline bool Foam::IOobject::isHeaderClass(const word& expectedType) const
275{
276 return (expectedType.empty() || (expectedType == headerClassName_));
277}
278
279
280template<class Type>
281inline bool Foam::IOobject::isHeaderClass() const
282{
283 if constexpr (std::is_void_v<Type>)
284 {
285 return true;
286 }
287 else
288 {
289 return (Type::typeName == headerClassName_);
290 }
291}
292
293
294// Path components
297{
298 return instance_;
299}
300
303{
304 return instance_;
305}
306
309{
310 return local_;
311}
312
315{
316 return local_;
317}
318
321{
322 return path()/name();
323}
324
327{
328 return globalPath()/name();
329}
330
331
333(
335) const
336{
337 return path(layout)/name();
338}
339
340
342(
344) const
345{
347}
348
349
351(
352 const word& instance
353) const
358
359// Error Handling
361inline bool Foam::IOobject::good() const noexcept
362{
363 return objState_ == objectState::GOOD;
364}
365
366
367inline bool Foam::IOobject::bad() const noexcept
368{
369 return objState_ == objectState::BAD;
370}
371
372
373// ************************************************************************* //
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
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 globalObject() const noexcept
True if object is treated the same for all processors.
readOption readOpt() const noexcept
Get the read option.
writeOption writeOpt() const noexcept
Get the write 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.
readOption
Enumeration defining read preferences.
writeOption
Enumeration defining write preferences.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName Always true for a void type.
Definition IOobjectI.H:274
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition IOobjectI.H:223
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes, possibly read from the header.
Definition IOobjectI.H:253
fileName globalObjectPath() const
The complete global path + object name.
Definition IOobjectI.H:319
bool good() const noexcept
Did last readHeader() succeed?
Definition IOobjectI.H:354
bool bad() const noexcept
Did last readHeader() fail?
Definition IOobjectI.H:360
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition IOobjectI.H:50
static char scopeSeparator
Character for scoping object names (':' or '_').
Definition IOobject.H:353
static word group(const word &name)
Return group (extension part of name).
Definition IOobject.C:300
bool hasHeaderClass() const noexcept
True if headerClassName() is non-empty (after reading).
Definition IOobjectI.H:261
static bool fileModificationChecking_masterOnly() noexcept
Test fileModificationChecking for master-only.
Definition IOobjectI.H:23
const fileName & local() const noexcept
Read access to local path component.
Definition IOobjectI.H:301
word group() const
Return group (extension part of name).
Definition IOobjectI.H:211
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition IOobject.H:358
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes, possibly read from the header.
Definition IOobjectI.H:247
fileName path() const
The complete path for the object (with instance, local,...).
Definition IOobject.C:500
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
word member() const
Return member (name without the extension).
Definition IOobjectI.H:217
const string & note() const noexcept
Return the optional note.
Definition IOobjectI.H:235
fileName objectPath() const
The complete path + object name.
Definition IOobjectI.H:313
fileName globalPath() const
The complete global path for the object (with instance, local,...).
Definition IOobject.C:512
A class for handling file names.
Definition fileName.H:75
Registry of regIOobjects.
A class for handling character strings derived from std::string.
Definition string.H:76
A class for handling words, derived from Foam::string.
Definition word.H:66
word ext() const
Return file name extension (part after last .).
Definition wordI.H:171
word lessExt() const
Return word without extension (part before last .).
Definition wordI.H:192
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
bool local
Definition EEqn.H:20
const auto & io
auto & name
const direction noexcept
Definition scalarImpl.H:265
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127