regIOobject.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::regIOobject
26 
27 Description
28  regIOobject is an abstract class derived from IOobject to handle
29  automatic object registration with the objectRegistry.
30 
31 SourceFiles
32  regIOobject.C
33  regIOobjectRead.C
34  regIOobjectWrite.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef regIOobject_H
39 #define regIOobject_H
40 
41 #include "IOobject.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class regIOobject Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class regIOobject
54 :
55  public IOobject
56 {
57  // Private Data
58 
59  //- Is this object registered with the registry
60  bool registered_;
61 
62  //- Is this object owned by the registry
63  bool ownedByRegistry_;
64 
65  //- List of modification watch indices
66  mutable labelList watchIndices_;
67 
68  //- eventNo of last update
69  uint64_t eventNo_;
70 
71  //- Istream for reading
72  autoPtr<ISstream> isPtr_;
73 
74 
75  // Private Member Functions
76 
77  //- Return Istream
78  Istream& readStream(const bool read = true);
79 
80 
81 protected:
82 
83  // Protected Member Functions
84 
85  //- Read header, check readOpt flags and read data if necessary.
86  // Format is set to ASCII if defaultFormat and file format are ASCII
87  bool readHeaderOk
88  (
89  const IOstream::streamFormat defaultFormat,
90  const word& typeName
91  );
92 
93 
94 public:
95 
96  // Static data
97 
98  //- Runtime type information
99  TypeName("regIOobject");
100 
101  static float fileModificationSkew;
102 
103 
104  // Constructors
105 
106  //- Construct from IOobject. Optional flag for if IOobject is the
107  // top level regIOobject.
108  regIOobject(const IOobject&, const bool isTime = false);
109 
110  //- Construct from IOobject with new name, and overriding the
111  // IOobject's register object setting
112  regIOobject(const word& newName, const IOobject&, bool registerObject);
113 
114  //- Copy constructor
115  regIOobject(const regIOobject&);
116 
117  //- Move constructor
118  // Registers copy if the object is registered
120 
121  //- Copy constructor, transferring registry registration to copy
122  // if registerCopy is true
123  regIOobject(const regIOobject&, bool registerCopy);
124 
125 
126  //- Destructor
127  virtual ~regIOobject();
128 
129 
130  // Member Functions
131 
132  // Path components
133 
134  //- Return true if object is global, i.e. same for all processors
135  // Defaults to false, must be overridden by global IO classes
136  virtual bool global() const;
137 
138  //- Return true if object is global, i.e. same for all processors
139  // and written to the global case directory,
140  // i.e. not the processor time directory
141  // Defaults to global()
142  virtual bool globalFile() const;
143 
144  using IOobject::caseName;
145 
146  const fileName& caseName() const;
147 
148  using IOobject::path;
149 
150  //- Return complete path
151  fileName path() const;
152 
153  using IOobject::objectPath;
154 
155  //- Return complete path + object name
156  fileName objectPath() const
157  {
158  return path()/name();
159  }
160 
161  using IOobject::filePath;
162 
163  //- Return complete path + object name if the file exists
164  // in the case directory otherwise null.
165  //
166  // For global objects in parallel searches up into the global
167  // case directory
168  fileName filePath() const;
169 
170 
171  // Registration
172 
173  //- Add object to registry
174  bool checkIn();
175 
176  //- Remove object from registry
177  bool checkOut();
178 
179  //- Add file watch on object (if registered and READ_IF_MODIFIED)
180  void addWatch();
181 
182  //- Is this object registered with the registry?
183  inline bool registered() const;
184 
185  //- Is this object owned by the registry?
186  inline bool ownedByRegistry() const;
187 
188  //- Transfer ownership of this object to its registry
189  inline void store();
190 
191  //- Transfer ownership of the given object pointer to its registry
192  // and return reference to object.
193  template<class Type>
194  inline static Type& store(Type*);
195 
196  //- Transfer ownership of the given object pointer to its registry
197  // and return reference to object.
198  template<class Type>
199  inline static Type& store(autoPtr<Type>&);
200 
201  //- Release ownership of this object from its registry
202  inline void release();
203 
204 
205  // Dependency checking
206 
207  //- Event number at last update.
208  inline uint64_t eventNo() const;
209 
210  //- Event number at last update.
211  inline uint64_t& eventNo();
212 
213  //- Return true if up-to-date with respect to given object
214  // otherwise false
215  bool upToDate(const regIOobject&) const;
216 
217  //- Return true if up-to-date with respect to given objects
218  // otherwise false
219  bool upToDate
220  (
221  const regIOobject&,
222  const regIOobject&
223  ) const;
224 
225  //- Return true if up-to-date with respect to given objects
226  // otherwise false
227  bool upToDate
228  (
229  const regIOobject&,
230  const regIOobject&,
231  const regIOobject&
232  ) const;
233 
234  //- Return true if up-to-date with respect to given objects
235  // otherwise false
236  bool upToDate
237  (
238  const regIOobject&,
239  const regIOobject&,
240  const regIOobject&,
241  const regIOobject&
242  ) const;
243 
244  //- Set up to date (obviously)
245  void setUpToDate();
246 
247 
248  // Edit
249 
250  //- Rename
251  virtual void rename(const word& newName);
252 
253 
254  // Reading
255 
256  //- Read and check header info
257  bool headerOk();
258 
259  //- Return Istream and check object type against that given
260  Istream& readStream(const word&, const bool read = true);
261 
262  //- Close Istream
263  void close();
264 
265  //- Virtual readData function.
266  // Must be defined in derived types for which
267  // re-reading is required
268  virtual bool readData(Istream&);
269 
270  //- Read object
271  virtual bool read();
272 
273  //- Return file-monitoring handles
274  inline const labelList& watchIndices() const;
275 
276  //- Return file-monitoring handles
277  inline labelList& watchIndices();
278 
279  //- Return true if the object's file (or files for objectRegistry)
280  // have been modified. (modified state is cached by Time)
281  virtual bool modified() const;
282 
283  //- Return true if the object's dependencies have been modified
284  virtual bool dependenciesModified() const
285  {
286  return false;
287  }
288 
289  //- Read object if modified (as set by call to modified)
290  virtual bool readIfModified();
291 
292 
293  // Writing
294 
295  //- Pure virtual writaData function.
296  // Must be defined in derived types
297  virtual bool writeData(Ostream&) const = 0;
298 
299  //- Write using given format, version and compression
300  virtual bool writeObject
301  (
305  const bool write
306  ) const;
307 
308  //- Write using setting from DB
309  virtual bool write(const bool write = true) const;
310 
311 
312  // Member Operators
313 
314  //- Assign to IOobject
315  void operator=(const IOobject&) = delete;
316 
317  //- Disallow default assignment
318  void operator=(const regIOobject&) = delete;
319 };
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 } // End namespace Foam
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 #include "regIOobjectI.H"
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #endif
333 
334 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const fileName & caseName(const bool global) const
Definition: IOobject.C:339
bool & registerObject()
Register object created from this IOobject with registry if true.
Definition: IOobject.H:343
fileName filePath(const bool global) const
Return complete path + object name if the file exists.
Definition: IOobject.C:409
const word & name() const
Return name.
Definition: IOobject.H:307
fileName objectPath(const bool global) const
Return complete path + object name including the processor.
Definition: IOobject.H:411
fileName path(const bool global) const
Return complete path including the processor sub-directory.
Definition: IOobject.C:383
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
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:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A class for handling file names.
Definition: fileName.H:82
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
const fileName & caseName() const
Definition: regIOobject.C:169
bool registered() const
Is this object registered with the registry?
Definition: regIOobjectI.H:28
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:34
void release()
Release ownership of this object from its registry.
Definition: regIOobjectI.H:83
const labelList & watchIndices() const
Return file-monitoring handles.
Definition: regIOobjectI.H:100
fileName objectPath() const
Return complete path + object name.
Definition: regIOobject.H:155
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
void setUpToDate()
Set up to date (obviously)
Definition: regIOobject.C:387
virtual bool modified() const
Return true if the object's file (or files for objectRegistry)
virtual bool global() const
Return true if object is global, i.e. same for all processors.
Definition: regIOobject.C:157
void close()
Close Istream.
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
fileName filePath() const
Return complete path + object name if the file exists.
Definition: regIOobject.C:423
regIOobject(const IOobject &, const bool isTime=false)
Construct from IOobject. Optional flag for if IOobject is the.
Definition: regIOobject.C:41
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
Definition: regIOobject.C:305
TypeName("regIOobject")
Runtime type information.
virtual bool dependenciesModified() const
Return true if the object's dependencies have been modified.
Definition: regIOobject.H:283
virtual bool write(const bool write=true) const
Write using setting from DB.
bool headerOk()
Read and check header info.
Definition: regIOobject.C:429
void operator=(const IOobject &)=delete
Assign to IOobject.
virtual bool readIfModified()
Read object if modified (as set by call to modified)
static float fileModificationSkew
Definition: regIOobject.H:100
virtual bool globalFile() const
Return true if object is global, i.e. same for all processors.
Definition: regIOobject.C:163
fileName path() const
Return complete path.
Definition: regIOobject.C:175
virtual bool readData(Istream &)
Virtual readData function.
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:217
bool readHeaderOk(const IOstream::streamFormat defaultFormat, const word &typeName)
Read header, check readOpt flags and read data if necessary.
virtual ~regIOobject()
Destructor.
Definition: regIOobject.C:126
void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:235
uint64_t eventNo() const
Event number at last update.
Definition: regIOobjectI.H:89
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:393
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:40
virtual bool read()
Read object.
bool checkIn()
Add object to registry.
Definition: regIOobject.C:181
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
Namespace for OpenFOAM.