00001
00002
00003
00004
00005
00006
00007 #ifndef MCFSBOSTREAM_H
00008 #define MCFSBOSTREAM_H
00009
00010 #ifdef USE_STD
00011 #include <iostream>
00012 #include <string>
00013 using namespace std;
00014 #else
00015 #include <iostream.h>
00016 #include <string.h>
00017 #endif
00018
00019 #include "utility.h"
00020 #include "MCFmp.h"
00021 #include "MCF_Code.h"
00022
00023 #include "MCFsbostreamBase.h"
00024
00025 template < class Rtmra_t >
00026 class MCFsbostream : public MCFsbostreamBase
00027 {
00028 public:
00029 typedef typename Rtmra_t::DataType Data_t;
00030 MCFsbostream( const string& descript = "_", ostream& os = cout );
00031 ~MCFsbostream() {}
00032 virtual void final( Rtmra_t& );
00033 MCFsbostream<Rtmra_t>& operator << ( Rtmra_t& );
00034 void threshold( const Data_t threshold );
00035 protected:
00036 Data_t _threshold;
00037 };
00038
00039 template <class Rtmra_t>
00040 MCFsbostream<Rtmra_t>::MCFsbostream( const string& descript, ostream& os)
00041 : MCFsbostreamBase( descript, os ), _threshold(0)
00042 {
00043 _arraydim = Rtmra_t::ArrayDim;
00044 _datatype_code = DataType_Code<Data_t>::eval();
00045 }
00046
00047 template <class Rtmra_t>
00048 void MCFsbostream<Rtmra_t>:: final( Rtmra_t& x )
00049 {
00050 bool eob = ( x.mcycle() == x.mmax() );
00051 _lockfinalstep = true;
00052 while ( !eob ) {
00053
00054 x.assign( typename Rtmra_t::DataType(0) );
00055 x++;
00056 (*this) << x;
00057 eob = ( x.mcycle() == x.mmax() );
00058 }
00059 }
00060
00061 template <class Rtmra_t>
00062 MCFsbostream<Rtmra_t>& MCFsbostream<Rtmra_t>::operator << ( Rtmra_t& x )
00063 {
00064
00065 MCFmp<Rtmra_t> mp( _bplen_mpsizeb, _bplen_coef, _bplen_n, _bplen_a );
00066 mp.threshold(_threshold);
00067
00068 if ( !isopen() ) open();
00069
00070 if ( isopen() ) {
00071 if ( _needheader ) outheader();
00072 int m = x.mcycle();
00073 bool eob = ( m == x.mmax() );
00074 if (eob) {
00075 (*_os) << mp( x, char(m) );
00076 }
00077 while ( m != 0 ) {
00078 (*_os) << mp( x, char(0x80|m) );
00079 m--;
00080 }
00081
00082 if ( !_lockfinalstep ) {
00083
00084 _finalstep = x.mrastep() & ( ( 1 << x.mmax() ) - 1 );
00085 #ifdef STORM_DEBUG
00086 cout << "locked with _finalstep = " << _finalstep << endl;
00087 #endif
00088 }
00089 if (eob) {
00090 close();
00091 _sbn++;
00092 _needheader = true;
00093 }
00094 }
00095 return *this;
00096 }
00097
00098 template <class Rtmra_t>
00099 void MCFsbostream<Rtmra_t>::threshold ( const Data_t threshold )
00100 {
00101 _threshold = threshold;
00102 }
00103
00104 #endif
00105