1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 IOobject defines the attributes of an object for which implicit
29 objectRegistry management is supported, and provides the infrastructure
30 for performing stream I/O.
32 An IOobject is constructed with an object name, a class name, an instance
33 path, a reference to a objectRegistry, and parameters determining its
38 Define what is done on object construction and explicit reads:
40 Object must be read from Istream on construction. \n
41 Error if Istream does not exist or can't be read.
42 @param READ_IF_PRESENT
43 Read object from Istream if Istream exists, otherwise don't. \n
44 Error only if Istream exists but can't be read.
50 Define what is done on object destruction and explicit writes:
52 Object is written automatically when requested to by the
55 No automatic write on destruction but can be written explicitly
63 \*---------------------------------------------------------------------------*/
71 #include "InfoProxy.H"
73 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81 /*---------------------------------------------------------------------------*\
82 Class IOobject Declaration
83 \*---------------------------------------------------------------------------*/
92 //- Enumeration defining the valid states of an IOobject
99 //- Enumeration defining the read options
107 //- Enumeration defining the write options
122 //- Class name read from header
123 word headerClassName_;
128 //- Instance path component
131 //- Local path component
134 //- objectRegistry reference
135 const objectRegistry& db_;
143 //- Register object created from this IOobject with registry if true
144 bool registerObject_;
147 objectState objState_;
152 // Protected member functions
154 //- Construct and return an IFstream for the object.
155 // The results is NULL if the stream construction failed
156 Istream* objectStream();
158 //- Set the object state to bad
159 void setBad(const string&);
164 //- Runtime type information
165 TypeName("IOobject");
168 // Static Member Functions
170 //- Split path into instance, local, name components
171 static bool fileNameComponents
173 const fileName& path,
182 //- Construct from name, instance, registry, io options
186 const Time& registry,
187 readOption r = NO_READ,
188 writeOption w = NO_WRITE
191 //- Construct from name, instance, registry, io options
195 const fileName& instance,
196 const objectRegistry& registry,
197 readOption r = NO_READ,
198 writeOption w = NO_WRITE,
199 bool registerObject = true
202 //- Construct from name, instance, local, registry, io options
206 const fileName& instance,
207 const fileName& local,
208 const objectRegistry& registry,
209 readOption r = NO_READ,
210 writeOption w = NO_WRITE,
211 bool registerObject = true
214 //- Construct from path, registry, io options
215 // Uses fileNameComponents() to split path into components.
218 const fileName& path,
219 const objectRegistry& registry,
220 readOption r = NO_READ,
221 writeOption w = NO_WRITE,
222 bool registerObject = true
226 Foam::autoPtr<IOobject> clone() const
228 return autoPtr<IOobject>(new IOobject(*this));
242 const Time& time() const;
244 //- Return the local objectRegistry
245 const objectRegistry& db() const;
248 const word& name() const
253 //- Return name of the class name read from header
254 const word& headerClassName() const
256 return headerClassName_;
259 //- Return non-constant access to the optional note
265 //- Return the optional note
266 const string& note() const
272 virtual void rename(const word& newName)
277 //- Register object created from this IOobject with registry
279 bool registerObject() const
281 return registerObject_;
285 // Read/write options
287 readOption readOpt() const
292 readOption& readOpt()
297 writeOption writeOpt() const
302 writeOption& writeOpt()
310 const fileName& rootPath() const;
312 const fileName& caseName() const;
314 const fileName& instance() const
324 const fileName& local() const
329 //- Return complete path
330 fileName path() const;
332 //- Return complete path with alternative instance and local
335 const word& instance,
336 const fileName& local = ""
339 //- Return complete path + object name
340 fileName objectPath() const
342 return path()/name();
345 //- Return complete path + object name if the file exists
346 // either in the case/processor or case otherwise null
347 fileName filePath() const;
353 bool readHeader(Istream&);
355 //- Read and check header info
361 //- Write the standard FOAM file/dictionary banner
362 // Optionally without -*- C++ -*- editor hint (eg, for logs)
363 template<class Stream>
364 static inline Stream& writeBanner(Stream& os, bool noHint=false);
366 //- Write the standard file section divider
367 template<class Stream>
368 static inline Stream& writeDivider(Stream& os);
370 //- Write the standard end file divider
371 template<class Stream>
372 static inline Stream& writeEndDivider(Stream& os);
375 bool writeHeader(Ostream&) const;
382 return objState_ == GOOD;
387 return objState_ == BAD;
393 //- Return info proxy.
394 // Used to print token information to a stream
395 InfoProxy<IOobject> info() const
403 void operator=(const IOobject&);
407 #if defined (__GNUC__)
410 Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);
413 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 } // End namespace Foam
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 # include "IOobjectI.H"
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
425 // ************************************************************************* //