00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#ifndef CTDATACACHE_H
00036
#define CTDATACACHE_H
00037
00038 template <
int SIZE,
int GRANULARITY>
class CHIPCARD_API CTDataCache;
00039
00040
#include <bitset>
00041
#include <string>
00042
using namespace std;
00043
00044
00050 template <
int SIZE,
int GRANULARITY>
class CHIPCARD_API CTDataCache {
00051
private:
00052 bitset<SIZE/GRANULARITY> _valid;
00053 bitset<SIZE/GRANULARITY> _dirty;
00054
char _data[SIZE];
00055
public:
00056 CTDataCache(){ _valid.reset(); _dirty.reset();};
00057 ~
CTDataCache(){
00058
#if DEBUGMODE>0
00059
fprintf(stderr,
"~DataCache\n");
00060
#endif
00061
};
00062
00063 bool isValid(
unsigned int block){
return _valid.test(block);};
00064 bool isDirty(
unsigned int block){
return _dirty.test(block);};
00065 unsigned int granularity(){
return GRANULARITY;};
00066 unsigned int size() {
return SIZE;};
00067 void setAllValid() { _valid.set();};
00068 void setNoneValid() { _valid.reset();};
00069 void setAllDirty() { _dirty.set();};
00070 void setNoneDirty() { _dirty.reset();};
00071 void setData(
const string &d,
unsigned int pos) {
00072 memmove(_data+pos,
00073 d.data(),
00074 d.length());};
00075 string data(
unsigned int pos,
unsigned int s){
00076
return string(_data+pos,s);};
00077
00078 void setValid(
unsigned int block) { _valid.set(block);};
00079 void setInvalid(
unsigned int block) { _valid.reset(block);};
00080 void setDirty(
unsigned int block) { _dirty.set(block);};
00081 void setClean(
unsigned int block) { _dirty.reset(block);};
00082 };
00083
00084
00085
#endif
00086
00087
00088