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