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-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::regIOobject
29 
30 Description
31  regIOobject is an abstract class derived from IOobject to handle
32  automatic object registration with the objectRegistry.
33 
34 SourceFiles
35  regIOobject.C
36  regIOobjectRead.C
37  regIOobjectWrite.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef regIOobject_H
42 #define regIOobject_H
43 
44 #include "IOobject.H"
45 #include "typeInfo.H"
46 #include "OSspecific.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 
51 namespace Foam
52 {
53 
54 namespace functionEntries
55 {
56  class codeStream;
57 }
58 namespace fileOperations
59 {
60  class uncollatedFileOperation;
61  class masterUncollatedFileOperation;
62 }
63 
64 /*---------------------------------------------------------------------------*\
65  Class regIOobject Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class regIOobject
69 :
70  public IOobject
71 {
72 protected:
73 
74  //- Helper: check readOpt flags and read if necessary
75  bool readHeaderOk
76  (
77  const IOstream::streamFormat PstreamFormat,
78  const word& typeName
79  );
80 
81  //- Construct and return an IFstream for the object.
82  // The results is NULL if the stream construction failed
84 
85  //- To flag master-only reading of objects
86  static bool masterOnlyReading;
87 
88 
89 private:
90 
91  // Private data
92 
93  //- Is this object registered with the registry
94  bool registered_;
95 
96  //- Is this object owned by the registry
97  bool ownedByRegistry_;
98 
99  //- List of modification watch indices
100  mutable labelList watchIndices_;
101 
102  //- eventNo of last update
103  label eventNo_;
104 
105  //- Istream for reading
106  autoPtr<ISstream> isPtr_;
107 
108 
109  // Private Member Functions
110 
111  //- Return Istream
112  Istream& readStream(const bool valid = true);
113 
114  //- No copy assignment
115  void operator=(const regIOobject&) = delete;
116 
117 
118 public:
119 
120  //- Declare friendship with any classes that need access to
121  // masterOnlyReading
125 
126 
127  // Static data
128 
129  //- Runtime type information
130  TypeName("regIOobject");
131 
132  static float fileModificationSkew;
133 
134  static int maxFileModificationPolls;
135 
136 
137  // Constructors
138 
139  //- Construct from IOobject. The optional flag adds special handling
140  //- if the object is the top-level regIOobject (eg, Time).
141  regIOobject(const IOobject& io, const bool isTime = false);
142 
143  //- Copy construct
144  regIOobject(const regIOobject& rio);
145 
146  //- Copy construct, transferring registry registration to the copy
147  //- if registerCopy is true
148  regIOobject(const regIOobject& rio, bool registerCopy);
149 
150  //- Copy construct with new name, transferring registry registration
151  //- to the copy f registerCopy is true
152  regIOobject(const word& newName, const regIOobject&, bool registerCopy);
153 
154  //- Copy construct with new IO parameters
155  regIOobject(const IOobject& io, const regIOobject& rio);
156 
157 
158  //- Destructor
159  virtual ~regIOobject();
160 
161 
162  // Member Functions
163 
164  // Registration
165 
166  //- Add object to registry, if not already registered
167  // \return true if object 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  //- Is this object owned by the registry?
178  inline bool ownedByRegistry() const;
179 
180  //- Transfer ownership of this object to its registry
181  inline void store();
182 
183  //- Transfer ownership of the given object pointer to its registry
184  // \return reference to the object.
185  template<class Type>
186  inline static Type& store(Type* p);
187 
188  //- Transfer ownership of the given object pointer to its registry
189  // \return reference to the object.
190  template<class Type>
191  inline static Type& store(autoPtr<Type>& aptr);
192 
193  //- Transfer ownership of the given object pointer to its registry
194  // \return reference to the object.
195  template<class Type>
196  inline static Type& store(autoPtr<Type>&& aptr);
197 
198  //- Release ownership of this object from its registry
199  // \param unregister optionally set as non-registered
200  inline void release(const bool unregister = false);
201 
202 
203  // Dependency checking
204 
205  //- Event number at last update.
206  inline label eventNo() const;
207 
208  //- Event number at last update.
209  inline label& eventNo();
210 
211  //- Return true if up-to-date with respect to given object
212  bool upToDate(const regIOobject&) const;
213 
214  //- Return true if up-to-date with respect to given objects
215  bool upToDate
216  (
217  const regIOobject&,
218  const regIOobject&
219  ) const;
220 
221  //- Return true if up-to-date with respect to given objects
222  bool upToDate
223  (
224  const regIOobject&,
225  const regIOobject&,
226  const regIOobject&
227  ) const;
228 
229  //- Return true if up-to-date with respect to given objects
230  bool upToDate
231  (
232  const regIOobject&,
233  const regIOobject&,
234  const regIOobject&,
235  const regIOobject&
236  ) const;
237 
238 
239  //- Set as up-to-date
240  void setUpToDate();
241 
242 
243  // Edit
244 
245  //- Rename
246  virtual void rename(const word& newName);
247 
248 
249  // Reading
250 
251  //- Return complete path + object name if the file exists
252  // in the case directory otherwise null. Does not search
253  // up if parallel. Can be overridden to provide this functionality
254  // (e.g. IOdictionary)
255  virtual fileName filePath() const;
256 
257  //- Read and check header info
258  bool headerOk();
259 
260  //- Return Istream and check object type against that given
261  Istream& readStream(const word&, const bool valid = true);
262 
263  //- Close Istream
264  void close();
265 
266  //- Virtual readData function.
267  // Must be defined in derived types for which
268  // re-reading is required
269  virtual bool readData(Istream&);
270 
271  //- Read object
272  virtual bool read();
273 
274  //- Add file watch for fileName on object if not yet watched. Return
275  // index of watch
276  virtual label addWatch(const fileName&);
277 
278  //- Return file-monitoring handles
279  inline const labelList& watchIndices() const;
280 
281  //- Return file-monitoring handles
282  inline labelList& watchIndices();
283 
284  //- Return true if the object's file (or files for objectRegistry)
285  // have been modified. (modified state is cached by Time)
286  virtual bool modified() const;
287 
288  //- Read object if modified (as set by call to modified)
289  virtual bool readIfModified();
290 
291 
292  // Writing
293 
294  //- Pure virtual writeData function.
295  // Must be defined in derived types
296  virtual bool writeData(Ostream&) const = 0;
297 
298  //- Write using given format, version and compression
299  virtual bool writeObject
300  (
304  const bool valid
305  ) const;
306 
307  //- Write using setting from DB
308  virtual bool write(const bool valid = true) const;
309 
310 
311  // Other
312 
313  //- Is object global
314  virtual bool global() const
315  {
316  return false;
317  }
318 
319 
320  // Member operators
321 
322  void operator=(const IOobject&);
323 };
324 
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 } // End namespace Foam
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #include "regIOobjectI.H"
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 #endif
337 
338 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::regIOobject::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write using given format, version and compression.
Definition: regIOobjectWrite.C:39
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::regIOobject::objectStream
Istream * objectStream()
Construct and return an IFstream for the object.
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
typeInfo.H
Foam::regIOobject::release
void release(const bool unregister=false)
Release ownership of this object from its registry.
Definition: regIOobjectI.H:73
Foam::regIOobject::upToDate
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
Definition: regIOobject.C:350
Foam::regIOobject::watchIndices
const labelList & watchIndices() const
Return file-monitoring handles.
Definition: regIOobjectI.H:94
Foam::regIOobject::writeData
virtual bool writeData(Ostream &) const =0
Pure virtual writeData function.
Foam::regIOobject::fileModificationSkew
static float fileModificationSkew
Definition: regIOobject.H:131
Foam::regIOobject::addWatch
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:280
Foam::regIOobject::regIOobject
regIOobject(const IOobject &io, const bool isTime=false)
Definition: regIOobject.C:70
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:202
Foam::regIOobject::checkIn
bool checkIn()
Add object to registry, if not already registered.
Definition: regIOobject.C:201
Foam::regIOobject::maxFileModificationPolls
static int maxFileModificationPolls
Definition: regIOobject.H:133
Foam::regIOobject::global
virtual bool global() const
Is object global.
Definition: regIOobject.H:313
Foam::regIOobject::eventNo
label eventNo() const
Event number at last update.
Definition: regIOobjectI.H:83
Foam::regIOobject::readHeaderOk
bool readHeaderOk(const IOstream::streamFormat PstreamFormat, const word &typeName)
Helper: check readOpt flags and read if necessary.
Definition: regIOobjectRead.C:39
Foam::label
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:62
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::regIOobject::modified
virtual bool modified() const
Return true if the object's file (or files for objectRegistry)
Definition: regIOobjectRead.C:248
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: regIOobjectWrite.C:170
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::regIOobject::readIfModified
virtual bool readIfModified()
Read object if modified (as set by call to modified)
Definition: regIOobjectRead.C:262
IOobject.H
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::regIOobject::ownedByRegistry
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:31
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::regIOobject::masterOnlyReading
static bool masterOnlyReading
To flag master-only reading of objects.
Definition: regIOobject.H:85
Foam::regIOobject::setUpToDate
void setUpToDate()
Set as up-to-date.
Definition: regIOobject.C:422
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::regIOobject::store
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:37
Foam::regIOobject::TypeName
TypeName("regIOobject")
Runtime type information.
Foam::fileOperations::masterUncollatedFileOperation
fileOperations that performs all file operations on the master processor. Requires the calls to be pa...
Definition: masterUncollatedFileOperation.H:85
Foam::regIOobject::checkOut
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:237
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:182
Foam::fileOperations::uncollatedFileOperation
fileOperation that assumes file operations are local.
Definition: uncollatedFileOperation.H:50
Foam::regIOobject::rename
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:428
Foam::List< label >
Foam::regIOobject::filePath
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: regIOobject.C:443
Foam::functionEntries::codeStream
Dictionary entry that contains C++ OpenFOAM code that is compiled to generate the entry itself....
Definition: codeStream.H:116
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::regIOobject::readData
virtual bool readData(Istream &)
Virtual readData function.
Definition: regIOobjectRead.C:196
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::regIOobject::~regIOobject
virtual ~regIOobject()
Destructor.
Definition: regIOobject.C:162
Foam::regIOobject::headerOk
bool headerOk()
Read and check header info.
Definition: regIOobject.C:449
regIOobjectI.H