Rev 5965 | Rev 5977 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5959 | leency | 1 | #ifndef INCLUDE_COLLECTION_H |
2 | #define INCLUDE_COLLECTION_H |
||
3 | #print "[include |
||
4 | |||
5 | struct collection |
||
6 | { |
||
5965 | leency | 7 | int realloc_size, count; |
8 | dword data_start; |
||
5959 | leency | 9 | dword data_size; |
5965 | leency | 10 | dword element_offset[4090]; |
11 | int add(); |
||
5959 | leency | 12 | dword get(); |
13 | void drop(); |
||
5965 | leency | 14 | void increase_data_size(); |
5959 | leency | 15 | |
16 | }; |
||
17 | |||
5965 | leency | 18 | void collection::increase_data_size() { |
19 | int filled_size; |
||
20 | if (realloc_size<4096) realloc_size = 4096; |
||
21 | if (!data_size) { |
||
22 | data_size = realloc_size; |
||
23 | data_start = malloc(realloc_size); |
||
24 | } |
||
25 | else { |
||
26 | data_size = data_size + realloc_size; |
||
27 | data_start = realloc(data_start, data_size); |
||
28 | } |
||
5959 | leency | 29 | } |
30 | |||
5965 | leency | 31 | int collection::add(dword in) { |
32 | if (count >= 4090) return 0; |
||
5974 | leency | 33 | if (element_offset[count]+strlen(in)+2 > data_size) { |
5965 | leency | 34 | increase_data_size(); |
35 | add(in); |
||
36 | return; |
||
37 | } |
||
5974 | leency | 38 | strcpy(data_start+element_offset[count], in); |
5959 | leency | 39 | count++; |
5974 | leency | 40 | element_offset[count] = element_offset[count-1] + strlen(in) + 1; |
5965 | leency | 41 | return 1; |
5959 | leency | 42 | } |
43 | |||
44 | dword collection::get(dword pos) { |
||
5974 | leency | 45 | if (pos<0) || (pos>=count) return 0; |
5965 | leency | 46 | return data_start + element_offset[pos]; |
5959 | leency | 47 | } |
48 | |||
49 | void collection::drop() { |
||
5965 | leency | 50 | if (data_start) free(data_start); |
5974 | leency | 51 | data_size = data_start = element_offset[count] = count = 0; |
5959 | leency | 52 | } |
53 | |||
54 | #endif0)>4096)> |