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-2023 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  label 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  //- Copy constructor
111  regIOobject(const regIOobject&);
112 
113  //- Move constructor
114  // Registers copy if the object is registered
115  regIOobject(const regIOobject&&);
116 
117  //- Copy constructor, transferring registry registration to copy
118  // if registerCopy is true
119  regIOobject(const regIOobject&, bool registerCopy);
120 
121  //- Copy constructor with new name, transferring registry registration
122  // to copy as specified
123  regIOobject(const word& newName, const regIOobject&, bool registerCopy);
124 
125  //- Copy constructor with new IO parameters
126  regIOobject(const IOobject&, const regIOobject&);
127 
128 
129  //- Destructor
130  virtual ~regIOobject();
131 
132 
133  // Member Functions
134 
135  // Path components
136 
137  //- Return true if object is global, i.e. same for all processors
138  // Defaults to false, must be overridden by global IO classes
139  virtual bool global() const;
140 
141  //- Return true if object is global, i.e. same for all processors
142  // and written to the global case directory,
143  // i.e. not the processor time directory
144  // Defaults to global()
145  virtual bool globalFile() const;
146 
147  using IOobject::caseName;
148 
149  const fileName& caseName() const;
150 
151  using IOobject::path;
152 
153  //- Return complete path
154  fileName path() const;
155 
156  using IOobject::objectPath;
157 
158  //- Return complete path + object name
159  fileName objectPath() const
160  {
161  return path()/name();
162  }
163 
164  using IOobject::filePath;
165 
166  //- Return complete path + object name if the file exists
167  // in the case directory otherwise null.
168  //
169  // For global objects in parallel searches up into the global
170  // case directory
171  fileName filePath() const;
172 
173 
174  // Registration
175 
176  //- Add object to registry
177  bool checkIn();
178 
179  //- Remove object from registry
180  bool checkOut();
181 
182  //- Add file watch on object (if registered and READ_IF_MODIFIED)
183  void addWatch();
184 
185  //- Is this object registered with the registry?
186  inline bool registered() const;
187 
188  //- Is this object owned by the registry?
189  inline bool ownedByRegistry() const;
190 
191  //- Transfer ownership of this object to its registry
192  inline void store();
193 
194  //- Transfer ownership of the given object pointer to its registry
195  // and return reference to object.
196  template<class Type>
197  inline static Type& store(Type*);
198 
199  //- Transfer ownership of the given object pointer to its registry
200  // and return reference to object.
201  template<class Type>
202  inline static Type& store(autoPtr<Type>&);
203 
204  //- Release ownership of this object from its registry
205  inline void release();
206 
207 
208  // Dependency checking
209 
210  //- Event number at last update.
211  inline label eventNo() const;
212 
213  //- Event number at last update.
214  inline label& eventNo();
215 
216  //- Return true if up-to-date with respect to given object
217  // otherwise false
218  bool upToDate(const regIOobject&) const;
219 
220  //- Return true if up-to-date with respect to given objects
221  // otherwise false
222  bool upToDate
223  (
224  const regIOobject&,
225  const regIOobject&
226  ) const;
227 
228  //- Return true if up-to-date with respect to given objects
229  // otherwise false
230  bool upToDate
231  (
232  const regIOobject&,
233  const regIOobject&,
234  const regIOobject&
235  ) const;
236 
237  //- Return true if up-to-date with respect to given objects
238  // otherwise false
239  bool upToDate
240  (
241  const regIOobject&,
242  const regIOobject&,
243  const regIOobject&,
244  const regIOobject&
245  ) const;
246 
247  //- Set up to date (obviously)
248  void setUpToDate();
249 
250 
251  // Edit
252 
253  //- Rename
254  virtual void rename(const word& newName);
255 
256 
257  // Reading
258 
259  //- Read and check header info
260  bool headerOk();
261 
262  //- Return Istream and check object type against that given
263  Istream& readStream(const word&, const bool read = true);
264 
265  //- Close Istream
266  void close();
267 
268  //- Virtual readData function.
269  // Must be defined in derived types for which
270  // re-reading is required
271  virtual bool readData(Istream&);
272 
273  //- Read object
274  virtual bool read();
275 
276  //- Return file-monitoring handles
277  inline const labelList& watchIndices() const;
278 
279  //- Return file-monitoring handles
280  inline labelList& watchIndices();
281 
282  //- Return true if the object's file (or files for objectRegistry)
283  // have been modified. (modified state is cached by Time)
284  virtual bool modified() const;
285 
286  //- Return true if the object's dependencies have been modified
287  virtual bool dependenciesModified() const
288  {
289  return false;
290  }
291 
292  //- Read object if modified (as set by call to modified)
293  virtual bool readIfModified();
294 
295 
296  // Writing
297 
298  //- Pure virtual writaData function.
299  // Must be defined in derived types
300  virtual bool writeData(Ostream&) const = 0;
301 
302  //- Write using given format, version and compression
303  virtual bool writeObject
304  (
308  const bool write
309  ) const;
310 
311  //- Write using setting from DB
312  virtual bool write(const bool write = true) const;
313 
314 
315  // Member Operators
316 
317  //- Assign to IOobject
318  void operator=(const IOobject&);
319 
320  //- Disallow default assignment
321  void operator=(const regIOobject&) = delete;
322 };
323 
324 
325 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
326 
327 } // End namespace Foam
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 #include "regIOobjectI.H"
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #endif
336 
337 // ************************************************************************* //
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:342
fileName filePath(const word &typeName, const bool global) const
Return complete path + object name if the file exists.
Definition: IOobject.C:407
const word & name() const
Return name.
Definition: IOobject.H:310
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:380
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:193
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:158
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
void setUpToDate()
Set up to date (obviously)
Definition: regIOobject.C:411
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:181
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:447
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:329
TypeName("regIOobject")
Runtime type information.
virtual bool dependenciesModified() const
Return true if the object's dependencies have been modified.
Definition: regIOobject.H:286
virtual bool write(const bool write=true) const
Write using setting from DB.
bool headerOk()
Read and check header info.
Definition: regIOobject.C:453
label eventNo() const
Event number at last update.
Definition: regIOobjectI.H:89
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:187
fileName path() const
Return complete path.
Definition: regIOobject.C:199
virtual bool readData(Istream &)
Virtual readData function.
void operator=(const IOobject &)
Assign to IOobject.
Definition: regIOobject.C:474
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:241
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:150
void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:259
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
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:205
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59