aboutsummaryrefslogtreecommitdiff
path: root/Src/nde/android/IndexField.cpp
blob: faf3cb4916e8c762e2f7538f4106fdd60222587c (plain) (blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ---------------------------------------------------------------------------
Nullsoft Database Engine
--------------------
codename: Near Death Experience
--------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------

IndexField Class
Android (linux) implementation

Field data layout
[4 bytes] Position
[4 bytes] Data Type
[1 byte] Name Length
[Name Length bytes] Name (UTF-8)
--------------------------------------------------------------------------- */

#include "../nde.h"
#include "../ndestring.h"
//---------------------------------------------------------------------------
IndexField::IndexField(unsigned char id, int Pos, int type, const char *FieldName)
{
	InitField();
	Type = FIELD_INDEX;
	Name = ndestring_wcsdup(FieldName);
	ID = id;
	Position = Pos;
	DataType = type;
}

//---------------------------------------------------------------------------
void IndexField::InitField(void)
{
	index = 0;
	Type = FIELD_INDEX;
	Name = NULL;
	ID = 0;
	Position = -1;
	DataType = FIELD_UNKNOWN;
}

//---------------------------------------------------------------------------
IndexField::IndexField()
{
	InitField();
}

//---------------------------------------------------------------------------
IndexField::~IndexField()
{
	ndestring_release(Name);
	delete index;
}

//---------------------------------------------------------------------------
void IndexField::ReadTypedData(const uint8_t *data, size_t len)
{
	unsigned char c;
	int pos=0;
	CHECK_INT(len);
	Position = GET_INT(); pos += 4;
	CHECK_INT(len);
	DataType = GET_INT(); pos += 4;
	CHECK_CHAR(len);
	c = GET_CHAR(); pos++;
	if (c)
	{
		CHECK_BIN(len, c);
		Name = ndestring_wcsndup((const char *)(data+pos), c);
	}
}

//---------------------------------------------------------------------------
void IndexField::WriteTypedData(uint8_t *data, size_t len)
{
	int pos=0;
	CHECK_INT(len);
	PUT_INT(Position); pos += 4;

	CHECK_INT(len);
	PUT_INT(DataType); pos += 4;
	CHECK_CHAR(len);
	
	CHECK_CHAR(len);

	if (Name) 
	{
		int string_length = strlen(Name);
		if (string_length)
		{
			PUT_CHAR(string_length);
			pos++;

			CHECK_BIN(len, string_length);
			PUT_BINARY(data, (const uint8_t *)Name, string_length, pos);
		}
		else
		{
			PUT_CHAR(0);
		}
	}
	else
	{
		PUT_CHAR(0);
	}
}

//---------------------------------------------------------------------------

char *IndexField::GetIndexName(void)
{
	return Name;
}

//---------------------------------------------------------------------------
size_t IndexField::GetDataSize(void)
{
	size_t s=9;
	if (Name)
	{
		s+=strlen(Name);
	}
	s++;
	return s;
}

//---------------------------------------------------------------------------
int IndexField::Compare(Field * /*Entry*/)
{
	return 0;
}

//---------------------------------------------------------------------------
int IndexField::TranslateToIndex(int Id, IndexField *toindex)
{
	if (index && toindex && toindex->index)
		return index->TranslateIndex(Id, toindex->index);
	return -1;
}