Subversion Repositories Kolibri OS

Rev

Rev 7043 | Rev 7286 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5959 leency 1
#ifndef INCLUDE_COLLECTION_H
2
#define INCLUDE_COLLECTION_H
3
#print "[include ]\n"
4
 
6285 leency 5
/*========================================================
6
=                                                        =
7
=                       String                           =
8
=                                                        =
9
========================================================*/
10
 
5959 leency 11
struct collection
12
{
5965 leency 13
	int realloc_size, count;
14
	dword data_start;
5959 leency 15
	dword data_size;
7049 leency 16
	dword element_offset[4000];
5965 leency 17
	int add();
7049 leency 18
	int addn();
5959 leency 19
	dword get();
20
	void drop();
5965 leency 21
	void increase_data_size();
5959 leency 22
};
23
 
5965 leency 24
void collection::increase_data_size() {
25
	int filled_size;
26
	if (realloc_size<4096) realloc_size = 4096;
27
	if (!data_size) {
28
		data_size = realloc_size;
29
		data_start = malloc(realloc_size);
30
	}
31
	else {
32
		data_size = data_size + realloc_size;
33
		data_start = realloc(data_start, data_size);
34
	}
5959 leency 35
}
36
 
5965 leency 37
int collection::add(dword in) {
7049 leency 38
	return addn(in, strlen(in));
39
}
40
 
41
int collection::addn(dword in, len) {
42
	if (count >= 4000) return 0;
43
	if (element_offset[count]+len+2 > data_size) {
5965 leency 44
		increase_data_size();
7049 leency 45
		addn(in, len);
46
		return 1;
5965 leency 47
	}
7049 leency 48
	strncpy(data_start+element_offset[count], in, len);
5959 leency 49
	count++;
7049 leency 50
	element_offset[count] = element_offset[count-1] + len + 1;
5965 leency 51
	return 1;
5959 leency 52
}
53
 
54
dword collection::get(dword pos) {
5974 leency 55
	if (pos<0) || (pos>=count) return 0;
5965 leency 56
	return data_start + element_offset[pos];
5959 leency 57
}
58
 
59
void collection::drop() {
5965 leency 60
	if (data_start) free(data_start);
5974 leency 61
	data_size = data_start = element_offset[count] = count = 0;
5959 leency 62
}
63
 
6285 leency 64
 
65
/*========================================================
66
=                                                        =
67
=                       Integer                          =
68
=                                                        =
69
========================================================*/
70
 
7043 leency 71
struct collection_int
6285 leency 72
{
73
	int count;
74
	dword element[4096*3];
75
	int add();
76
	dword get();
77
	void drop();
78
};
79
 
7043 leency 80
int collection_int::add(dword in) {
6285 leency 81
	if (count >= 4096*3) return 0;
82
	element[count] = in;
83
	count++;
84
	return 1;
85
}
86
 
7043 leency 87
dword collection_int::get(dword pos) {
6285 leency 88
	if (pos<0) || (pos>=count) return 0;
89
	return element[pos];
90
}
91
 
7043 leency 92
void collection_int::drop() {
6285 leency 93
	element[0] =
94
	count = 0;
95
}
96
 
5959 leency 97
#endif