summaryrefslogtreecommitdiff
path: root/Database/internals/database-references.h
blob: 6ad64bda844b1676ed3fce72258bf6348aa8a961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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