Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

DCFsbostream.h

Go to the documentation of this file.
00001 // DCFsbostream.h
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2001-2002 Brown Deer Technology, LLC.
00004 //                        All rights reserved.
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 // specialization DCFsbostream<DCF::generic>
00119 
00120 //class DCF { public: typedef void generic; };
00121 
00122 //template <>
00123 //class DCFsbostream< DCF::generic > : public DCFsbostreamBase 
00124 //{
00125 //   public:
00126 //      DCFsbostream( const string& = "_\0", ostream& = cout);
00127 //      virtual void close();
00128 //      virtual void final() {}
00129 //      DCFsbostream<DCF::generic>& operator<<( DCFmpacketBase& );
00130 //      void descr( ostream& os = cout );
00131 //      virtual void outheader();
00132 //
00133 //   public:
00134 //      DCFencode<DCF::generic> _enc;
00135 //};
00136 
00137 //template <>
00138 //DCFsbostream< DCF::generic >::DCFsbostream( 
00139 //  const string& descript,
00140 //  ostream& os
00141 //) 
00142 //  : DCFsbostreamBase( descript, os ) 
00143 //{
00144 //   _enctype = _enc.enctype();
00145 //   _encsizeb = _enc.encsizeb();
00146 //}
00147 
00148 //template <>
00149 //void DCFsbostream< DCF::generic >:: close() 
00150 //{
00151 //   if (isopen()) {
00152 //      bytepack bp;
00153 //      (*_os) << bp( 0, _bplen_sizeb );
00154 //      (*_os) << bp( _finalstep, _bplen_n );
00155 //      (*_os) << endl;
00156 //   }
00157 //}
00158 
00159 //template <>
00160 //DCFsbostream< DCF::generic >& 
00161 //  DCFsbostream< DCF::generic >::operator << ( DCFmpacketBase& mp ) 
00162 //{
00163 //   if ( isopen() ) {
00164 //      if (_needheader) outheader();
00165 //      (*_os) << mp;
00166 //   }
00167 //   return *this;
00168 //}
00169 
00170 //template <>
00171 //void DCFsbostream< DCF::generic >::descr( ostream& os ) 
00172 //{
00173 //   DCFsbostreamBase::descr(os);
00174 //   _enc.descr(os);
00175 //}
00176 
00177 //template <>
00178 //void DCFsbostream< DCF::generic >::void outheader() 
00179 //{
00180 //   DCFsbostreamBase::outheader();
00181 //   (*_os) << _enc;
00182 //}
00183 
00184 #endif
00185 

Generated on Mon May 31 21:38:44 2004 for SR2k4 Assembler by doxygen 1.3.6