#ifndef __DATABASE_REFERENCES_H__ #define __DATABASE_REFERENCES_H__ #include "database-segment.h" class RefTo; class Database; /** The reference system, where the database will be able to hold references from and to memory pointers. */ class RefFrom : public Base { public: RefFrom(RefTo * refTo, SegmentRefData * data); ~RefFrom(); SegmentRefData * getRefSegData(); SegmentRefData * getSegRefData() { return data; } RefFrom * getNext() { return next; } private: RefTo * refTo; RefFrom * next, * prev; SegmentRefData * data; }; class RefTo : public Base { public: RefTo(absolute_ptr ptr, SegmentRefData * data, Database *); ~RefTo(); SegmentRefData * getRefSegData(); SegmentRefData * getSegRefData() { return data; } private: RefFrom * refFrom; SegmentRefData * data; }; inline SegmentRefData * RefFrom::getRefSegData() { return refTo->getSegRefData(); } inline SegmentRefData * RefTo::getRefSegData() { return refFrom->getSegRefData(); } class SegmentRefData : public Base { public: SegmentRefData(Uint32 ptr, Segment * seg); ~SegmentRefData(); Uint32 getPtr() { return ptr; } Segment * getSegment() { return seg; } SegmentRefData * getSegmentRefData(Uint32 ptr) { return seg->getSegmentRefData(ptr); } RefTo * getRefTo() { return refTo; } RefFrom * getRefFrom() { return firstRefFrom; } void setRefTo(RefTo * newRefTo) { refTo = newRefTo; checkDestroy(); } void setFirstRefFrom(RefFrom * newFirstRefFrom) { firstRefFrom = newFirstRefFrom; checkDestroy(); } private: RefTo * refTo; RefFrom * firstRefFrom; Uint32 ptr; Segment * seg; void checkDestroy() { if (!refTo && !firstRefFrom) delete this; } }; #endif