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