regIOobject.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-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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::regIOobject
29
30Description
31 regIOobject is an abstract class derived from IOobject to handle
32 automatic object registration with the objectRegistry.
33
34SourceFiles
35 regIOobject.C
36 regIOobjectRead.C
37 regIOobjectWrite.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_regIOobject_H
42#define Foam_regIOobject_H
43
44#include "IOobject.H"
45#include "refPtr.H"
46#include "tmp.H"
47#include "typeInfo.H"
48#include "stdFoam.H"
49#include "OSspecific.H"
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52
53
54namespace Foam
55{
56
57// Forward Declarations
58
59class dictionary;
60
61namespace functionEntries
62{
63 class codeStream;
65namespace fileOperations
66{
67 class uncollatedFileOperation;
68}
69
70/*---------------------------------------------------------------------------*\
71 Class regIOobject Declaration
72\*---------------------------------------------------------------------------*/
74class regIOobject
75:
76 public IOobject
77{
78protected:
79
80 //- Helper: check readOpt flags and read if necessary
81 bool readHeaderOk
82 (
84 const word& typeName
85 );
86
87 //- To flag master-only reading of objects
88 static bool masterOnlyReading;
89
90
91private:
92
93 // Private Data
94
95 //- Is this object registered with the registry
96 bool registered_;
97
98 //- Is this object owned by the registry
99 bool ownedByRegistry_;
100
101 //- List of modification watch indices
102 mutable labelList watchIndices_;
103
104 //- eventNo of last update
105 label eventNo_;
106
107 //- Dictionary for any meta-data
108 autoPtr<dictionary> metaDataPtr_;
109
110 //- Istream for reading
111 autoPtr<ISstream> isPtr_;
112
113
114 // Private Member Functions
115
116 //- Construct object stream, read header if not already constructed
117 void readStream(const bool valid);
118
119 //- No copy assignment
120 void operator=(const regIOobject&) = delete;
121
122
123public:
124
125 //- Friendship with classes needing access to masterOnlyReading
128
129
130 // Static Data
131
132 //- Runtime type information
133 TypeName("regIOobject");
134
135
136 // Constructors
137
138 //- Construct from IOobject. The optional flag adds special handling
139 //- if the object is the top-level regIOobject (eg, Time).
140 regIOobject(const IOobject& io, const bool isTimeObject = false);
141
142 //- Copy construct
143 regIOobject(const regIOobject& rio);
144
145 //- Copy construct, transferring registry registration to the copy
146 //- if registerCopy is true
147 regIOobject(const regIOobject& rio, bool registerCopy);
148
149 //- Copy construct with new name, transferring registry registration
150 //- to the copy f registerCopy is true
151 regIOobject(const word& newName, const regIOobject&, bool registerCopy);
152
153 //- Copy construct with new IO parameters
154 regIOobject(const IOobject& io, const regIOobject& rio);
155
156
157 //- Destructor
158 virtual ~regIOobject();
159
160
161 // Member Functions
162
163 // Registration
164
165 //- Add object to registry, if not already registered
166 // \return true if object was already registered,
167 // or was newly registered
168 bool checkIn();
169
170 //- Remove all file watches and remove object from registry
171 // \return true if object was registered and was removed
172 bool checkOut();
173
174 //- Add file watch on object (if registered and READ_IF_MODIFIED)
175 virtual void addWatch();
176
177 //- Query the registered state (ie, has been checked in).
178 //- This is not necessarily the same as registerObject(),
179 //- which is just a stated preference.
180 inline bool registered() const noexcept;
181
182 //- Is this object owned by the registry?
183 inline bool ownedByRegistry() const noexcept;
184
185 //- Register object with its registry
186 //- and transfer ownership to the registry.
187 // \return true if now ownedByRegistry
188 inline bool store();
189
190 //- Transfer pointer ownership to its registry.
191 // \return reference to the stored object
192 template<class Type>
193 inline static Type& store(Type* p);
194
195 //- Transfer pointer ownership to its registry.
196 // Resets (clears) the parameter.
197 // \return reference to the stored object
198 template<class Type>
199 inline static Type& store(autoPtr<Type>& ptr);
200
201 //- Transfer pointer ownership to its registry.
202 // Resets (clears) the parameter.
203 // \return reference to the stored object
204 template<class Type>
205 inline static Type& store(autoPtr<Type>&& ptr);
206
207 //- Transfer pointer ownership to its registry.
208 // Changes parameter from PTR to CREF (do not rely on this).
209 // \return reference to the stored object
210 template<class Type>
211 inline static Type& store(refPtr<Type>& ptr);
212
213 //- Transfer pointer ownership to its registry.
214 // Changes parameter from PTR to CREF (do not rely on this).
215 // \return reference to the stored object
216 template<class Type>
217 inline static Type& store(refPtr<Type>&& ptr);
218
219 //- Transfer pointer ownership to its registry.
220 // Changes parameter from PTR to CREF (do not rely on this).
221 // \return reference to the stored object
222 template<class Type>
223 inline static Type& store(tmp<Type>& ptr);
224
225 //- Transfer pointer ownership to its registry.
226 // Changes parameter from PTR to CREF (do not rely on this).
227 // \return reference to the stored object
228 template<class Type>
229 inline static Type& store(tmp<Type>&& ptr);
230
231 //- Set object as \b not ownedByRegistry
232 // \param unregister optionally set as non-registered too
233 inline void release(const bool unregister = false) noexcept;
234
235
236 // Dependency Checking
237
238 //- Event number at last update.
239 inline label eventNo() const noexcept;
240
241 //- Event number at last update.
242 inline label& eventNo() noexcept;
243
244 //- Return true if up-to-date with respect to given object
245 bool upToDate(const regIOobject&) const;
246
247 //- Return true if up-to-date with respect to given objects
248 bool upToDate
249 (
250 const regIOobject&,
251 const regIOobject&
252 ) const;
253
254 //- Return true if up-to-date with respect to given objects
255 bool upToDate
256 (
257 const regIOobject&,
258 const regIOobject&,
259 const regIOobject&
260 ) const;
261
262 //- Return true if up-to-date with respect to given objects
263 bool upToDate
264 (
265 const regIOobject&,
266 const regIOobject&,
267 const regIOobject&,
268 const regIOobject&
269 ) const;
270
271
272 //- Set as up-to-date
273 void setUpToDate();
274
275
276 // Edit
277
278 //- Rename
279 virtual void rename(const word& newName);
280
281
282 // Meta-data
283
284 //- Return pointer to meta-data or nullptr
285 const dictionary* findMetaData() const noexcept;
286
287 //- Get or create meta-data
289
290 //- Remove meta-data
291 void removeMetaData();
292
293 //- Update internal meta-data (eg, prior to writing)
294 virtual void updateMetaData();
295
296
297 // Reading
298
299 //- Return complete path + object name if the file exists
300 // in the case directory otherwise null. Does not search
301 // up if parallel. Can be overridden to provide this functionality
302 // (e.g. IOdictionary)
303 virtual fileName filePath() const;
304
305 //- Read and check header info. Does not check the headerClassName.
306 bool headerOk();
307
308 //- Return Istream and check object type against that given
309 Istream& readStream(const word&, const bool valid = true);
310
311 //- Close Istream
312 void close();
313
314 //- Virtual readData function.
315 // Must be defined in derived types for which
316 // re-reading is required
317 virtual bool readData(Istream&);
318
319 //- Read object
320 virtual bool read();
321
322 //- Add file watch for fileName on object if not yet watched.
323 // \return index of watch
324 virtual label addWatch(const fileName&);
325
326 //- Read access to file-monitoring handles
327 inline const labelList& watchIndices() const noexcept;
328
329 //- Write access to file-monitoring handles
331
332 //- Return true if the object's file (or files for objectRegistry)
333 //- have been modified. (modified state is cached by Time)
334 virtual bool modified() const;
335
336 //- Read object if modified (as set by call to modified)
337 virtual bool readIfModified();
338
339
340 // Writing
341
342 //- Pure virtual writeData function.
343 // Must be defined in derived types
344 virtual bool writeData(Ostream&) const = 0;
345
346 //- Write using stream options
347 virtual bool writeObject
348 (
349 IOstreamOption streamOpt,
350 const bool valid
351 ) const;
352
353 //- Write using setting from DB
354 virtual bool write(const bool valid = true) const;
355
356
357 // Other
358
359 //- Is object global
360 virtual bool global() const
361 {
362 return false;
363 }
364
365
366 // Member Operators
367
368 //- Copy assignment
369 void operator=(const IOobject& io);
370
371
372 // Housekeeping
373
374 //- Write using given format, version and compression
375 FOAM_DEPRECATED_FOR(2020-02, "writeObject(IOstreamOption, bool)")
376 virtual bool writeObject
377 (
378 IOstreamOption::streamFormat fmt,
379 IOstreamOption::versionNumber ver,
380 IOstreamOption::compressionType comp,
381 const bool valid
382 ) const;
383};
384
385
386// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387
388} // End namespace Foam
389
390// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391
392#include "regIOobjectI.H"
393
394// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395
396#endif
397
398// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
The IOstreamOption is a simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
fileOperation that assumes file operations are local.
Dictionary entry that contains C++ OpenFOAM code that is compiled to generate the entry itself....
Definition: codeStream.H:119
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
const dictionary * findMetaData() const noexcept
Return pointer to meta-data or nullptr.
bool registered() const noexcept
Definition: regIOobjectI.H:31
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
void setUpToDate()
Set as up-to-date.
Definition: regIOobject.C:411
virtual bool modified() const
virtual bool global() const
Is object global.
Definition: regIOobject.H:359
void close()
Close Istream.
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: regIOobject.C:432
virtual void updateMetaData()
Update internal meta-data (eg, prior to writing)
const labelList & watchIndices() const noexcept
Read access to file-monitoring handles.
Definition: regIOobjectI.H:202
bool ownedByRegistry() const noexcept
Is this object owned by the registry?
Definition: regIOobjectI.H:37
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
Definition: regIOobject.C:339
static bool masterOnlyReading
To flag master-only reading of objects.
Definition: regIOobject.H:87
TypeName("regIOobject")
Runtime type information.
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
virtual bool readIfModified()
Read object if modified (as set by call to modified)
void removeMetaData()
Remove meta-data.
label eventNo() const noexcept
Event number at last update.
Definition: regIOobjectI.H:191
virtual bool readData(Istream &)
Virtual readData function.
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:224
virtual ~regIOobject()
Destructor.
Definition: regIOobject.C:149
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:267
dictionary & getMetaData() noexcept
Get or create meta-data.
bool readHeaderOk(const IOstreamOption::streamFormat fmt, const word &typeName)
Helper: check readOpt flags and read if necessary.
void release(const bool unregister=false) noexcept
Set object as not ownedByRegistry.
Definition: regIOobjectI.H:181
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
virtual bool read()
Read object.
bool checkIn()
Add object to registry, if not already registered.
Definition: regIOobject.C:188
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223
runTime write()
Includes some standard C++ headers, defines global macros and templates used in multiple places by Op...
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73