kolibrios/programs/cmm/lib/collection.h
Kirill Lipatov (Leency) a950d94c01 C-- basic Collections support (lib/collection.h)
git-svn-id: svn://kolibrios.org@5959 a494cfbc-eb01-0410-851d-a64ba20cac60
2015-12-13 13:28:06 +00:00

45 lines
886 B
C

#ifndef INCLUDE_COLLECTION_H
#define INCLUDE_COLLECTION_H
#print "[include <collection.h>]\n"
struct collection
{
int count;
dword element_offset[4096];
dword data_size;
dword string_data_start;
dword string_data_cur_pos;
void add();
dword get();
void drop();
void init();
};
void collection::init(dword size) {
if (data_size) drop();
data_size = data_size + size;
string_data_cur_pos = string_data_start = malloc(data_size);
count = 0;
}
void collection::add(dword in) {
strcpy(string_data_cur_pos, in);
element_offset[count] = string_data_cur_pos;
string_data_cur_pos += strlen(in) + 1;
count++;
}
dword collection::get(dword pos) {
return element_offset[pos];
}
void collection::drop() {
if (string_data_start) free(string_data_start);
data_size =
string_data_start =
string_data_cur_pos =
count = 0;
}
#endif