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-2022 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  return scope + (IOobject::scopeSeparator + name);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
64 (
65  const word& name,
66  const fileName& instance,
67  const objectRegistry& registry,
70  bool registerObject,
71  bool globalObject
72 )
73 :
74  IOobject
75  (
76  name,
77  instance,
78  registry,
79  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
80  )
81 {}
82 
83 
85 (
86  const word& name,
87  const fileName& instance,
88  const fileName& local,
89  const objectRegistry& registry,
92  bool registerObject,
93  bool globalObject
94 )
95 :
96  IOobject
97  (
98  name,
99  instance,
100  local,
101  registry,
102  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
103  )
104 {}
105 
106 
108 (
109  const fileName& path,
110  const objectRegistry& registry,
113  bool registerObject,
114  bool globalObject
115 )
116 :
117  IOobject
118  (
119  path,
120  registry,
121  IOobjectOption(rOpt, wOpt, registerObject, globalObject)
122  )
123 {}
124 
125 
127 (
128  const IOobject& io,
129  const word& name,
130  const fileName& local
131 )
132 :
134 {
135  local_ = local;
136 }
137 
138 
140 (
141  const IOobject& io,
144 )
145 :
146  IOobject(io)
147 {
148  readOpt(rOpt);
149  writeOpt(wOpt);
150 }
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
155 // General access
157 inline const Foam::word& Foam::IOobject::name() const noexcept
158 {
159  return name_;
160 }
161 
163 inline Foam::word Foam::IOobject::group() const
164 {
165  return name_.ext();
166 }
167 
169 inline Foam::word Foam::IOobject::member() const
170 {
171  return name_.lessExt();
172 }
173 
176 {
177  return headerClassName_;
178 }
179 
182 {
183  return headerClassName_;
184 }
185 
187 inline const Foam::string& Foam::IOobject::note() const noexcept
188 {
189  return note_;
190 }
191 
194 {
195  return note_;
196 }
197 
199 inline unsigned Foam::IOobject::labelByteSize() const noexcept
200 {
201  return static_cast<unsigned>(sizeofLabel_);
202 }
203 
204 
205 inline unsigned Foam::IOobject::scalarByteSize() const noexcept
206 {
207  return static_cast<unsigned>(sizeofScalar_);
208 }
209 
210 
211 // Checks
212 
214 {
215  return !headerClassName_.empty();
216 }
217 
218 
219 template<class Type>
220 inline bool Foam::IOobject::isHeaderClass() const
221 {
222  return (Type::typeName == headerClassName_);
223 }
224 
225 
226 // Path components
229 {
230  return instance_;
231 }
232 
235 {
236  return instance_;
237 }
238 
240 inline const Foam::fileName& Foam::IOobject::local() const noexcept
241 {
242  return local_;
243 }
244 
245 
247 {
248  return path()/name();
249 }
250 
251 
252 // Error Handling
254 inline bool Foam::IOobject::good() const noexcept
255 {
256  return objState_ == objectState::GOOD;
257 }
258 
259 
260 inline bool Foam::IOobject::bad() const noexcept
261 {
262  return objState_ == objectState::BAD;
263 }
264 
265 
266 // ************************************************************************* //
writeOption
Enumeration defining write preferences.
A class for handling file names.
Definition: fileName.H:71
readOption readOpt() const noexcept
Get the read option.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:180
word member() const
Return member (name without the extension)
Definition: IOobjectI.H:162
bool bad() const noexcept
Did last readHeader() fail?
Definition: IOobjectI.H:253
word group() const
Return group (extension part of name)
Definition: IOobjectI.H:156
bool good() const noexcept
Did last readHeader() succeed?
Definition: IOobjectI.H:247
fileName objectPath() const
The complete path + object name.
Definition: IOobjectI.H:239
bool hasHeaderClass() const noexcept
True if headerClassName() is non-empty (after reading)
Definition: IOobjectI.H:206
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
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())
const fileName & instance() const noexcept
Read access to instance path component.
Definition: IOobjectI.H:221
static char scopeSeparator
Character for scoping object names (&#39;:&#39; or &#39;_&#39;)
Definition: IOobject.H:308
unsigned labelByteSize() const noexcept
The sizeof (label) in bytes, possibly read from the header.
Definition: IOobjectI.H:192
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:168
IOobject(const IOobject &)=default
Copy construct.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Registry of regIOobjects.
const fileName & local() const noexcept
Read access to local path component.
Definition: IOobjectI.H:233
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
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:213
unsigned scalarByteSize() const noexcept
The sizeof (scalar) in bytes, possibly read from the header.
Definition: IOobjectI.H:198
readOption
Enumeration defining read preferences.