aboutsummaryrefslogtreecommitdiff
path: root/enginedata.h
blob: 0b6b47213f6cf841cb7e5ac21b4f16d5e338cf97 (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
63
64
65
66
67
68
#pragma once

#include <string>
#include <map>
#include <list>

using namespace std;

struct RowItem;
struct Row;
struct ColHeader;
struct Table;

struct RowItem{
	union{
		int32_t rh_int32;
		uint32_t rh_uint32;
		unsigned char *rh_bytes;
	} v;
	RowItem copy(const ColHeader&);
};

enum ColHeaderType{
	RH_INT32,
	RH_UINT32,
	RH_BYTES //takes length argument
};
struct ColHeader{
	ColHeaderType type;
	int arg;
};

struct Row{
	int nc;
	Table *table; //pointer to the parent table; don't delete!
	RowItem *items;

	Row(void);
	Row(const int _nc,Table *_t);
	~Row(void);
	Row(Row &&other); //move constr
	Row(const Row &other); //copy constr
	Row& operator=(const Row &other); //copy assignment

	friend ostream& operator<<(ostream &os,const Row &r);
};

struct Table{
	const string name;
	const int nc;
	ColHeader *header;
	map<string,Row> rows; //map key is serialised version of the first column

	Table(const string &_n,const int _nc,const ColHeader *const _hd); //copies from _hd, so you can freely delete or edit the passed colheader array
	~Table(void);
	Table(const Table &other);
	Table(Table &&other);
};

string serialise(const ColHeader &header,const RowItem &rowitem);
string serialise(int32_t v);
string serialise(uint32_t v);
string serialise(unsigned char *v,int len);

int riCompare(const ColHeader &header,const RowItem &ri1,const RowItem &ri2);
int riCompare(int32_t v1,int32_t v2);
int riCompare(uint32_t v1,uint32_t v2);
int riCompare(unsigned char *v1,unsigned char *v2,int len);