Subversion Repositories Kolibri OS

Rev

Rev 6285 | Rev 7043 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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