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

MCFmpBase.cpp

Go to the documentation of this file.
00001 // MCFmpBase.cpp
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2001-2002 Brown Deer Technology, LLC.
00004 //                        All rights reserved.
00005 //////////////////////////////////////////////////////////////////////
00006 
00007 #ifdef USE_STD
00008 #include <iostream>
00009 using namespace std;
00010 #else
00011 #include <iostream.h>
00012 #endif
00013 
00014 #include "MCFmpBase.h"
00015 
00016 MCFmpBase::MCFmpBase( 
00017   const int bplen_mpsizeb, const int bplen_coef, 
00018   const int bplen_n, const int bplen_a
00019 ) 
00020   : _arraydim(1),
00021     _bplen_mpsizeb(bplen_mpsizeb), _bplen_coef(bplen_coef),
00022     _bplen_n(bplen_n), _bplen_a(bplen_a),
00023     _mcode(0), _null(1)
00024 {
00025    _n = -1;
00026    _data = new vector<char>;
00027 }
00028 
00029 MCFmpBase::MCFmpBase( 
00030   const int bplen_mpsizeb, const int bplen_coef, 
00031   const int bplen_n
00032 ) 
00033   : _arraydim(0),
00034     _bplen_mpsizeb(bplen_mpsizeb), _bplen_coef(bplen_coef),
00035     _bplen_n(bplen_n),
00036     _mcode(0), _null(1)
00037 {
00038    _n = -1;
00039    _data = new vector<char>;
00040 }
00041 
00042 MCFmpBase::~MCFmpBase() 
00043 { 
00044    if ( _data ) { delete _data; _data = 0; } 
00045 }
00046 
00047 void MCFmpBase::set( 
00048   const int bplen_mpsizeb, const int bplen_coef, 
00049   const int bplen_n, const int bplen_a
00050 )
00051 {
00052    _arraydim = 1;
00053    _bplen_mpsizeb = bplen_mpsizeb;
00054    _bplen_coef = bplen_coef;
00055    _mcode = 0;
00056    _bplen_n = bplen_n;
00057    _bplen_a = bplen_a;
00058    _n = -1;
00059    if ( _data ) { delete _data; _data = 0; } 
00060    _data = new vector<char>;
00061    _null = 1;
00062 }
00063 
00064 void MCFmpBase::set( 
00065   const int bplen_mpsizeb, const int bplen_coef, 
00066   const int bplen_n
00067 )
00068 {
00069    _arraydim = 0;
00070    _bplen_mpsizeb = bplen_mpsizeb;
00071    _bplen_coef = bplen_coef;
00072    _mcode = 0;
00073    _bplen_n = bplen_n;
00074    _n = -1;
00075    if ( _data ) { delete [] _data; _data = 0; } 
00076    _data = new vector<char>;
00077    _null = 1;
00078 }
00079 
00080 int MCFmpBase::mpsizeb() 
00081 {
00082    if ( _null ) return 0;
00083    else return 2*_bplen_mpsizeb + 1 + _bplen_n + (*_data).size();
00084 }
00085 
00086 inline
00087 void MCFmpBase::write( ostream& os ) 
00088 {
00089    bytepack bp;
00090    if ( !empty() && os.good() ) {
00091       os << bp( mpsizeb(), _bplen_mpsizeb );
00092       os << bp( _mcode, 1 );
00093       os << bp( _n, _bplen_n );
00094 //      for( int i = 0; i < (int)(*_data).size(); i++ ) os.put( (*_data)[i] ); 
00095       for( int i = 0; i < (int)_data->size(); i++ ) os.put( (*_data)[i] ); 
00096       os << bp( mpsizeb(), _bplen_mpsizeb );
00097 #ifdef STORM_DEBUG
00098            cout << "MCFmpBase::write(): mpsizeb() " << mpsizeb() << endl;
00099 #endif
00100    }
00101 }
00102 
00103 void MCFmpBase::read( istream& is ) 
00104 {
00105    clear();
00106    if ( is.good() ) {
00107       char c;
00108       bytepack bp;
00109       is >> bp( 0, _bplen_mpsizeb ); int sizeb = int(bp);
00110       if ( sizeb != 0 ) {
00111          _null = 0;
00112          is >> bp(0,1); _mcode = char(bp);
00113          is >> bp( 0, _bplen_n ); _n = int(bp);
00114          for( int i = 0; i < (sizeb - 2*_bplen_mpsizeb - 1 - _bplen_n); i++ ) {
00115             is.get(c); 
00116             push_back(c);
00117          }
00118          is >> bp( 0, _bplen_mpsizeb ); int tmp = int(bp);
00119          if ( tmp != sizeb ) {
00120             _null = 1;
00121 #ifdef STORM_DEBUG
00122             cout << "MCFmpBase::read(istream&): "
00123                  << "ERROR: read inconsistent mpsizeb"
00124                  << sizeb << ' ' << tmp << endl;
00125 #endif
00126          }
00127       }
00128       else { _null = 1; }
00129    }
00130 };
00131 
00132 ostream& operator << (ostream& os, MCFmpBase& mp )
00133 {
00134    mp.write(os);
00135    return os;
00136 };
00137 
00138 istream& operator >> ( istream& is, MCFmpBase& mp ) 
00139 {
00140    mp.read(is);
00141    return is;
00142 };
00143 

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