00001
00002
00003
00004
00005
00006
00007 #ifndef DCFSBOSTREAM_H
00008 #define DCFSBOSTREAM_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 "DCFutility.h"
00020 #include "DCFencode.h"
00021 #include "DCFmpacket.h"
00022
00023 #include "DCFsbostreamBase.h"
00024
00025 template < class Data_t >
00026 class DCFsbostream : public DCFsbostreamBase
00027 {
00028 public:
00029 DCFsbostream( const string& = "_\0", ostream& = cout );
00030 virtual void close();
00031 virtual void final( Data_t& );
00032 DCFsbostream<Data_t>& operator << ( Data_t& );
00033 void descr( ostream& os = cout );
00034 virtual void outheader();
00035
00036 public:
00037 DCFencode<Data_t> _enc;
00038 };
00039
00040 template <class Data_t>
00041 DCFsbostream<Data_t>::DCFsbostream( const string& descript, ostream& os )
00042 : DCFsbostreamBase( descript, os )
00043 {
00044 _enctype = _enc.enctype();
00045 _encsizeb = _enc.encsizeb();
00046 };
00047
00048 template <class Data_t>
00049 void DCFsbostream<Data_t>:: close()
00050 {
00051 if ( isopen() ) {
00052 bytepack bp;
00053 (*_os) << bp( 0, _bplen_sizeb );
00054 (*_os) << bp( _finalstep, _bplen_n );
00055 (*_os) << endl;
00056 }
00057 };
00058
00059 template <class Data_t>
00060 void DCFsbostream<Data_t>:: final( Data_t& x )
00061 {
00062 bool eob = ( x.mcycle() == x.mmax() );
00063 _lockfinalstep = true;
00064 while ( !eob ) {
00065 x.assign( 0.0 );
00066 x++;
00067 (*this) << x;
00068 eob = ( x.mcycle() == x.mmax() );
00069 }
00070 };
00071
00072 template <class Data_t>
00073 DCFsbostream<Data_t>& DCFsbostream<Data_t>::operator << ( Data_t& x )
00074 {
00075
00076 DCFmpacket<Data_t> mp(DCF_DEFAULT_MPACKET,
00077 _bplen_sizeb, _bplen_n, _enc);
00078
00079 if ( !isopen() ) open();
00080
00081 if ( isopen() ) {
00082 if ( _needheader ) outheader();
00083 int m = x.mcycle();
00084 bool eob = ( m == x.mmax() );
00085 if (eob) {
00086 (*_os) << mp( x, char(m) );
00087 }
00088 while (m) {
00089 (*_os) << mp(x,char(0x80|m));
00090 m--;
00091 }
00092 if ( !_lockfinalstep ) {
00093 _finalstep = x.mrastep() & ( ( 1 << _mmax ) - 1 );
00094 }
00095 if (eob) {
00096 close();
00097 _blocknum++;
00098 _needheader = true;
00099 }
00100 }
00101 return *this;
00102 };
00103
00104 template <class Data_t>
00105 void DCFsbostream<Data_t>::descr( ostream& os = cout )
00106 {
00107 DCFsbostreamBase::descr(os);
00108 _enc.descr(os);
00109 };
00110
00111 template <class Data_t>
00112 void DCFsbostream<Data_t>::outheader()
00113 {
00114 DCFsbostreamBase::outheader();
00115 (*_os) << _enc;
00116 };
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 #endif
00185