Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "OFstream.H"
00027 #include <OpenFOAM/OSspecific.H>
00028 #include <OpenFOAM/gzstream.h>
00029
00030
00031
00032 defineTypeNameAndDebug(Foam::OFstream, 0);
00033
00034
00035
00036
00037 Foam::OFstreamAllocator::OFstreamAllocator
00038 (
00039 const fileName& pathname,
00040 IOstream::compressionType compression
00041 )
00042 :
00043 ofPtr_(NULL)
00044 {
00045 if (pathname.empty())
00046 {
00047 if (OFstream::debug)
00048 {
00049 Info<< "OFstreamAllocator::OFstreamAllocator(const fileName&) : "
00050 "cannot open null file " << endl;
00051 }
00052 }
00053
00054 if (compression == IOstream::COMPRESSED)
00055 {
00056
00057 if (isFile(pathname, false))
00058 {
00059 rm(pathname);
00060 }
00061
00062 ofPtr_ = new ogzstream((pathname + ".gz").c_str());
00063 }
00064 else
00065 {
00066
00067 if (isFile(pathname + ".gz", false))
00068 {
00069 rm(pathname + ".gz");
00070 }
00071
00072 ofPtr_ = new ofstream(pathname.c_str());
00073 }
00074 }
00075
00076
00077 Foam::OFstreamAllocator::~OFstreamAllocator()
00078 {
00079 delete ofPtr_;
00080 }
00081
00082
00083 std::ostream& Foam::OFstreamAllocator::stdStream()
00084 {
00085 if (!ofPtr_)
00086 {
00087 FatalErrorIn("OFstreamAllocator::stdStream()")
00088 << "No stream allocated." << abort(FatalError);
00089 }
00090 return *ofPtr_;
00091 }
00092
00093
00094
00095
00096 Foam::OFstream::OFstream
00097 (
00098 const fileName& pathname,
00099 streamFormat format,
00100 versionNumber version,
00101 compressionType compression
00102 )
00103 :
00104 OFstreamAllocator(pathname, compression),
00105 OSstream(*ofPtr_, "OFstream.sinkFile_", format, version, compression),
00106 pathname_(pathname)
00107 {
00108 setClosed();
00109 setState(ofPtr_->rdstate());
00110
00111 if (!good())
00112 {
00113 if (debug)
00114 {
00115 Info<< "IFstream::IFstream(const fileName&,"
00116 "streamFormat format=ASCII,"
00117 "versionNumber version=currentVersion) : "
00118 "could not open file for input\n"
00119 "in stream " << info() << Foam::endl;
00120 }
00121
00122 setBad();
00123 }
00124 else
00125 {
00126 setOpened();
00127 }
00128
00129 lineNumber_ = 1;
00130 }
00131
00132
00133
00134
00135 Foam::OFstream::~OFstream()
00136 {}
00137
00138
00139
00140
00141 void Foam::OFstream::print(Ostream& os) const
00142 {
00143 os << " OFstream: ";
00144 OSstream::print(os);
00145 }
00146
00147
00148