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-2020 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  //- Dissallow 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");
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  //- Copy constructor, transferring registry registration to copy
115  // if registerCopy is true
116  regIOobject(const regIOobject&, bool registerCopy);
117 
118  //- Copy constructor with new name, transferring registry registration
119  // to copy as specified
120  regIOobject(const word& newName, const regIOobject&, bool registerCopy);
121 
122  //- Copy constructor with new IO parameters
123  regIOobject(const IOobject&, const regIOobject&);
124 
125 
126  //- Destructor
127  virtual ~regIOobject();
128 
129 
130  // Member Functions
131 
132  // Registration
133 
134  //- Add object to registry
135  bool checkIn();
136 
137  //- Remove object from registry
138  bool checkOut();
139 
140  //- Add file watch on object (if registered and READ_IF_MODIFIED)
141  void addWatch();
142 
143  //- Is this object owned by the registry?
144  inline bool ownedByRegistry() const;
145 
146  //- Transfer ownership of this object to its registry
147  inline void store();
148 
149  //- Transfer ownership of the given object pointer to its registry
150  // and return reference to object.
151  template<class Type>
152  inline static Type& store(Type*);
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(autoPtr<Type>&);
158 
159  //- Release ownership of this object from its registry
160  inline void release();
161 
162 
163  // Dependency checking
164 
165  //- Event number at last update.
166  inline label eventNo() const;
167 
168  //- Event number at last update.
169  inline label& eventNo();
170 
171  //- Return true if up-to-date with respect to given object
172  // otherwise false
173  bool upToDate(const regIOobject&) const;
174 
175  //- Return true if up-to-date with respect to given objects
176  // otherwise false
177  bool upToDate
178  (
179  const regIOobject&,
180  const regIOobject&
181  ) const;
182 
183  //- Return true if up-to-date with respect to given objects
184  // otherwise false
185  bool upToDate
186  (
187  const regIOobject&,
188  const regIOobject&,
189  const regIOobject&
190  ) const;
191 
192  //- Return true if up-to-date with respect to given objects
193  // otherwise false
194  bool upToDate
195  (
196  const regIOobject&,
197  const regIOobject&,
198  const regIOobject&,
199  const regIOobject&
200  ) const;
201 
202  //- Set up to date (obviously)
203  void setUpToDate();
204 
205 
206  // Edit
207 
208  //- Rename
209  virtual void rename(const word& newName);
210 
211 
212  // Reading
213 
214  //- Return complete path + object name if the file exists
215  // in the case directory otherwise null. Does not search
216  // up if parallel. Can be overridden to provide this functionality
217  // (e.g. IOdictionary)
218  virtual fileName filePath() const;
219 
220  //- Read and check header info
221  bool headerOk();
222 
223  //- Return Istream and check object type against that given
224  Istream& readStream(const word&, const bool read = true);
225 
226  //- Close Istream
227  void close();
228 
229  //- Virtual readData function.
230  // Must be defined in derived types for which
231  // re-reading is required
232  virtual bool readData(Istream&);
233 
234  //- Read object
235  virtual bool read();
236 
237  //- Return file-monitoring handles
238  inline const labelList& watchIndices() const;
239 
240  //- Return file-monitoring handles
241  inline labelList& watchIndices();
242 
243  //- Return true if the object's file (or files for objectRegistry)
244  // have been modified. (modified state is cached by Time)
245  virtual bool modified() const;
246 
247  //- Read object if modified (as set by call to modified)
248  virtual bool readIfModified();
249 
250  //- Is object same for all processors
251  // Defaults to false, must be overridden by global IO classes
252  virtual bool global() const;
253 
254 
255  // Writing
256 
257  //- Pure virtual writaData function.
258  // Must be defined in derived types
259  virtual bool writeData(Ostream&) const = 0;
260 
261  //- Write using given format, version and compression
262  virtual bool writeObject
263  (
267  const bool write
268  ) const;
269 
270  //- Write using setting from DB
271  virtual bool write(const bool write = true) const;
272 
273 
274  // Member Operators
275 
276  void operator=(const IOobject&);
277 };
278 
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #include "regIOobjectI.H"
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 #endif
291 
292 // ************************************************************************* //
bool upToDate(const regIOobject &) const
Return true if up-to-date with respect to given object.
Definition: regIOobject.C:288
bool readHeaderOk(const IOstream::streamFormat defaultFormat, const word &typeName)
Read header, check readOpt flags and read data if necessary.
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:370
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:397
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:391
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:41
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:54
bool checkOut()
Remove object from registry.
Definition: regIOobject.C:200
void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:218
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:376
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:418
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:52
static float fileModificationSkew
Definition: regIOobject.H:101
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 checkIn()
Add object to registry.
Definition: regIOobject.C:164
Namespace for OpenFOAM.
virtual ~regIOobject()
Destructor.
Definition: regIOobject.C:134