Rev 7049 | Rev 7738 | 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 | |||
6285 | leency | 5 | /*======================================================== |
6 | = = |
||
7 | = String = |
||
8 | = = |
||
9 | ========================================================*/ |
||
10 | |||
5959 | leency | 11 | struct collection |
12 | { |
||
5965 | leency | 13 | int realloc_size, count; |
14 | dword data_start; |
||
5959 | leency | 15 | dword data_size; |
7049 | leency | 16 | dword element_offset[4000]; |
5965 | leency | 17 | int add(); |
7049 | leency | 18 | int addn(); |
5959 | leency | 19 | dword get(); |
20 | void drop(); |
||
5965 | leency | 21 | void increase_data_size(); |
5959 | leency | 22 | }; |
23 | |||
7286 | leency | 24 | :void collection::increase_data_size() { |
5965 | leency | 25 | int filled_size; |
26 | if (realloc_size<4096) realloc_size = 4096; |
||
27 | if (!data_size) { |
||
28 | data_size = realloc_size; |
||
29 | data_start = malloc(realloc_size); |
||
30 | } |
||
31 | else { |
||
32 | data_size = data_size + realloc_size; |
||
33 | data_start = realloc(data_start, data_size); |
||
34 | } |
||
5959 | leency | 35 | } |
36 | |||
7286 | leency | 37 | :int collection::add(dword in) { |
7049 | leency | 38 | return addn(in, strlen(in)); |
39 | } |
||
40 | |||
7286 | leency | 41 | :int collection::addn(dword in, len) { |
7049 | leency | 42 | if (count >= 4000) return 0; |
43 | if (element_offset[count]+len+2 > data_size) { |
||
5965 | leency | 44 | increase_data_size(); |
7049 | leency | 45 | addn(in, len); |
46 | return 1; |
||
5965 | leency | 47 | } |
7049 | leency | 48 | strncpy(data_start+element_offset[count], in, len); |
5959 | leency | 49 | count++; |
7049 | leency | 50 | element_offset[count] = element_offset[count-1] + len + 1; |
5965 | leency | 51 | return 1; |
5959 | leency | 52 | } |
53 | |||
7286 | leency | 54 | :dword collection::get(dword pos) { |
5974 | leency | 55 | if (pos<0) || (pos>=count) return 0; |
5965 | leency | 56 | return data_start + element_offset[pos]; |
5959 | leency | 57 | } |
58 | |||
7286 | leency | 59 | :void collection::drop() { |
5965 | leency | 60 | if (data_start) free(data_start); |
5974 | leency | 61 | data_size = data_start = element_offset[count] = count = 0; |
5959 | leency | 62 | } |
63 | |||
6285 | leency | 64 | |
65 | /*======================================================== |
||
66 | = = |
||
67 | = Integer = |
||
68 | = = |
||
69 | ========================================================*/ |
||
70 | |||
7043 | leency | 71 | struct collection_int |
6285 | leency | 72 | { |
73 | int count; |
||
74 | dword element[4096*3]; |
||
75 | int add(); |
||
76 | dword get(); |
||
7286 | leency | 77 | dword get_last(); |
78 | void pop(); |
||
6285 | leency | 79 | void drop(); |
80 | }; |
||
81 | |||
7286 | leency | 82 | :int collection_int::add(dword in) { |
6285 | leency | 83 | if (count >= 4096*3) return 0; |
84 | element[count] = in; |
||
85 | count++; |
||
86 | return 1; |
||
87 | } |
||
88 | |||
7286 | leency | 89 | :dword collection_int::get(dword pos) { |
6285 | leency | 90 | if (pos<0) || (pos>=count) return 0; |
91 | return element[pos]; |
||
92 | } |
||
93 | |||
7286 | leency | 94 | :dword collection_int::get_last() { |
95 | return element[count]; |
||
96 | } |
||
97 | |||
98 | :void collection_int::pop() { |
||
99 | if (count>0) count--; |
||
100 | } |
||
101 | |||
102 | :void collection_int::drop() { |
||
6285 | leency | 103 | element[0] = |
104 | count = 0; |
||
105 | } |
||
106 | |||
5959 | leency | 107 | #endif0)>0)>4096)> |