00001
00002
00003
00004
00005
00006
00007 #ifndef MCFSBOFSTREAM_H
00008 #define MCFSBOFSTREAM_H
00009
00010 #ifdef USE_STD
00011 #include <iostream>
00012 #include <fstream>
00013 #include <string>
00014 using namespace std;
00015 #else
00016 #include <iostream.h>
00017 #include <fstream.h>
00018 #include <string.h>
00019 #endif
00020
00021 #include "MCFutility.h"
00022 #include "MCFsbostream.h"
00023
00024 template < class Rtmra_t >
00025 class MCFsbofstream : public MCFsbostream<Rtmra_t>
00026 {
00027 public:
00028
00029 MCFsbofstream( const string& = "_" );
00030 ~MCFsbofstream();
00031
00032 void filenamebase( const string& );
00033
00034 bool isopen();
00035 void open();
00036 void close();
00037 void outheader();
00038 void final( Rtmra_t& x );
00039
00040
00041 void logmessage( string _message );
00042
00043 private:
00044 string _filenamebase;
00045 string _filenamelog;
00046 string _filenamesb;
00047 ofstream* _logofs;
00048 };
00049
00050 template < class Rtmra_t >
00051 MCFsbofstream<Rtmra_t>::MCFsbofstream( const string& descript)
00052 : MCFsbostream<Rtmra_t>( descript, *(new ofstream) )
00053 {
00054 _filenamebase = descript;
00055 if ( descript != "_" ) {
00056 mcflogfilename( _filenamebase, _filenamelog );
00057 _logofs = new ofstream( _filenamelog.c_str() );
00058 (*_logofs) << "MCFLOG" << endl;
00059 (*_logofs) << "MCF CONSTRUCT " << endl;
00060 (*_logofs) << "MCF FILENAMEBASE " << _filenamebase << endl;
00061 }
00062 else { _logofs = 0; }
00063 };
00064
00065 template < class Rtmra_t >
00066 MCFsbofstream<Rtmra_t>::~MCFsbofstream()
00067 {
00068 (*_logofs) << "MCF DESTRUCT " << _filenamebase << endl;
00069 (*_logofs) << endl; (*_logofs).close();
00070 if ( _logofs != 0 ) { delete _logofs; _logofs = 0; }
00071 };
00072
00073 template < class Rtmra_t >
00074 void MCFsbofstream<Rtmra_t>::filenamebase( const string& filenamebase )
00075 {
00076 setdescript( filenamebase );
00077
00078 _filenamebase = filenamebase;
00079
00080 if ( _logofs != 0 ) { delete _logofs; _logofs = 0; }
00081
00082 mcflogfilename( _filenamebase, _filenamelog );
00083 _logofs = new ofstream( _filenamelog.c_str() );
00084 (*_logofs) << "MCFLOG" << endl;
00085 (*_logofs) << "MCF FILENAMEBASE " << _filenamebase << endl;
00086 };
00087
00088 template < class Rtmra_t >
00089 bool MCFsbofstream<Rtmra_t>::isopen()
00090 {
00091 return (*static_cast<ofstream*>(_os)).is_open();
00092 }
00093
00094 template < class Rtmra_t >
00095 void MCFsbofstream<Rtmra_t>::open()
00096 {
00097 bytepack bp;
00098 if (isopen()) close();
00099 mcfsbfilename( _sbn, _filenamebase, _filenamesb );
00100 (*static_cast<ofstream*>(_os)).open( _filenamesb.c_str() );
00101 (*_logofs) << "MCF OPEN " << _filenamesb << endl;
00102 #ifdef STORM_DEBUG
00103 cout << "MCFsbofstream.open(): _sbn _filenamesb "
00104 << _sbn << ' ' << _filenamesb << '\n';
00105 #endif
00106 };
00107
00108 template < class Rtmra_t >
00109 void MCFsbofstream<Rtmra_t>::close()
00110 {
00111 if ( isopen() ) {
00112 MCFsbostreamBase::close();
00113 (*static_cast<ofstream*>(_os)).close();
00114 (*_logofs) << "MCF CLOSE " << _filenamesb << endl;
00115 }
00116 };
00117
00118 template < class Rtmra_t >
00119 void MCFsbofstream<Rtmra_t>::outheader()
00120 {
00121 MCFsbostreamBase::outheader();
00122 report( (*_logofs) );
00123 };
00124
00125 template < class Rtmra_t >
00126 void MCFsbofstream<Rtmra_t>::final( Rtmra_t& x )
00127 {
00128 (*_logofs) << "MCF FINAL mrastep= " << x.mrastep() << endl;
00129 MCFsbostream<Rtmra_t>::final(x);
00130 (*_os) << endl;
00131 (*static_cast<ofstream*>(_os)).close();
00132 };
00133
00134 template < class Rtmra_t >
00135
00136 void MCFsbofstream<Rtmra_t>::logmessage( string _message )
00137 {
00138 (*_logofs) << "USR " << _message << endl;
00139 };
00140
00141 #endif
00142