Subversion Repositories Kolibri OS

Rev

Rev 5977 | Rev 6738 | 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;
5965 leency 16
	dword element_offset[4090];
17
	int add();
5959 leency 18
	dword get();
19
	void drop();
5965 leency 20
	void increase_data_size();
5959 leency 21
};
22
 
5965 leency 23
void collection::increase_data_size() {
24
	int filled_size;
25
	if (realloc_size<4096) realloc_size = 4096;
26
	if (!data_size) {
27
		data_size = realloc_size;
28
		data_start = malloc(realloc_size);
29
	}
30
	else {
31
		data_size = data_size + realloc_size;
32
		data_start = realloc(data_start, data_size);
33
	}
5959 leency 34
}
35
 
5965 leency 36
int collection::add(dword in) {
37
	if (count >= 4090) return 0;
5974 leency 38
	if (element_offset[count]+strlen(in)+2 > data_size) {
5965 leency 39
		increase_data_size();
40
		add(in);
41
		return;
42
	}
5974 leency 43
	strcpy(data_start+element_offset[count], in);
5959 leency 44
	count++;
5974 leency 45
	element_offset[count] = element_offset[count-1] + strlen(in) + 1;
5965 leency 46
	return 1;
5959 leency 47
}
48
 
49
dword collection::get(dword pos) {
5974 leency 50
	if (pos<0) || (pos>=count) return 0;
5965 leency 51
	return data_start + element_offset[pos];
5959 leency 52
}
53
 
54
void collection::drop() {
5965 leency 55
	if (data_start) free(data_start);
5974 leency 56
	data_size = data_start = element_offset[count] = count = 0;
5959 leency 57
}
58
 
6285 leency 59
 
60
/*========================================================
61
=                                                        =
62
=                       Integer                          =
63
=                                                        =
64
========================================================*/
65
 
66
struct collection_int
67
{
68
	int count;
69
	dword element[4096*3];
70
	int add();
71
	dword get();
72
	void drop();
73
};
74
 
75
int collection_int::add(dword in) {
76
	if (count >= 4096*3) return 0;
77
	element[count] = in;
78
	count++;
79
	return 1;
80
}
81
 
82
dword collection_int::get(dword pos) {
83
	if (pos<0) || (pos>=count) return 0;
84
	return element[pos];
85
}
86
 
87
void collection_int::drop() {
88
	element[0] =
89
	count = 0;
90
}
91
 
5959 leency 92
#endif