1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 IOobject defines the attributes of an object for which implicit
30 objectRegistry management is supported, and provides the infrastructure
31 for performing stream I/O.
33 An IOobject is constructed with an object name, a class name, an instance
34 path, a reference to a objectRegistry, and parameters determining its
39 Define what is done on object construction and explicit reads:
41 Object must be read from Istream on construction. \n
42 Error if Istream does not exist or can't be read.
43 @param READ_IF_PRESENT
44 Read object from Istream if Istream exists, otherwise don't. \n
45 Error only if Istream exists but can't be read.
51 Define what is done on object destruction and explicit writes:
53 Object is written automatically when requested to by the
56 No automatic write on destruction but can be written explicitly
64 \*---------------------------------------------------------------------------*/
72 #include "InfoProxy.H"
74 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 /*---------------------------------------------------------------------------*\
83 Class IOobject Declaration
84 \*---------------------------------------------------------------------------*/
93 //- Enumeration defining the valid states of an IOobject
100 //- Enumeration defining the read options
108 //- Enumeration defining the write options
123 //- Class name read from header
124 word headerClassName_;
129 //- Instance path component
132 //- Local path component
135 //- objectRegistry reference
136 const objectRegistry& db_;
144 //- Register object created from this IOobject with registry if true
145 bool registerObject_;
148 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 fileName& instance,
187 const objectRegistry& registry,
188 readOption r=NO_READ,
189 writeOption w=NO_WRITE,
190 bool registerObject=true
193 //- Construct from name, instance, local, registry, io options
197 const fileName& instance,
198 const fileName& local,
199 const objectRegistry& registry,
200 readOption r=NO_READ,
201 writeOption w=NO_WRITE,
202 bool registerObject=true
205 //- Construct from path, registry, io options
206 // Uses fileNameComponents() to split path into components.
209 const fileName& path,
210 const objectRegistry& registry,
211 readOption r=NO_READ,
212 writeOption w=NO_WRITE,
213 bool registerObject=true
217 Foam::autoPtr<IOobject> clone() const
219 return autoPtr<IOobject>(new IOobject(*this));
233 const Time& time() const;
235 //- Return the local objectRegistry
236 const objectRegistry& db() const;
239 const word& name() const
244 //- Return name of the class name read from header
245 const word& headerClassName() const
247 return headerClassName_;
250 //- Return non-constant access to the optional note
256 //- Return the optional note
257 const string& note() const
263 virtual void rename(const word& newName)
268 //- Register object created from this IOobject with registry if true
269 bool registerObject() const
271 return registerObject_;
275 // Read/write options
277 readOption readOpt() const
282 readOption& readOpt()
287 writeOption writeOpt() const
292 writeOption& writeOpt()
300 const fileName& rootPath() const;
302 const fileName& caseName() const;
304 const fileName& instance() const
314 const fileName& local() const
319 //- Return complete path
320 fileName path() const;
322 //- Return complete path with alternative instance and local
325 const word& instance,
326 const fileName& local = ""
329 //- Return complete path + object name
330 fileName objectPath() const
332 return path()/name();
335 //- Return complete path + object name if the file exists
336 // either in the case/processor or case otherwise null
337 fileName filePath() const;
343 bool readHeader(Istream&);
345 //- Read and check header info
351 //- Write the standard OpenFOAM file/dictionary banner
352 // Optionally without -*- C++ -*- editor hint (eg, for logs)
353 template<class Stream>
354 static inline Stream& writeBanner(Stream& os, bool noHint=false);
356 //- Write the standard file section divider
357 template<class Stream>
358 static inline Stream& writeDivider(Stream& os);
360 //- Write the standard end file divider
361 template<class Stream>
362 static inline Stream& writeEndDivider(Stream& os);
365 bool writeHeader(Ostream&) const;
372 return objState_ == GOOD;
377 return objState_ == BAD;
383 //- Return info proxy.
384 // Used to print token information to a stream
385 InfoProxy<IOobject> info() const
393 void operator=(const IOobject&);
397 #if defined (__GNUC__)
400 Ostream& operator<<(Ostream& os, const InfoProxy<IOobject>& ip);
403 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
405 } // End namespace Foam
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 # include "IOobjectI.H"
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 // ************************************************************************* //