00001
00002
00003
00004
00005
00006
00007 #ifndef MRASBN_H
00008 #define MRASBN_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 MRAsbn
00024 {
00025 public:
00026
00027 MRAsbn( const MRAsbn& );
00028 explicit MRAsbn( int dim = 0 );
00029
00030 MRAsbn& copy( const MRAsbn& );
00031 MRAsbn& operator = ( const MRAsbn& );
00032 MRAsbn& copy( int sbn );
00033 MRAsbn& operator = ( int sbn );
00034
00035 MRAsbn& operator () ( const MRAsbn& );
00036 MRAsbn& operator () ( int dim = 0 );
00037
00038 int& operator [] ( int d );
00039
00040 bool is_equal( const MRAsbn& rhs );
00041 bool operator == ( const MRAsbn& rhs );
00042 bool operator != ( const MRAsbn& rhs );
00043
00044 void report( ostream& os = cout );
00045
00046 void set_dim(int);
00047 int dim();
00048
00049 int sizeb();
00050
00051 void write( BufferBase& );
00052 MRAsbn& operator << ( BufferBase& );
00053 void read( BufferBase& );
00054 MRAsbn& operator >> ( BufferBase& );
00055
00056 void write( istream& );
00057 void read( ostream& );
00058
00059 private:
00060
00061 int _dim;
00062 int _n[MRA_MAXDIM];
00063
00064 friend BufferBase& operator << ( BufferBase&, MRAsbn& );
00065 friend BufferBase& operator >> ( BufferBase&, MRAsbn& );
00066 friend ostream& operator << ( ostream&, MRAsbn& );
00067 friend istream& operator >> ( istream&, MRAsbn& );
00068
00069 };
00070
00071 inline
00072 MRAsbn::MRAsbn( int dim ) : _dim(dim) {}
00073
00074 inline
00075 MRAsbn::MRAsbn( const MRAsbn& sbn )
00076 : _dim(sbn._dim)
00077 {
00078 for( int d = 0; d < _dim; ++d ) _n[d] = sbn._n[d];
00079 }
00080
00081 inline
00082 MRAsbn& MRAsbn::copy( const MRAsbn& sbn )
00083 {
00084 _dim = sbn._dim;
00085 for( int d = 0; d < _dim; ++d ) _n[d] = sbn._n[d];
00086 return *this;
00087 }
00088
00089 inline
00090 MRAsbn& MRAsbn::operator = ( const MRAsbn& rhs ) { return copy(rhs); }
00091
00092 inline
00093 MRAsbn& MRAsbn::copy( int sbn )
00094 {
00095 for( int d = 0; d < _dim; ++d ) _n[d] = sbn;
00096 return *this;
00097 }
00098
00099 inline
00100 MRAsbn& MRAsbn::operator = ( int rhs ) { return copy(rhs); }
00101
00102 inline
00103 MRAsbn& MRAsbn::operator () ( const MRAsbn& sbn )
00104 {
00105 return copy(sbn);
00106 }
00107
00108 inline
00109 MRAsbn& MRAsbn::operator () ( int dim )
00110 {
00111 _dim = dim;
00112 return *this;
00113 }
00114
00115 inline
00116 int& MRAsbn::operator [] ( int d ) { return _n[d]; }
00117
00118 inline
00119 bool MRAsbn::is_equal( const MRAsbn& rhs )
00120 {
00121 if ( _dim != rhs._dim ) return false;
00122 for( int d = 0; d < _dim; ++d )
00123 if ( _n[d] != rhs._n[d] ) return false;
00124 return true;
00125 }
00126
00127 inline
00128 bool MRAsbn::operator == ( const MRAsbn& rhs ) { return is_equal(rhs); }
00129
00130 inline
00131 bool MRAsbn::operator != ( const MRAsbn& rhs ) { return !is_equal(rhs); }
00132
00133 inline
00134 void MRAsbn::report( ostream& os ) {
00135 os << "MRAsbn::report(){\n";
00136 os << "dim = " << _dim << '\n';
00137 for( int d = 0; d < _dim; ++d ) { os << "n[] = " << _n[d] << '\n'; }
00138 os << "}\n";
00139 }
00140
00141 inline
00142 void MRAsbn::set_dim( int dim ) { _dim = dim; }
00143
00144 inline
00145 int MRAsbn::dim() { return _dim; }
00146
00147 inline
00148 int MRAsbn::sizeb() { return _dim * 4; }
00149
00150 inline
00151 void MRAsbn::write( BufferBase& buffer )
00152 {
00153 bytepack bp;
00154 for( int d = 0; d < _dim; ++d ) {
00155 buffer >> bp( 0, 4 ); _n[d] = int(bp);
00156 }
00157 }
00158
00159 inline
00160 MRAsbn& MRAsbn::operator << ( BufferBase& buffer )
00161 {
00162 write(buffer);
00163 return *this;
00164 }
00165
00166 inline
00167 void MRAsbn::read( BufferBase& buffer )
00168 {
00169 bytepack bp;
00170 for( int d = 0; d < _dim; ++d ) buffer << bp( _n[d], 4 );
00171 }
00172
00173 inline
00174 MRAsbn& MRAsbn::operator >> ( BufferBase& buffer )
00175 {
00176 read(buffer);
00177 return *this;
00178 }
00179
00180 inline
00181 void MRAsbn::write( istream& is )
00182 {
00183 bytepack bp;
00184 for( int d = 0; d < _dim; ++d ) {
00185 is >> bp( 0, 4 ); _n[d] = int(bp);
00186 }
00187 }
00188
00189 inline
00190 void MRAsbn::read( ostream& os )
00191 {
00192 bytepack bp;
00193 for( int d = 0; d < _dim; ++d ) os << bp( _n[d], 4 );
00194 }
00195
00196
00197
00198 inline
00199 BufferBase& operator >> ( BufferBase& buffer, MRAsbn& sbn )
00200 {
00201 sbn.write(buffer);
00202 return buffer;
00203 }
00204
00205 inline
00206 BufferBase& operator << ( BufferBase& buffer, MRAsbn& sbn )
00207 {
00208 sbn.read(buffer);
00209 return buffer;
00210 }
00211
00212 inline
00213 istream& operator >> ( istream& is, MRAsbn& sbn )
00214 {
00215 sbn.write(is);
00216 return is;
00217 }
00218
00219 inline
00220 ostream& operator << ( ostream& os, MRAsbn& sbn )
00221 {
00222 sbn.read(os);
00223 return os;
00224 }
00225
00226 #endif
00227