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