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

MRAmpEncode.h

Go to the documentation of this file.
00001 // MRAmpEncode.h
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2002 Brown Deer Technology, LLC.
00004 //                        All rights reserved.
00005 //////////////////////////////////////////////////////////////////////
00006 
00007 #ifndef MRAMPENCODE_H
00008 #define MRAMPENCODE_H
00009 
00010 #ifdef USE_STD
00011 #include <iostream>
00012 using namespace std;
00013 #else
00014 #include <iostream.h>
00015 #endif
00016 
00017 #include "BufferBase.h"
00018 
00019 #ifndef MRA_MAXDIM
00020 #define MRA_MAXDIM 4
00021 #endif
00022 
00023 class MRAsbEncode;
00024 
00025 class MRAmpEncode
00026 {
00027    public:
00028 
00029       MRAmpEncode();
00030       MRAmpEncode( const MRAmpEncode& );
00031       MRAmpEncode(
00032          int grid_dim, int array_dim = 0,
00033          int bplen_mpsizeb = 0, int bplen_coef = 0,
00034          int bplen_n = 0, int bplen_a = 0
00035       );
00036       MRAmpEncode(
00037          int grid_dim, int array_dim,
00038          int bplen_mpsizeb, int bplen_coef,
00039          const int* bplen_n, const int* bplen_a
00040       );
00041 
00042       MRAmpEncode& copy( const MRAmpEncode& );
00043       MRAmpEncode& operator = ( const MRAmpEncode& );
00044 
00045       MRAmpEncode& operator () ();
00046       MRAmpEncode& operator () ( const MRAmpEncode& );
00047       MRAmpEncode& operator () (
00048          int grid_dim, int array_dim = 0,
00049          int bplen_mpsizeb = 0, int bplen_coef = 0,
00050          int bplen_n = 0, int bplen_a = 0
00051       );
00052       MRAmpEncode& operator () (
00053          int grid_dim, int array_dim,
00054          int bplen_mpsizeb, int bplen_coef,
00055          const int* bplen_n, const int* bplen_a
00056       );
00057 
00058       bool is_equal( const MRAmpEncode& );
00059       bool operator == ( const MRAmpEncode& );
00060       bool operator != ( const MRAmpEncode& );
00061 
00062       MRAmpEncode& set_null();
00063       bool is_null();
00064       bool operator ! ();
00065 
00066       void write( BufferBase& );
00067       MRAmpEncode& operator << ( BufferBase& );
00068       void read( BufferBase& );
00069       MRAmpEncode& operator >> ( BufferBase& );
00070 
00071       void write( istream& );
00072       MRAmpEncode& operator << ( istream& );
00073       void read( ostream& );
00074       MRAmpEncode& operator >> ( ostream& );
00075 
00076       int grid_dim();
00077       int array_dim();
00078       int bplen_mpsizeb();
00079       int bplen_coef();
00080       int* bplen_n();
00081       int bplen_n( int d );
00082       int* bplen_a();
00083       int bplen_a( int d );
00084 
00085       virtual int sizeb();
00086 
00087       void report( ostream& = cout );
00088 
00089    protected:
00090 
00091       int _grid_dim;
00092       int _array_dim;
00093       int _bplen_mpsizeb;
00094       int _bplen_coef;
00095       int _bplen_n[MRA_MAXDIM];
00096       int _bplen_a[MRA_MAXDIM];
00097 
00098    private:
00099       void synchronize() {}
00100 
00101    friend class MRAsbEncode; 
00102 
00103    friend BufferBase& operator << ( BufferBase&, MRAmpEncode& );
00104 
00105    friend BufferBase& operator >> ( BufferBase&, MRAmpEncode& );
00106 
00107    friend ostream& operator << ( ostream&, MRAmpEncode& );
00108 
00109    friend istream& operator >> ( istream&, MRAmpEncode& );
00110 
00111 };
00112 
00113 inline
00114 MRAmpEncode::MRAmpEncode() { set_null(); } 
00115 
00116 inline
00117 MRAmpEncode::MRAmpEncode( const MRAmpEncode& mpenc )
00118   : _grid_dim(mpenc._grid_dim), _array_dim(mpenc._array_dim), 
00119     _bplen_mpsizeb(mpenc._bplen_mpsizeb), _bplen_coef(mpenc._bplen_coef)
00120 {
00121    for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = mpenc._bplen_n[d];
00122    for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = mpenc._bplen_a[d];
00123 }
00124 
00125 inline
00126 MRAmpEncode::MRAmpEncode(
00127   int grid_dim, int array_dim,
00128   int bplen_mpsizeb, int bplen_coef,
00129   int bplen_n, int bplen_a
00130 )
00131   : _grid_dim(grid_dim), _array_dim(array_dim), 
00132     _bplen_mpsizeb(bplen_mpsizeb), _bplen_coef(bplen_coef)
00133 {
00134    for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = bplen_n;
00135    for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = bplen_a;
00136 }
00137 
00138 inline
00139 MRAmpEncode::MRAmpEncode(
00140   int grid_dim, int array_dim,
00141   int bplen_mpsizeb, int bplen_coef,
00142   const int* bplen_n, const int* bplen_a
00143 )
00144   : _grid_dim(grid_dim), _array_dim(array_dim), 
00145     _bplen_mpsizeb(bplen_mpsizeb), _bplen_coef(bplen_coef)
00146 {
00147    for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = bplen_n[d];
00148    for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = bplen_a[d];
00149 }
00150 
00151 inline
00152 MRAmpEncode& MRAmpEncode::copy( const MRAmpEncode& mpenc )
00153 {
00154    if ( this != &mpenc ) {
00155       _grid_dim = mpenc._grid_dim;
00156       _array_dim = mpenc._array_dim;
00157       _bplen_mpsizeb = mpenc._bplen_mpsizeb;
00158       _bplen_coef = mpenc._bplen_coef;
00159       for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = mpenc._bplen_n[d];
00160       for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = mpenc._bplen_a[d];
00161    }
00162    return *this;
00163 }
00164 
00165 inline
00166 MRAmpEncode& MRAmpEncode::operator = ( const MRAmpEncode& rhs ) 
00167 {
00168    return copy(rhs); 
00169 }
00170 
00171 inline
00172 MRAmpEncode& MRAmpEncode::operator () () { return set_null(); }
00173 
00174 inline
00175 MRAmpEncode& MRAmpEncode::operator () ( const MRAmpEncode& mpenc )
00176 { 
00177    return copy(mpenc);
00178 }
00179 
00180 inline
00181 MRAmpEncode& MRAmpEncode::operator () (
00182   int grid_dim, int array_dim,
00183   int bplen_mpsizeb, int bplen_coef,
00184   int bplen_n, int bplen_a
00185 )
00186 {
00187    _grid_dim = grid_dim;
00188    _array_dim = array_dim;
00189    _bplen_mpsizeb = bplen_mpsizeb;
00190    _bplen_coef = bplen_coef;
00191    for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = bplen_n;
00192    for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = bplen_a;
00193    return *this;
00194 }
00195 
00196 inline
00197 MRAmpEncode& MRAmpEncode::operator () (
00198   int grid_dim, int array_dim,
00199   int bplen_mpsizeb, int bplen_coef,
00200   const int* bplen_n, const int* bplen_a
00201 )
00202 {
00203    _grid_dim = grid_dim;
00204    _array_dim = array_dim;
00205    _bplen_mpsizeb = bplen_mpsizeb;
00206    _bplen_coef = bplen_coef;
00207    for( int d = 0; d < _grid_dim; ++d ) _bplen_n[d] = bplen_n[d];
00208    for( int d = 0; d < _array_dim; ++d ) _bplen_a[d] = bplen_a[d];
00209    return *this;
00210 }
00211 
00212 inline
00213 bool MRAmpEncode::is_equal( 
00214   const MRAmpEncode& mpenc
00215 )
00216 {
00217    if ( this != &mpenc ) {
00218       if ( _grid_dim != mpenc._grid_dim ) return false;
00219       if ( _array_dim != mpenc._array_dim ) return false;
00220       if ( _bplen_mpsizeb != mpenc._bplen_mpsizeb ) return false;
00221       if ( _bplen_coef != mpenc._bplen_coef ) return false;
00222       for( int d = 0; d < _grid_dim; ++d ) 
00223          if ( _bplen_n[d] != mpenc._bplen_n[d] ) return false;
00224       for( int d = 0; d < _array_dim; ++d ) 
00225          if ( _bplen_a[d] != mpenc._bplen_a[d] ) return false;
00226    } 
00227    return true;
00228 }
00229 
00230 inline
00231 bool MRAmpEncode::operator == ( const MRAmpEncode& rhs ) 
00232 { 
00233    return is_equal(rhs); 
00234 }
00235 
00236 inline
00237 bool MRAmpEncode::operator != ( const MRAmpEncode& rhs ) 
00238 { 
00239    return !is_equal(rhs); 
00240 }
00241 
00242 inline
00243 MRAmpEncode& MRAmpEncode::set_null() 
00244 {
00245    _grid_dim = 0;
00246    _array_dim = 0;
00247    _bplen_mpsizeb = 0;
00248    _bplen_coef = 0;
00249    return *this;
00250 }
00251 
00252 inline
00253 bool MRAmpEncode::is_null() { return ( _grid_dim == 0); }
00254 
00255 inline
00256 bool MRAmpEncode::operator ! () { return is_null(); }
00257 
00258 inline
00259 void MRAmpEncode::write( BufferBase& buffer )
00260 {
00261    bytepack bp;
00262    buffer >> bp(0,1); _grid_dim = int(bp);
00263    buffer >> bp(0,1); _array_dim = int(bp);
00264    buffer >> bp(0,1); _bplen_mpsizeb = int(bp);
00265    buffer >> bp(0,1); _bplen_coef = int(bp);
00266    for( int d = 0; d < _grid_dim; ++d ) {
00267       buffer >> bp(0,1); _bplen_n[d]= int(bp);
00268    }
00269    for( int d = 0; d < _array_dim; ++d ) {
00270       buffer >> bp(0,1); _bplen_a[d]= int(bp);
00271    }
00272    synchronize();
00273 }
00274 
00275 inline
00276 MRAmpEncode& MRAmpEncode::operator << ( BufferBase& buffer ) 
00277 {
00278    write(buffer);
00279    return *this;
00280 }
00281 
00282 inline
00283 void MRAmpEncode::read( BufferBase& buffer )
00284 {
00285    bytepack bp;
00286    buffer << bp( _grid_dim, 1 );
00287    buffer << bp( _array_dim, 1 );
00288    buffer << bp( _bplen_mpsizeb, 1 );
00289    buffer << bp( _bplen_coef, 1 );
00290    for( int d = 0; d < _grid_dim; ++d ) {
00291       buffer << bp( _bplen_n[d], 1 );
00292    }
00293    for( int d = 0; d < _array_dim; ++d ) {
00294       buffer << bp( _bplen_a[d], 1 );
00295    }
00296 }
00297 
00298 inline
00299 MRAmpEncode& MRAmpEncode::operator >> ( BufferBase& buffer ) 
00300 {
00301    read(buffer);
00302    return *this;
00303 }
00304 
00305 inline
00306 void MRAmpEncode::write( istream& is )
00307 {
00308    bytepack bp;
00309    is >> bp(0,1); _grid_dim = int(bp);
00310    is >> bp(0,1); _array_dim = int(bp);
00311    is >> bp(0,1); _bplen_mpsizeb = int(bp);
00312    is >> bp(0,1); _bplen_coef = int(bp);
00313    for( int d = 0; d < _grid_dim; ++d ) {
00314       is >> bp(0,1); _bplen_n[d]= int(bp);
00315    }
00316    for( int d = 0; d < _array_dim; ++d ) {
00317       is >> bp(0,1); _bplen_a[d]= int(bp);
00318    }
00319    synchronize();
00320 }
00321 
00322 inline
00323 MRAmpEncode& MRAmpEncode::operator << ( istream& is ) 
00324 {
00325    write(is);
00326    return *this;
00327 }
00328 
00329 inline
00330 void MRAmpEncode::read( ostream& os )
00331 {
00332    bytepack bp;
00333    os << bp( _grid_dim, 1 );
00334    os << bp( _array_dim, 1 );
00335    os << bp( _bplen_mpsizeb, 1 );
00336    os << bp( _bplen_coef, 1 );
00337    for( int d = 0; d < _grid_dim; ++d ) {
00338       os << bp( _bplen_n[d], 1 );
00339    }
00340    for( int d = 0; d < _array_dim; ++d ) {
00341       os << bp( _bplen_a[d], 1 );
00342    }
00343 }
00344 
00345 inline
00346 MRAmpEncode& MRAmpEncode::operator >> ( ostream& os ) 
00347 {
00348    read(os);
00349    return *this;
00350 }
00351 
00352 inline
00353 int MRAmpEncode::grid_dim() { return _grid_dim; }
00354 
00355 inline
00356 int MRAmpEncode::array_dim() { return _array_dim; }
00357 
00358 inline
00359 int MRAmpEncode::bplen_mpsizeb() { return _bplen_mpsizeb; }
00360 
00361 inline
00362 int MRAmpEncode::bplen_coef() { return _bplen_coef; }
00363 
00364 inline
00365 int MRAmpEncode::bplen_n( int d ) { return _bplen_n[d]; }
00366 
00367 inline
00368 int MRAmpEncode::bplen_a( int d ) { return _bplen_a[d]; }
00369 
00370 inline
00371 int MRAmpEncode::sizeb() { return ( 4 + grid_dim() + array_dim() ); }
00372 
00373 inline
00374 void MRAmpEncode::report( ostream& os ) 
00375 {
00376    os << "MRAmpEncode::report grid_dim=" << grid_dim() << '\n';
00377    os << "MRAmpEncode::report array_dim=" << array_dim() << '\n';
00378    os << "MRAmpEncode::report bplen_mpsizeb=" 
00379       << bplen_mpsizeb() << '\n';
00380    os << "MRAmpEncode::report bplen_coef=" << bplen_coef() << '\n';
00381    for( int d = 0; d < _grid_dim; ++d ) {
00382       os << "MRAmpEncode::report bplen_n[" << d << "]=" 
00383          << bplen_n(d) << '\n';
00384    }
00385    for( int d = 0; d < _array_dim; ++d ) {
00386       os << "MRAmpEncode::report bplen_a[" << d << "]=" 
00387          << bplen_a(d) << '\n';
00388    }
00389 }
00390 
00391 // ##### friends #####
00392 
00393 inline
00394 BufferBase& operator << ( BufferBase& buffer, MRAmpEncode& mp )
00395 {
00396    mp.read(buffer);
00397    return buffer;
00398 }
00399 
00400 inline
00401 BufferBase& operator >> ( BufferBase& buffer, MRAmpEncode& mp )
00402 {
00403    mp.write(buffer);
00404    return buffer;
00405 }
00406 
00407 inline
00408 ostream& operator << ( ostream& os, MRAmpEncode& mp )
00409 {
00410    mp.read(os);
00411    return os;
00412 }
00413 
00414 inline
00415 istream& operator >> ( istream& is, MRAmpEncode& mp )
00416 {
00417    mp.write(is);
00418    return is;
00419 }
00420 
00421 #endif
00422 

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