FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/IOobject.H>
42 #include <OpenFOAM/typeInfo.H>
43 #include <OpenFOAM/OSspecific.H>
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class regIOobject Declaration
53 \*---------------------------------------------------------------------------*/
54 
56 :
57  public IOobject
58 {
59 
60 private:
61 
62  // Private data
63 
64  //- Is this object registered with the registry
65  bool registered_;
66 
67  //- Is this object owned by the registry
68  bool ownedByRegistry_;
69 
70  //- Time of last modification
71  mutable time_t lastModified_;
72 
73  //- eventNo of last update
74  label eventNo_;
75 
76  //- Istream for reading
77  Istream* isPtr_;
78 
79 
80  // Private member functions
81 
82  //- Return Istream
83  Istream& readStream();
84 
85  //- Dissallow assignment
86  void operator=(const regIOobject&);
87 
88 
89 public:
90 
91  // Static data
92 
93  //- Runtime type information
94  TypeName("regIOobject");
95 
97 
98 
99  // Constructors
100 
101  //- Construct from IOobject. Optional flag for if IOobject is the
102  // top level regIOobject.
103  regIOobject(const IOobject&, const bool isTime = false);
104 
105  //- Construct as copy
106  regIOobject(const regIOobject&);
107 
108  //- Construct as copy, and transferring registry registration to copy
109  // if registerCopy is true
110  regIOobject(const regIOobject&, bool registerCopy);
111 
112 
113  // Destructor
114 
115  virtual ~regIOobject();
116 
117 
118  // Member functions
119 
120  // Registration
121 
122  //- Add object to registry
123  bool checkIn();
124 
125  //- Remove object from registry
126  bool checkOut();
127 
128  //- Is this object owned by the registry?
129  inline bool ownedByRegistry() const;
130 
131  //- Transfer ownership of this object to its registry
132  inline void store();
133 
134  //- Transfer ownership of the given object pointer to its registry
135  // and return reference to object.
136  template<class Type>
137  inline static Type& store(Type*);
138 
139  //- Transfer ownership of the given object pointer to its registry
140  // and return reference to object.
141  template<class Type>
142  inline static Type& store(autoPtr<Type>&);
143 
144  //- Release ownership of this object from its registry
145  inline void release();
146 
147 
148  // Dependency checking
149 
150  //- Event number at last update.
151  inline label eventNo() const;
152 
153  //- Event number at last update.
154  inline label& eventNo();
155 
156  //- Am I uptodate with respect to other regIOobjects
157  bool upToDate(const word&) const;
158  bool upToDate(const word&, const word&) const;
159  bool upToDate(const word&, const word&, const word&) const;
160  bool upToDate
161  (
162  const word&,
163  const word&,
164  const word&,
165  const word&
166  ) const;
167 
168  //- Flag me as up to date
169  void setUpToDate();
170 
171 
172  // Edit
173 
174  //- Rename
175  virtual void rename(const word& newName);
176 
177 
178  // Reading
179 
180  //- Return Istream and check object type against that given
181  Istream& readStream(const word&);
182 
183  //- Close Istream
184  void close();
185 
186  //- Virtual readData function.
187  // Must be defined in derived types for which
188  // re-reading is required
189  virtual bool readData(Istream&);
190 
191  //- Read object
192  virtual bool read();
193 
194  //- Return true if the object's file has been modified
195  virtual bool modified() const;
196 
197  //- Read object if modified
198  virtual bool readIfModified();
199 
200 
201  // Writing
202 
203  //- Pure virtual writaData function.
204  // Must be defined in derived types
205  virtual bool writeData(Ostream&) const = 0;
206 
207  //- Write using given format, version and compression
208  virtual bool writeObject
209  (
213  ) const;
214 
215  //- Write using setting from DB
216  virtual bool write() const;
217 
218 
219  // Member operators
220 
221  void operator=(const IOobject&);
222 };
223 
224 
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 
227 } // End namespace Foam
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 #include <OpenFOAM/regIOobjectI.H>
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #endif
236 
237 // ************************ vim: set sw=4 sts=4 et: ************************ //