1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 std::istream& Foam::IFstreamAllocator::stdStream()
84 FatalErrorIn("IFstreamAllocator::stdStream()")
85 << "No stream allocated" << abort(FatalError);
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
93 Foam::IFstream::IFstream
95 const fileName& pathname,
100 IFstreamAllocator(pathname),
104 "IFstream.sourceFile_",
107 IFstreamAllocator::compression_
113 setState(ifPtr_->rdstate());
119 Info<< "IFstream::IFstream(const fileName&,"
120 "streamFormat=ASCII,"
121 "versionNumber=currentVersion) : "
122 "could not open file for input"
123 << endl << info() << endl;
137 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
139 Foam::IFstream::~IFstream()
143 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 void Foam::IFstream::print(Ostream& os) const
153 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
155 Foam::IFstream& Foam::IFstream::operator()() const
159 // also checks .gz file
160 if (isFile(pathname_, true))
162 check("IFstream::operator()");
167 FatalIOErrorIn("IFstream::operator()", *this)
168 << "file " << pathname_ << " does not exist"
169 << exit(FatalIOError);
173 return const_cast<IFstream&>(*this);
177 // ************************************************************************* //