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-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
30 template<class StringType>
32 (
33  StringType base,
34  const word& group
35 )
36 {
37  if (group.empty())
38  {
39  return base;
40  }
41 
42  return base + ('.' + group);
43 }
44 
45 
47 (
48  const std::string& scope,
49  const word& name
50 )
51 {
52  if (scope.empty())
53  {
54  return name;
55  }
56 
57  word output;
58  output.reserve(scope.size() + name.size() + 1);
59 
60  output += scope;
62  output += name;
63  return output;
64 }
65 
66 
68 (
69  const std::string& scope,
70  const word& name1,
71  const word& name2
72 )
73 {
74  if (scope.empty())
75  {
76  return IOobject::scopedName(name1, name2);
77  }
78 
79  word output;
80  output.reserve(scope.size() + name1.size() + name2.size() + 2);
81 
82  output += scope;
84  output += name1;
85  if (!name2.empty())
86  {
88  output += name2;
89  }
90  return output;
91 }
92 
93 
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 
96 inline Foam::IOobject::IOobject
97 (
98  const word& name,
99  const fileName& instance,
100  const objectRegistry& registry,
103  bool registerObject,
104  bool globalObject
105 )
106 :
107  IOobject
108  (
109  name,
110  instance,
111  registry,
112  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
113  )
114 {}
115 
116 
117 inline Foam::IOobject::IOobject
118 (
119  const word& name,
120  const fileName& instance,
121  const fileName& local,
122  const objectRegistry& registry,
125  bool registerObject,
126  bool globalObject
127 )
128 :
129  IOobject
130  (
131  name,
132  instance,
133  local,
134  registry,
135  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
136  )
137 {}
138 
139 
140 inline Foam::IOobject::IOobject
141 (
142  const fileName& path,
143  const objectRegistry& registry,
146  bool registerObject,
147  bool globalObject
148 )
149 :
150  IOobject
151  (
152  path,
153  registry,
154  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
155  )
156 {}
157 
158 
159 inline Foam::IOobject::IOobject
160 (
161  const IOobject& io,
162  const word& name,
163  const fileName& local
164 )
165 :
167 {
168  local_ = local;
169 }
170 
171 
172 inline Foam::IOobject::IOobject
173 (
174  const IOobject& io,
177 )
178 :
179  IOobject(io)
180 {
183 }
184 
185 
186 inline Foam::IOobject::IOobject
187 (
188  const IOobject& io,
190 )
191 :
192  IOobject(io)
193 {
195 }
196 
197 
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 
200 // General access
202 inline const Foam::word& Foam::IOobject::name() const noexcept
203 {
204  return name_;
205 }
206 
208 inline Foam::word Foam::IOobject::group() const
209 {
210  return name_.ext();
211 }
212 
214 inline Foam::word Foam::IOobject::member() const
215 {
216  return name_.lessExt();
217 }
218 
221 {
222  return headerClassName_;
223 }
224 
227 {
228  return headerClassName_;
229 }
230 
232 inline const Foam::string& Foam::IOobject::note() const noexcept
233 {
234  return note_;
235 }
236 
239 {
240  return note_;
241 }
242 
244 inline unsigned Foam::IOobject::labelByteSize() const noexcept
245 {
246  return static_cast<unsigned>(sizeofLabel_);
247 }
248 
249 
250 inline unsigned Foam::IOobject::scalarByteSize() const noexcept
251 {
252  return static_cast<unsigned>(sizeofScalar_);
253 }
254 
255 
256 // Checks
257 
259 {
260  return !headerClassName_.empty();
261 }
262 
263 
264 template<class Type>
265 inline bool Foam::IOobject::isHeaderClass() const
266 {
267  return (Type::typeName == headerClassName_);
268 }
269 
270 
271 // Path components
274 {
275  return instance_;
276 }
277 
280 {
281  return instance_;
282 }
283 
285 inline const Foam::fileName& Foam::IOobject::local() const noexcept
286 {
287  return local_;
288 }
289 
292 {
293  return path()/name();
294 }
295 
296 
298 {
299  return globalPath()/name();
300 }
301 
302 
303 // Error Handling
305 inline bool Foam::IOobject::good() const noexcept
306 {
307  return objState_ == objectState::GOOD;
308 }
309 
310 
311 inline bool Foam::IOobject::bad() const noexcept
312 {
313  return objState_ == objectState::BAD;
314 }
315 
316 
317 // ************************************************************************* //
writeOption
Enumeration defining write preferences.
A class for handling file names.
Definition: fileName.H:72
readOption readOpt() const noexcept
Get the read option.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:225
word member() const
Return member (name without the extension)
Definition: IOobjectI.H:207
bool bad() const noexcept
Did last readHeader() fail?
Definition: IOobjectI.H:304
word group() const
Return group (extension part of name)
Definition: IOobjectI.H:201
bool good() const noexcept
Did last readHeader() succeed?
Definition: IOobjectI.H:298
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:284
bool hasHeaderClass() const noexcept
True if headerClassName() is non-empty (after reading)
Definition: IOobjectI.H:251
constexpr const char *const group
Group name for atomic constants.
word ext() const
Return file name extension (part after last .)
Definition: wordI.H:171
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
writeOption writeOpt() const noexcept
Get the write option.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
word lessExt() const
Return word without extension (part before last .)
Definition: wordI.H:192
bool local
Definition: EEqn.H:20
const direction noexcept
Definition: Scalar.H:258
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
fileName globalObjectPath() const
The complete global path + object name.
Definition: IOobjectI.H:290
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:266
static char scopeSeparator
Character for scoping object names (&#39;:&#39; or &#39;_&#39;)
Definition: IOobject.H:338
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes, possibly read from the header.
Definition: IOobjectI.H:237
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:213
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
bool registerObject() const noexcept
Should objects created with this IOobject be registered?
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
const fileName & local() const noexcept
Read access to local path component.
Definition: IOobjectI.H:278
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
A class for handling character strings derived from std::string.
Definition: string.H:72
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName.
Definition: IOobjectI.H:258
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes, possibly read from the header.
Definition: IOobjectI.H:243
readOption
Enumeration defining read preferences.