2015-12-13 16:28:06 +03:00
|
|
|
#ifndef INCLUDE_COLLECTION_H
|
|
|
|
#define INCLUDE_COLLECTION_H
|
|
|
|
#print "[include <collection.h>]\n"
|
|
|
|
|
|
|
|
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;
|
2015-12-15 19:18:38 +03:00
|
|
|
dword element_offset[4090];
|
|
|
|
int add();
|
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) {
|
|
|
|
if (count >= 4090) return 0;
|
2015-12-16 19:13:34 +03:00
|
|
|
if (element_offset[count]+strlen(in)+2 > data_size) {
|
2015-12-15 19:18:38 +03:00
|
|
|
increase_data_size();
|
|
|
|
add(in);
|
|
|
|
return;
|
|
|
|
}
|
2015-12-16 19:13:34 +03:00
|
|
|
strcpy(data_start+element_offset[count], in);
|
2015-12-13 16:28:06 +03:00
|
|
|
count++;
|
2015-12-16 19:13:34 +03:00
|
|
|
element_offset[count] = element_offset[count-1] + strlen(in) + 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
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|