1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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/>.
24 \*---------------------------------------------------------------------------*/
27 #include "OSspecific.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::IFstream, 0);
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
40 compression_(IOstream::UNCOMPRESSED)
46 Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
47 "cannot open null file " << endl;
51 ifPtr_ = new ifstream(pathname.c_str());
53 // If the file is compressed, decompress it before reading.
54 if (!ifPtr_->good() && isFile(pathname + ".gz", false))
58 Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
59 "decompressing " << pathname + ".gz" << endl;
64 ifPtr_ = new igzstream((pathname + ".gz").c_str());
68 compression_ = IOstream::COMPRESSED;
74 Foam::IFstreamAllocator::~IFstreamAllocator()
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
82 Foam::IFstream::IFstream
84 const fileName& pathname,
89 IFstreamAllocator(pathname),
93 "IFstream.sourceFile_",
96 IFstreamAllocator::compression_
102 setState(ifPtr_->rdstate());
108 Info<< "IFstream::IFstream(const fileName&,"
109 "streamFormat=ASCII,"
110 "versionNumber=currentVersion) : "
111 "could not open file for input"
112 << endl << info() << endl;
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 Foam::IFstream::~IFstream()
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 std::istream& Foam::IFstream::stdStream()
138 FatalErrorIn("IFstream::stdStream()")
139 << "No stream allocated" << abort(FatalError);
145 const std::istream& Foam::IFstream::stdStream() const
149 FatalErrorIn("IFstream::stdStream() const")
150 << "No stream allocated" << abort(FatalError);
156 void Foam::IFstream::print(Ostream& os) const
164 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
166 Foam::IFstream& Foam::IFstream::operator()() const
170 // also checks .gz file
171 if (isFile(pathname_, true))
173 check("IFstream::operator()");
178 FatalIOErrorIn("IFstream::operator()", *this)
179 << "file " << pathname_ << " does not exist"
180 << exit(FatalIOError);
184 return const_cast<IFstream&>(*this);
188 // ************************************************************************* //