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 \*---------------------------------------------------------------------------*/
28 #include "OSspecific.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(IFstream, 0);
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
45 compression_(IOstream::UNCOMPRESSED)
51 Info<< "IFstreamAllocator::IFstreamAllocator"
52 "(const fileName& pathname) : "
53 "can't open null file "
58 ifPtr_ = new ifstream(pathname.c_str());
60 // If the file is compressed, decompress it before reading.
61 if (!ifPtr_->good() && file(pathname + ".gz"))
65 Info<< "IFstreamAllocator::IFstreamAllocator"
66 "(const fileName& pathname) : "
67 "decompressing " << pathname + ".gz"
73 ifPtr_ = new igzstream((pathname + ".gz").c_str());
77 compression_ = IOstream::COMPRESSED;
83 IFstreamAllocator::~IFstreamAllocator()
89 istream& IFstreamAllocator::stdStream()
93 FatalErrorIn("IFstreamAllocator::stdStream()")
94 << "No stream allocated." << abort(FatalError);
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
104 const fileName& pathname,
106 versionNumber version
109 IFstreamAllocator(pathname),
113 "IFstream.sourceFile_",
116 IFstreamAllocator::compression_
122 setState(ifPtr_->rdstate());
128 Info<< "IFstream::IFstream(const fileName& pathname,"
129 "streamFormat format=ASCII,"
130 "versionNumber version=currentVersion) : "
131 "couldn't open File for input"
132 << endl << info() << endl;
146 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 IFstream::~IFstream()
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 void IFstream::print(Ostream& os) const
162 //- Return a non-const reference to const Istream
163 // Needed for read-constructors where the stream argument is temporary:
164 // e.g. thing thisThing(IFstream("thingFileName")());
165 IFstream& IFstream::operator()() const
169 if (!file(pathname_) && !file(pathname_ + ".gz"))
171 FatalIOErrorIn("IFstream::operator()", *this)
172 << "file " << pathname_ << " does not exist"
173 << exit(FatalIOError);
177 check("IFstream::operator()");
182 return const_cast<IFstream&>(*this);
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 } // End namespace Foam
190 // ************************************************************************* //