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-2019 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 #include "typeInfo.H"
43 #include "OSspecific.H"
44 #include "NamedEnum.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class regIOobject Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class regIOobject
57 :
58  public IOobject
59 {
60 
61 protected:
62 
63  //- Helper: check readOpt flags and read if necessary
64  bool readHeaderOk
65  (
66  const IOstream::streamFormat PstreamFormat,
67  const word& typeName
68  );
69 
70 
71 private:
72 
73  // Private Data
74 
75  //- Is this object registered with the registry
76  bool registered_;
77 
78  //- Is this object owned by the registry
79  bool ownedByRegistry_;
80 
81  //- List of modification watch indices
82  mutable labelList watchIndices_;
83 
84  //- eventNo of last update
85  label eventNo_;
86 
87  //- Istream for reading
88  autoPtr<ISstream> isPtr_;
89 
90 
91  // Private Member Functions
92 
93  //- Return Istream
94  Istream& readStream(const bool read = true);
95 
96  //- Dissallow assignment
97  void operator=(const regIOobject&);
98 
99 
100 public:
101 
102  // Static data
103 
104  //- Runtime type information
105  TypeName("regIOobject");
107  static float fileModificationSkew;
108 
109 
110  // Constructors
111 
112  //- Construct from IOobject. Optional flag for if IOobject is the
113  // top level regIOobject.
114  regIOobject(const IOobject&, const bool isTime = false);
115 
116  //- Copy constructor
117  regIOobject(const regIOobject&);
118 
119  //- Copy constructor, transferring registry registration to copy
120  // if registerCopy is true
121  regIOobject(const regIOobject&, bool registerCopy);
122 
123  //- Copy constructor with new name, transferring registry registration
124  // to copy as specified
125  regIOobject(const word& newName, const regIOobject&, bool registerCopy);
126 
127  //- Copy constructor with new IO parameters
128  regIOobject(const IOobject&, const regIOobject&);
129 
130 
131  //- Destructor
132  virtual ~regIOobject();
133 
134 
135  // Member Functions
136 
137  // Registration
138 
139  //- Add object to registry
140  bool checkIn();
141 
142  //- Remove object from registry
143  bool checkOut();
144 
145  //- Add file watch on object (if registered and READ_IF_MODIFIED)
146  virtual void addWatch();
147 
148  //- Is this object owned by the registry?
149  inline bool ownedByRegistry() const;
150 
151  //- Transfer ownership of this object to its registry
152  inline void store();
153 
154  //- Transfer ownership of the given object pointer to its registry
155  // and return reference to object.
156  template<class Type>
157  inline static Type& store(Type*);
158 
159  //- Transfer ownership of the given object pointer to its registry
160  // and return reference to object.
161  template<class Type>
162  inline static Type& store(autoPtr<Type>&);
163 
164  //- Release ownership of this object from its registry
165  inline void release();
166 
167 
168  // Dependency checking
169 
170  //- Event number at last update.
171  inline label eventNo() const;
172 
173  //- Event number at last update.
174  inline label& eventNo();
175 
176  //- Return true if up-to-date with respect to given object
177  // otherwise false
178  bool upToDate(const regIOobject&) const;
179 
180  //- Return true if up-to-date with respect to given objects
181  // otherwise false
182  bool upToDate
183  (
184  const regIOobject&,
185  const regIOobject&
186  ) const;
187 
188  //- Return true if up-to-date with respect to given objects
189  // otherwise false
190  bool upToDate
191  (
192  const regIOobject&,
193  const regIOobject&,
194  const regIOobject&
195  ) const;
196 
197  //- Return true if up-to-date with respect to given objects
198  // otherwise false
199  bool upToDate
200  (
201  const regIOobject&,
202  const regIOobject&,
203  const regIOobject&,
204  const regIOobject&
205  ) const;
206 
207  //- Set up to date (obviously)
208  void setUpToDate();
209 
210 
211  // Edit
212 
213  //- Rename
214  virtual void rename(const word& newName);
215 
216 
217  // Reading
218 
219  //- Return complete path + object name if the file exists
220  // in the case directory otherwise null. Does not search
221  // up if parallel. Can be overridden to provide this functionality
222  // (e.g. IOdictionary)
223  virtual fileName filePath() const;
224 
225  //- Read and check header info
226  bool headerOk();
227 
228  //- Return Istream and check object type against that given
229  Istream& readStream(const word&, const bool read = true);
230 
231  //- Close Istream
232  void close();
233 
234  //- Virtual readData function.
235  // Must be defined in derived types for which
236  // re-reading is required
237  virtual bool readData(Istream&);
238 
239  //- Read object
240  virtual bool read();
241 
242  //- Add file watch for fileName on object if not yet watched. Return
243  // index of watch
244  virtual label addWatch(const fileName&);
245 
246  //- Return file-monitoring handles
247  inline const labelList& watchIndices() const;
248 
249  //- Return file-monitoring handles
250  inline labelList& watchIndices();
251 
252  //- Return true if the object's file (or files for objectRegistry)
253  // have been modified. (modified state is cached by Time)
254  virtual bool modified() const;
255 
256  //- Read object if modified (as set by call to modified)
257  virtual bool readIfModified();
258 
259  //- Is object same for all processors
260  // Defaults to false, must be overridden by global IO classes
261  virtual bool global() const;
262 
263 
264  // Writing
265 
266  //- Pure virtual writaData function.
267  // Must be defined in derived types
268  virtual bool writeData(Ostream&) const = 0;
269 
270  //- Write using given format, version and compression
271  virtual bool writeObject
272  (
276  const bool write
277  ) const;
278 
279  //- Write using setting from DB
280  virtual bool write(const bool write = true) const;
281 
282 
283  // Member Operators
284 
285  void operator=(const IOobject&);
286 };
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #include "regIOobjectI.H"
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************************************************************* //
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
Definition: regIOobject.C:322
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
A class for handling file names.
Definition: fileName.H:79
virtual bool read()
Read object.
void setUpToDate()
Set up to date (obviously)
Definition: regIOobject.C:404
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool headerOk()
Read and check header info.
Definition: regIOobject.C:431
TypeName("regIOobject")
Runtime type information.
const labelList & watchIndices() const
Return file-monitoring handles.
Definition: regIOobjectI.H:94
void release()
Release ownership of this object from its registry.
Definition: regIOobjectI.H:77
virtual fileName filePath() const
Return complete path + object name if the file exists.
Definition: regIOobject.C:425
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:28
regIOobject(const IOobject &, const bool isTime=false)
Construct from IOobject. Optional flag for if IOobject is the.
Definition: regIOobject.C:54
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void close()
Close Istream.
A class for handling words, derived from string.
Definition: word.H:59
virtual bool readIfModified()
Read object if modified (as set by call to modified)
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
label eventNo() const
Event number at last update.
Definition: regIOobjectI.H:83
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
void store()
Transfer ownership of this object to its registry.
Definition: regIOobjectI.H:34
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:211
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:252
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:410
virtual bool readData(Istream &)
Virtual readData function.
virtual bool modified() const
Return true if the object&#39;s file (or files for objectRegistry)
virtual bool global() const
Is object same for all processors.
Definition: regIOobject.C:452
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
static float fileModificationSkew
Definition: regIOobject.H:106
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual bool write(const bool write=true) const
Write using setting from DB.
virtual bool writeData(Ostream &) const =0
Pure virtual writaData function.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
bool readHeaderOk(const IOstream::streamFormat PstreamFormat, const word &typeName)
Helper: check readOpt flags and read if necessary.
bool checkIn()
Add object to registry.
Definition: regIOobject.C:175
Namespace for OpenFOAM.
virtual ~regIOobject()
Destructor.
Definition: regIOobject.C:147