Subversion Repositories Kolibri OS

Rev

Rev 5959 | Rev 5974 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5959 Rev 5965
Line 2... Line 2...
2
#define INCLUDE_COLLECTION_H
2
#define INCLUDE_COLLECTION_H
3
#print "[include ]\n"
3
#print "[include ]\n"
Line 4... Line 4...
4
 
4
 
5
struct collection
5
struct collection
6
{
6
{
7
	int count;
7
	int realloc_size, count;
-
 
8
	dword data_start;
8
	dword element_offset[4096];
9
	dword data_cur_pos;
9
	dword data_size;
-
 
10
	dword string_data_start;
10
	dword data_size;
11
	dword string_data_cur_pos;
11
	dword element_offset[4090];
12
	void add();
12
	int add();
13
	dword get();
13
	dword get();
14
	void drop();
14
	void drop();
Line 15... Line 15...
15
	void init();
15
	void increase_data_size();
Line 16... Line 16...
16
 
16
 
-
 
17
};
-
 
18
 
17
};
19
void collection::increase_data_size() {
18
 
20
	int filled_size;
19
void collection::init(dword size) {
21
	if (realloc_size<4096) realloc_size = 4096;
-
 
22
	if (!data_size) {
20
	if (data_size) drop();
23
		data_size = realloc_size;
-
 
24
		data_start = malloc(realloc_size);		
-
 
25
	}
-
 
26
	else {
21
	data_size = data_size + size;
27
		data_size = data_size + realloc_size;
Line 22... Line 28...
22
	string_data_cur_pos = string_data_start = malloc(data_size);
28
		data_start = realloc(data_start, data_size);
-
 
29
	}
-
 
30
}
-
 
31
 
-
 
32
int collection::add(dword in) {
-
 
33
	if (count >= 4090) return 0;
-
 
34
	if (data_cur_pos+strlen(in)+2 > data_size) {
23
	count = 0;
35
		increase_data_size();
24
}
36
		add(in);
25
 
37
		return;
26
void collection::add(dword in) {
38
	}
-
 
39
	strcpy(data_start+data_cur_pos, in);
27
	strcpy(string_data_cur_pos, in);
40
	element_offset[count] = data_cur_pos;
Line 28... Line 41...
28
	element_offset[count] = string_data_cur_pos;
41
	data_cur_pos += strlen(in) + 1;
29
	string_data_cur_pos += strlen(in) + 1;
42
	count++;
30
	count++;
43
	return 1;
Line 31... Line 44...
31
}
44
}
32
 
45
 
33
dword collection::get(dword pos) {
-
 
34
	return element_offset[pos];
-
 
35
}
46
dword collection::get(dword pos) {
36
 
-
 
37
void collection::drop() {
47
	return data_start + element_offset[pos];
Line 38... Line 48...
38
	if (string_data_start) free(string_data_start);
48
}
39
	data_size =
49