1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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
25 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 defineTypeNameAndDebug(IOobject, 0);
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 Foam::IOobject::IOobject
43 const fileName& instance,
44 const objectRegistry& registry,
51 headerClassName_(typeName),
58 registerObject_(registerObject),
61 if (objectRegistry::debug)
63 Info<< "Constructing IOobject called " << name_
64 << " of type " << headerClassName_
70 Foam::IOobject::IOobject
73 const fileName& instance,
74 const fileName& local,
75 const objectRegistry& registry,
82 headerClassName_(typeName),
89 registerObject_(registerObject),
92 if (objectRegistry::debug)
94 Info<< "Constructing IOobject called " << name_
95 << " of type " << headerClassName_
101 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
103 Foam::IOobject::~IOobject()
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 const Foam::objectRegistry& Foam::IOobject::db() const
115 const Foam::Time& Foam::IOobject::time() const
121 const Foam::fileName& Foam::IOobject::caseName() const
123 return time().caseName();
127 const Foam::fileName& Foam::IOobject::rootPath() const
129 return time().rootPath();
133 Foam::fileName Foam::IOobject::path() const
135 return rootPath()/caseName()/instance()/db_.dbDir()/local();
139 Foam::fileName Foam::IOobject::path
141 const word& instance,
142 const fileName& local
145 return rootPath()/caseName()/instance/db_.dbDir()/local;
149 Foam::fileName Foam::IOobject::filePath() const
151 fileName path = this->path();
152 fileName objectPath = path/name();
154 if (file(objectPath))
162 time().processorCase()
164 instance() == time().system()
165 || instance() == time().constant()
169 fileName parentObjectPath =
170 rootPath()/caseName()
171 /".."/instance()/db_.dbDir()/local()/name();
173 if (file(parentObjectPath))
175 return parentObjectPath;
181 word newInstancePath = time().findInstancePath(instant(instance()));
183 if (newInstancePath.size())
187 rootPath()/caseName()
188 /newInstancePath/db_.dbDir()/local()/name()
199 return fileName::null;
203 Foam::Istream* Foam::IOobject::objectStream()
205 fileName fName = filePath();
207 if (fName != fileName::null)
209 IFstream* isPtr = new IFstream(fName);
228 bool Foam::IOobject::headerOk()
232 Istream* isPtr = objectStream();
234 // If the stream has failed return
237 if (objectRegistry::debug)
240 << "IOobject::headerOk() : "
241 << "file " << objectPath() << " could not be opened"
249 // Try reading header
250 if (!readHeader(*isPtr))
252 if (objectRegistry::debug)
254 IOWarningIn("IOobject::headerOk()", (*isPtr))
255 << "failed to read header of file " << objectPath()
269 void Foam::IOobject::setBad(const string& s)
271 if (objState_ != GOOD)
273 FatalErrorIn("IOobject::setBad(const string&)")
274 << "recurrent failure for object " << s
280 Info<< "IOobject::setBad(const string&) : "
281 << "broken object " << s << info() << endl;
288 void Foam::IOobject::operator=(const IOobject& io)
291 headerClassName_ = io.headerClassName_;
293 instance_ = io.instance_;
297 objState_ = io.objState_;
301 // ************************************************************************* //