/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
*
* MAUS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MAUS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MAUS. If not, see .
*
*/
#ifndef __MDDATACONTAINER_H
#define __MDDATACONTAINER_H
#include
#include
#include
#include
#include
#include
#include
#include
#include "MDexception.h"
using namespace std;
typedef void (* DataTestCallback)( unsigned long32 );
class MDdataContainer {
protected:
unsigned char* _data;
unsigned int _size;
bool _valid;
DataTestCallback _testCallBack;
public:
MDdataContainer(void *d=0,unsigned int s=1)
:_data((unsigned char*)d),_size(s),_valid(false), _testCallBack(0){}
MDdataContainer( MDdataContainer& dc) {
_data = dc.GetDataPtr();
_size = dc.GetSize();
_valid = dc.IsValid();
}
virtual ~MDdataContainer(){}
unsigned char* GetDataPtr(unsigned int i=0) {
if ( i<_size ) return &_data[i];
else return NULL;
}
uint32_t* Get32bWordPtr(unsigned int i=0) {
if ( (i*4) < _size ) return (uint32_t*)&_data[i*4];
else {
stringstream ss;
ss << "ERROR in MDdataContainer::Get32bWordPtr - the size is exceeded ";
ss << "(i=" << i << " size=" << _size <<").";
throw MDexception(ss.str());
return NULL;
}
}
bool IsValid( void ){ return _valid; }
unsigned int GetSize() {return _size;}
virtual void SetDataPtr( void *d ) {
_data = (unsigned char*)d;
_valid = false;
_size = 1;
}
virtual void SetTest(DataTestCallback funk) {_testCallBack = funk;}
void Validate() { _valid = true;}
void UnValidate() { _valid = false;}
void SetSize(unsigned int s) {_size = s;}
virtual void Dump(int atTheTime=1){
if (_size%4) cerr << " Not 32 bits data !! Trying to ignore " ;
unsigned int ibyte(0),iword;
unsigned int nword=_size>>2;
for (iword=0 ; iword < nword ; ++iword) {
if ( iword%atTheTime == 0 ) cout << dec << setfill(' ') << setw(9)<< iword*4 << ") " ;
cout << noshowbase << hex ;
cout << setfill('0') << setw(8)
<< *Get32bWordPtr(iword) << " (" ;
for ( ibyte=0; ibyte<4; ++ibyte) {
if ( isprint( _data[iword*4+ibyte]) ) cout << _data[iword*4+ibyte];
else cout << ".";
}
cout << ") " ;
if ( (iword+1)%atTheTime == 0 ) cout << endl;
}
for ( ibyte=0; ibyte<_size%4; ++ibyte) {
if ( isprint( _data[nword*4+ibyte]) )
cout << _data[nword*4+ibyte] ;
else cout << ".";
}
if ( ibyte ) cout << endl;
else if ( iword%atTheTime ) cout << endl;
cout << dec << noshowbase << setfill(' ') ;
}
};
#endif