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
25 \*---------------------------------------------------------------------------*/
28 #include <OpenFOAM/OSspecific.H>
29 #include <OpenFOAM/gzstream.h>
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::IFstream, 0);
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
41 compression_(IOstream::UNCOMPRESSED)
47 Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
48 "cannot open null file " << endl;
52 ifPtr_ = new ifstream(pathname.c_str());
54 // If the file is compressed, decompress it before reading.
55 if (!ifPtr_->good() && isFile(pathname + ".gz", false))
59 Info<< "IFstreamAllocator::IFstreamAllocator(const fileName&) : "
60 "decompressing " << pathname + ".gz" << endl;
65 ifPtr_ = new igzstream((pathname + ".gz").c_str());
69 compression_ = IOstream::COMPRESSED;
75 Foam::IFstreamAllocator::~IFstreamAllocator()
81 std::istream& Foam::IFstreamAllocator::stdStream()
85 FatalErrorIn("IFstreamAllocator::stdStream()")
86 << "No stream allocated" << abort(FatalError);
92 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 Foam::IFstream::IFstream
96 const fileName& pathname,
101 IFstreamAllocator(pathname),
105 "IFstream.sourceFile_",
108 IFstreamAllocator::compression_
114 setState(ifPtr_->rdstate());
120 Info<< "IFstream::IFstream(const fileName&,"
121 "streamFormat=ASCII,"
122 "versionNumber=currentVersion) : "
123 "could not open file for input"
124 << endl << info() << endl;
138 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
140 Foam::IFstream::~IFstream()
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 void Foam::IFstream::print(Ostream& os) const
154 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
156 Foam::IFstream& Foam::IFstream::operator()() const
160 // also checks .gz file
161 if (isFile(pathname_, true))
163 check("IFstream::operator()");
168 FatalIOErrorIn("IFstream::operator()", *this)
169 << "file " << pathname_ << " does not exist"
170 << exit(FatalIOError);
174 return const_cast<IFstream&>(*this);
178 // ************************ vim: set sw=4 sts=4 et: ************************ //