00001 00010 #ifndef RPPOINTER_H 00011 #define RPPOINTER_H 00012 #include<assert.h> 00013 #include"mseg.h" 00014 #include<sys/types.h> 00015 00016 namespace RAMS 00017 { 00018 00024 class RPPointer_s 00025 { 00026 protected: 00028 Mseg *seg; 00030 off_t &off; 00031 public: 00035 RPPointer_s(Mseg *s,off_t& o):seg(s),off(o){} 00036 void init(Mseg *s,off_t& o) { seg=s; off=o; } 00037 off_t offset() const { return off; } 00038 00042 int ok() { return off < seg->length(); } 00046 size_t operator-(RPPointer_s a) 00047 { 00048 assert(a.seg->begin()==seg->begin()); 00049 return (off-a.off); 00050 } 00051 00053 void setoff(off_t o) { off=o; } 00057 RPPointer_s& cast(const RPPointer_s &anderer) 00058 { 00059 seg=anderer.seg; 00060 off=anderer.off; 00061 return *this; 00062 } 00063 void *operator=(void *p) 00064 { 00065 off=(char *)p - (char *)(seg->begin()); 00066 assert(ok()); 00067 return p; 00068 } 00069 }; 00070 }; 00071 #endif 00072 00073 00074