2015-12-13 16:28:06 +03:00
|
|
|
#ifndef INCLUDE_COLLECTION_H
|
|
|
|
#define INCLUDE_COLLECTION_H
|
|
|
|
#print "[include <collection.h>]\n"
|
|
|
|
|
2016-02-23 17:41:55 +03:00
|
|
|
/*========================================================
|
|
|
|
= =
|
|
|
|
= String =
|
|
|
|
= =
|
|
|
|
========================================================*/
|
|
|
|
|
2015-12-13 16:28:06 +03:00
|
|
|
struct collection
|
|
|
|
{
|
2015-12-15 19:18:38 +03:00
|
|
|
int realloc_size, count;
|
|
|
|
dword data_start;
|
2015-12-13 16:28:06 +03:00
|
|
|
dword data_size;
|
2017-10-05 01:59:57 +03:00
|
|
|
dword element_offset[4000];
|
2015-12-15 19:18:38 +03:00
|
|
|
int add();
|
2017-10-05 01:59:57 +03:00
|
|
|
int addn();
|
2015-12-13 16:28:06 +03:00
|
|
|
dword get();
|
|
|
|
void drop();
|
2015-12-15 19:18:38 +03:00
|
|
|
void increase_data_size();
|
2015-12-13 16:28:06 +03:00
|
|
|
};
|
|
|
|
|
2015-12-15 19:18:38 +03:00
|
|
|
void collection::increase_data_size() {
|
|
|
|
int filled_size;
|
|
|
|
if (realloc_size<4096) realloc_size = 4096;
|
|
|
|
if (!data_size) {
|
|
|
|
data_size = realloc_size;
|
|
|
|
data_start = malloc(realloc_size);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data_size = data_size + realloc_size;
|
|
|
|
data_start = realloc(data_start, data_size);
|
|
|
|
}
|
2015-12-13 16:28:06 +03:00
|
|
|
}
|
|
|
|
|
2015-12-15 19:18:38 +03:00
|
|
|
int collection::add(dword in) {
|
2017-10-05 01:59:57 +03:00
|
|
|
return addn(in, strlen(in));
|
|
|
|
}
|
|
|
|
|
|
|
|
int collection::addn(dword in, len) {
|
|
|
|
if (count >= 4000) return 0;
|
|
|
|
if (element_offset[count]+len+2 > data_size) {
|
2015-12-15 19:18:38 +03:00
|
|
|
increase_data_size();
|
2017-10-05 01:59:57 +03:00
|
|
|
addn(in, len);
|
|
|
|
return 1;
|
2015-12-15 19:18:38 +03:00
|
|
|
}
|
2017-10-05 01:59:57 +03:00
|
|
|
strncpy(data_start+element_offset[count], in, len);
|
2015-12-13 16:28:06 +03:00
|
|
|
count++;
|
2017-10-05 01:59:57 +03:00
|
|
|
element_offset[count] = element_offset[count-1] + len + 1;
|
2015-12-15 19:18:38 +03:00
|
|
|
return 1;
|
2015-12-13 16:28:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dword collection::get(dword pos) {
|
2015-12-16 19:13:34 +03:00
|
|
|
if (pos<0) || (pos>=count) return 0;
|
2015-12-15 19:18:38 +03:00
|
|
|
return data_start + element_offset[pos];
|
2015-12-13 16:28:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void collection::drop() {
|
2015-12-15 19:18:38 +03:00
|
|
|
if (data_start) free(data_start);
|
2015-12-16 19:13:34 +03:00
|
|
|
data_size = data_start = element_offset[count] = count = 0;
|
2015-12-13 16:28:06 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 17:41:55 +03:00
|
|
|
|
|
|
|
/*========================================================
|
|
|
|
= =
|
|
|
|
= Integer =
|
|
|
|
= =
|
|
|
|
========================================================*/
|
|
|
|
|
2017-10-03 17:55:12 +03:00
|
|
|
struct collection_int
|
2016-02-23 17:41:55 +03:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
dword element[4096*3];
|
|
|
|
int add();
|
|
|
|
dword get();
|
|
|
|
void drop();
|
|
|
|
};
|
|
|
|
|
2017-10-03 17:55:12 +03:00
|
|
|
int collection_int::add(dword in) {
|
2016-02-23 17:41:55 +03:00
|
|
|
if (count >= 4096*3) return 0;
|
|
|
|
element[count] = in;
|
|
|
|
count++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:55:12 +03:00
|
|
|
dword collection_int::get(dword pos) {
|
2016-02-23 17:41:55 +03:00
|
|
|
if (pos<0) || (pos>=count) return 0;
|
|
|
|
return element[pos];
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:55:12 +03:00
|
|
|
void collection_int::drop() {
|
2016-02-23 17:41:55 +03:00
|
|
|
element[0] =
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-13 16:28:06 +03:00
|
|
|
#endif
|