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