00001
00002
00003
00004
00005
00006
00007 #ifndef DCFSBOFSTREAM_H
00008 #define DCFSBOFSTREAM_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 "DCFsbostream.h"
00022
00023 template < class Data_t >
00024 class DCFsbofstream : public DCFsbostream<Data_t>
00025 {
00026 public:
00027 DCFsbofstream( const string& = "_\0" );
00028 ~DCFsbofstream();
00029 void filenamebase( const string& );
00030 inline bool isopen();
00031 void open();
00032 void close();
00033 void outheader();
00034 void final( Data_t& x );
00035 void logmessage( string& _message );
00036
00037 private:
00038 int _lenfilenamebase;
00039 string _filenamebase;
00040 string _filenamelog;
00041 string _filenamesb;
00042 ofstream* _ofs;
00043 ofstream* _logofs;
00044 };
00045
00046 template < class Data_t >
00047 DCFsbofstream<Data_t>::DCFsbofstream( const string& descript)
00048 : DCFsbostream<Data_t>( descript, *(_ofs=new ofstream) )
00049 {
00050 _lenfilenamebase = descript.size();
00051 _filenamebase = descript;
00052
00053 if ( _descript != "_\0" ) {
00054 dcflogfilename( _filenamebase, _filenamelog );
00055 _logofs = new ofstream( _filenamelog.c_str() );
00056 (*_logofs) << "DCFLOG" << endl;
00057 (*_logofs) << "DCF CONSTRUCT " << endl;
00058 (*_logofs) << "DCF FILENAMEBASE " << _filenamebase << endl;
00059 }
00060 else {
00061 _logofs = 0;
00062 }
00063 };
00064
00065 template < class Data_t >
00066 DCFsbofstream<Data_t>::~DCFsbofstream()
00067 {
00068 (*_logofs) << "DCF DESTRUCT " << _filenamebase << endl;
00069 (*_logofs) << endl; (*_logofs).close();
00070 delete _ofs; _ofs = 0;
00071 delete _logofs; _logofs = 0;
00072 };
00073
00074 template < class Data_t >
00075 void DCFsbofstream<Data_t>::filenamebase( const string& filenamebase )
00076 {
00077 descript( filenamebase );
00078
00079 _lenfilenamebase = filenamebase.size();
00080 _filenamebase = filenamebase;
00081
00082 delete _logofs; _logofs = 0;
00083
00084 dcflogfilename( _filenamebase, _filenamelog );
00085 _logofs = new ofstream( _filenamelog.c_str() );
00086 (*_logofs) << "DCFLOG" << endl;
00087 (*_logofs) << "DCF FILENAMEBASE " << _filenamebase << endl;
00088 };
00089
00090 template < class Data_t >
00091 inline bool DCFsbofstream<Data_t>::isopen() { return (*_ofs).is_open(); }
00092
00093 template < class Data_t >
00094 void DCFsbofstream<Data_t>::open()
00095 {
00096 bytepack bp;
00097 if (isopen()) close();
00098 dcfsbfilename( _blocknum, _filenamebase, _filenamesb );
00099 (*_ofs).open( _filenamesb.c_str() );
00100 (*_logofs) << "DCF OPEN " << _filenamesb << endl;
00101 #ifdef STORM_DEBUG
00102 cout << "DCFsbofstream.open(): _blocknum _filenamesb "
00103 << _blocknum << ' ' << _filenamesb << '\n';
00104 #endif
00105 };
00106
00107 template < class Data_t >
00108 void DCFsbofstream<Data_t>::close()
00109 {
00110 if ( isopen() ) {
00111 DCFsbostream<Data_t>::close();
00112 (*_ofs).close();
00113 (*_logofs) << "DCF CLOSE " << _filenamesb << endl;
00114 }
00115 };
00116
00117 template < class Data_t >
00118 void DCFsbofstream<Data_t>::outheader()
00119 {
00120 DCFsbostream<Data_t>::outheader();
00121 descr(*_logofs);
00122 };
00123
00124 template < class Data_t >
00125 void DCFsbofstream<Data_t>::final( Data_t& x )
00126 {
00127 (*_logofs) << "DCF FINAL mrastep= " << x.mrastep() << endl;
00128 DCFsbostream<Data_t>::final(x);
00129 (*_ofs) << endl;
00130 (*_ofs).close();
00131 };
00132
00133 template < class Data_t >
00134 void DCFsbofstream<Data_t>::logmessage( string& _message )
00135 {
00136 (*_logofs) << "USR " << _message << endl;
00137 };
00138
00139 #endif
00140