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
|
#ifndef __DATABASE_H__
#define __DATABASE_H__
#include "database-types.h"
#include "database-segment.h"
#include "database-internal.h"
class Database : public Base {
public:
Database() : start(0), end(0), currentId(1) { }
~Database() { while(start) delete start; }
DatabaseCell * getStart() { return start; }
DatabaseCell * getEnd() { return end; }
void setStart(DatabaseCell * newStart) { start = newStart; }
void setEnd(DatabaseCell * newEnd) { end = newEnd; }
Segment * getSegment(Uint32 id) {
// TODO: have a hash table.
DatabaseCell * cursor;
for (cursor = start; start; cursor = cursor->getNext())
if (cursor->getId() == id)
return cursor->getSegment();
return 0;
}
Uint32 GetNextSegId() { return currentId++; }
Segment * CreateSegment(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size = 0, const Byte * data = 0) {
DatabaseCell * r = new DatabaseCell(this, cpu, cpu_base, origin, size, extra_size, data);
return r->getSegment();
}
void Serialize(Handle * out);
void Deserialize(Handle *in);
private:
DatabaseCell * start, * end;
Uint32 currentId;
};
#endif
|