1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
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 Does not check timestamp or re-read.
43 \param MUST_READ_IF_MODIFIED
44 Object must be read from Istream on construction. \n
45 Error if Istream does not exist or can't be read. If object is
46 registered its timestamp will be checked every timestep and possibly
48 \param READ_IF_PRESENT
49 Read object from Istream if Istream exists, otherwise don't. \n
50 Error only if Istream exists but can't be read.
51 Does not check timestamp or re-read.
57 Define what is done on object destruction and explicit writes:
59 Object is written automatically when requested to by the
62 No automatic write on destruction but can be written explicitly
70 \*---------------------------------------------------------------------------*/
78 #include "InfoProxy.H"
80 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
88 /*---------------------------------------------------------------------------*\
89 Class IOobject Declaration
90 \*---------------------------------------------------------------------------*/
99 //- Enumeration defining the valid states of an IOobject
106 //- Enumeration defining the read options
110 MUST_READ_IF_MODIFIED,
115 //- Enumeration defining the write options
130 //- Class name read from header
131 word headerClassName_;
136 //- Instance path component
139 //- Local path component
142 //- objectRegistry reference
143 const objectRegistry& db_;
151 //- Register object created from this IOobject with registry if true
152 bool registerObject_;
155 objectState objState_;
159 // Protected Member Functions
161 //- Construct and return an IFstream for the object.
162 // The results is NULL if the stream construction failed
163 Istream* objectStream();
165 //- Construct and return an IFstream for the object given the
166 // exact file. The results is NULL if the stream construction failed
167 Istream* objectStream(const fileName&);
169 //- Set the object state to bad
170 void setBad(const string&);
175 //- Runtime type information
176 TypeName("IOobject");
179 // Static Member Functions
181 //- Split path into instance, local, name components
182 static bool fileNameComponents
184 const fileName& path,
193 //- Construct from name, instance, registry, io options
197 const fileName& instance,
198 const objectRegistry& registry,
199 readOption r=NO_READ,
200 writeOption w=NO_WRITE,
201 bool registerObject=true
204 //- Construct from name, instance, local, registry, io options
208 const fileName& instance,
209 const fileName& local,
210 const objectRegistry& registry,
211 readOption r=NO_READ,
212 writeOption w=NO_WRITE,
213 bool registerObject=true
216 //- Construct from path, registry, io options
217 // Uses fileNameComponents() to split path into components.
220 const fileName& path,
221 const objectRegistry& registry,
222 readOption r=NO_READ,
223 writeOption w=NO_WRITE,
224 bool registerObject=true
228 Foam::autoPtr<IOobject> clone() const
230 return autoPtr<IOobject>(new IOobject(*this));
243 const Time& time() const;
245 //- Return the local objectRegistry
246 const objectRegistry& db() const;
249 const word& name() const
254 //- Return name of the class name read from header
255 const word& headerClassName() const
257 return headerClassName_;
260 //- Return non-constant access to the optional note
266 //- Return the optional note
267 const string& note() const
273 virtual void rename(const word& newName)
278 //- Register object created from this IOobject with registry if true
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 OpenFOAM 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 // ************************************************************************* //