Commit 1bc9eea3 authored by Andrew Heather's avatar Andrew Heather
Browse files
parents 4a2475ac 4d5ce2ea
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "IFstream.H"
#include "OSspecific.H"
#include "zfstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(IFstream, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
:
ifPtr_(NULL),
compression_(IOstream::UNCOMPRESSED)
{
if (!pathname.size())
{
if (IFstream::debug)
{
Info<< "IFstreamAllocator::IFstreamAllocator"
"(const fileName& pathname) : "
"can't open null file "
<< endl;
}
}
ifPtr_ = new ifstream(pathname.c_str());
// If the file is compressed, decompress it before reading.
if (!ifPtr_->good() && file(pathname + ".gz"))
{
if (IFstream::debug)
{
Info<< "IFstreamAllocator::IFstreamAllocator"
"(const fileName& pathname) : "
"decompressing " << pathname + ".gz"
<< endl;
}
delete ifPtr_;
ifPtr_ = new gzifstream((pathname + ".gz").c_str());
if (ifPtr_->good())
{
compression_ = IOstream::COMPRESSED;
}
}
}
IFstreamAllocator::~IFstreamAllocator()
{
delete ifPtr_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
IFstream::IFstream
(
const fileName& pathname,
streamFormat format,
versionNumber version
)
:
IFstreamAllocator(pathname),
ISstream
(
*ifPtr_,
"IFstream.sourceFile_",
format,
version,
IFstreamAllocator::compression_
),
pathname_(pathname)
{
setClosed();
setState(ifPtr_->rdstate());
if (!good())
{
if (debug)
{
Info<< "IFstream::IFstream(const fileName& pathname,"
"streamFormat format=ASCII,"
"versionNumber version=currentVersion) : "
"couldn't open File for input"
<< endl << info() << endl;
}
setBad();
}
else
{
setOpened();
}
lineNumber_ = 1;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
IFstream::~IFstream()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void IFstream::print(Ostream& os) const
{
// Print File data
os << "IFstream: ";
ISstream::print(os);
}
//- Return a non-const reference to const Istream
// Needed for read-constructors where the stream argument is temporary:
// e.g. thing thisThing(IFstream("thingFileName")());
IFstream& IFstream::operator()() const
{
if (!good())
{
if (!file(pathname_) && !file(pathname_ + ".gz"))
{
FatalIOErrorIn("IFstream::operator()", *this)
<< "file " << pathname_ << " does not exist"
<< exit(FatalIOError);
}
else
{
check("IFstream::operator()");
FatalIOError.exit();
}
}
return const_cast<IFstream&>(*this);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OFstream.H"
#include "OSspecific.H"
#include "zfstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(OFstream, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OFstreamAllocator::OFstreamAllocator
(
const fileName& pathname,
IOstream::compressionType compression
)
:
ofPtr_(NULL)
{
if (!pathname.size())
{
if (OFstream::debug)
{
Info
<< "OFstreamAllocator::OFstreamAllocator"
"(const fileName& pathname) : "
"can't open null file "
<< endl;
}
}
if (compression == IOstream::COMPRESSED)
{
if (file(pathname))
{
rm(pathname);
}
gzofstream* gzofPtr = new gzofstream((pathname + ".gz").c_str());
gzofPtr->buffer_.setcompressionlevel(Z_BEST_SPEED);
ofPtr_ = gzofPtr;
}
else
{
if (file(pathname + ".gz"))
{
rm(pathname + ".gz");
}
ofPtr_ = new ofstream(pathname.c_str());
}
}
OFstreamAllocator::~OFstreamAllocator()
{
delete ofPtr_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
OFstream::OFstream
(
const fileName& pathname,
streamFormat format,
versionNumber version,
compressionType compression
)
:
OFstreamAllocator(pathname, compression),
OSstream(*ofPtr_, "OFstream.sinkFile_", format, version, compression),
pathname_(pathname)
{
setClosed();
setState(ofPtr_->rdstate());
if (!good())
{
if (debug)
{
Info<< "IFstream::IFstream(const fileName& pathname,"
"streamFormat format=ASCII,"
"versionNumber version=currentVersion) : "
"couldn't open File for input\n"
"in stream " << info() << Foam::endl;
}
setBad();
}
else
{
setOpened();
}
lineNumber_ = 1;
}
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
OFstream::~OFstream()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void OFstream::print(Ostream& os) const
{
// Print File data
os << " OFstream: ";
OSstream::print(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment