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