[Half-Life AMXX] / include / cellarray.inc Repository:
ViewVC logotype

Annotation of /include/cellarray.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (view) (download)

1 : ian 17 #if defined _cellarray_included
2 :     #endinput
3 :     #endif
4 :    
5 :     #define _cellarray_included
6 :    
7 :     /**
8 :     * These arrays are intended to be used for a form of global storage without
9 :     * requiring a #define that needs to be increased each time a person needs more
10 :     * storage.
11 :     * These are not designed to be used as a replacement for normal arrays, as
12 :     * normal arrays are faster and should be used whenever possible.
13 :     */
14 :    
15 :     /**
16 :     * Creates a handle to a dynamically sized array.
17 :     * It is very important that the cellsize you provide matches up with the buffer sizes
18 :     * that you pass with subsequent Array{Get,Set,Push} calls.
19 :     *
20 :     * @param cellsize How many cells each entry in the array is.
21 :     * @param reserved How many blank entries are created immediately when the array is created. These entries are not valid to read from until called with ArraySet.
22 :     * @return Handle to the array.
23 :     */
24 :     native Array:ArrayCreate(cellsize=1, reserved=32);
25 :    
26 :     /**
27 :     * Clears all entries from the array.
28 :     *
29 :     * @param which The array to clear.
30 :     * @return 1 on success, 0 on failure.
31 :     */
32 :     native ArrayClear(Array:which);
33 :    
34 :     /**
35 :     * Returns the number of elements in the array.
36 :     *
37 :     * @param which The array to check.
38 :     * @return How many elements are in the array.
39 :     */
40 :     native ArraySize(Array:which);
41 :    
42 :     /**
43 :     * Returns data within an array.
44 :     * Make sure the output buffer matches the size the array was created with!
45 :     *
46 :     * @param which The array to retrieve the item from.
47 :     * @param item The item to retrieve (zero-based).
48 :     * @param output The output buffer to write.
49 :     */
50 :     native ArrayGetArray(Array:which, item, any:output[]);
51 :    
52 :     /**
53 :     * Returns a single cell of data from an array.
54 :     * Use this only with arrays that were created with a cellsize of 1!
55 :     *
56 :     * @param which The array to retrieve the item from.
57 :     * @param item The item to retrieve (zero-based).
58 :     * @return The value of the cell.
59 :     */
60 :     native any:ArrayGetCell(Array:which, item);
61 :    
62 :     /**
63 :     * Returns a string value from an array.
64 :     *
65 :     * @param which The array to retrieve the item from.
66 :     * @param item The item to retrieve (zero-based).
67 :     * @param output The variable to store the value in.
68 :     * @param size Character size of the output buffer.
69 :     */
70 :     native ArrayGetString(Array:which, item, output[], size);
71 :    
72 :     /**
73 :     * Sets an item's data with that of a local buffer.
74 :     * The buffer size must match what the cellsize that the array was created with!
75 :     * The item must already exist, use ArrayPushArray to create a new item within the array.
76 :     *
77 :     * @param which The array to set the item from within.
78 :     * @param item The item to set (zero-based).
79 :     * @param input The input buffer to store.
80 :     */
81 :     native ArraySetArray(Array:which, item, const any:input[]);
82 :    
83 :     /**
84 :     * Sets an array's single cell value. Use this only on array that were created with a cellsize of 1!
85 :     * The item must already exist, use ArrayPushCell to create a new item within the array.
86 :     *
87 :     * @param which The array to set the item from within.
88 :     * @param item The item to set (zero-based).
89 :     * @param input The value to set.
90 :     */
91 :     native ArraySetCell(Array:which, item, any:input);
92 :    
93 :     /**
94 :     * Sets a string value from an array.
95 :     * The stored string will be truncated if it is longer than the cellsize the array was created with!
96 :     * The item must already exist, use ArrayPushString to create a new item within the array.
97 :     *
98 :     * @param which The array to set the item from within.
99 :     * @param item The item to set (zero-based).
100 :     * @param input The string to set the item as.
101 :     */
102 :     native ArraySetString(Array:which, item, const input[]);
103 :    
104 :     /**
105 :     * Creates a new item at the end of the array and sets its data with that of a local buffer.
106 :     * The buffer size must match what the cellsize that the array was created with!
107 :     *
108 :     * @param which The array to add the item to.
109 :     * @param input The input buffer to store.
110 :     */
111 :     native ArrayPushArray(Array:which, const any:input[]);
112 :    
113 :     /**
114 :     * Creates a new item and sets the array's single cell value.
115 :     * Use this only on array that were created with a cellsize of 1!
116 :     *
117 :     * @param which The array to add the item to.
118 :     * @param input The value to set.
119 :     */
120 :     native ArrayPushCell(Array:which, any:input);
121 :    
122 :     /**
123 :     * Creates a new element in the array and sets its value to the input buffer.
124 :     * The stored string will be truncated if it is longer than the cellsize the array was created with!
125 :     *
126 :     * @param which The array to add the item to.
127 :     * @param input The string to set the item as.
128 :     */
129 :     native ArrayPushString(Array:which, const input[]);
130 :    
131 :     /**
132 :     * Inserts an item after the selected item. All items beyond it get shifted up 1 space.
133 :     * The buffer size must match what the cellsize that the array was created with!
134 :     *
135 :     * @param which The array to add the item to.
136 :     * @param item The item to insert after.
137 :     * @param input The input buffer to store.
138 :     */
139 :     native ArrayInsertArrayAfter(Array:which, item, const any:input[]);
140 :    
141 :     /**
142 :     * Inserts an item after the selected item. All items beyond it get shifted up 1 space.
143 :     * Use this only on an array that was created with a cellsize of 1!
144 :     *
145 :     * @param which The array to add the item to.
146 :     * @param item The item to insert after.
147 :     * @param input The value to set.
148 :     */
149 :     native ArrayInsertCellAfter(Array:which, item, any:input);
150 :    
151 :     /**
152 :     * Inserts an item after the selected item. All items beyond it get shifted up 1 space.
153 :     * The stored string will be truncated if it is longer than the cellsize the array was created with!
154 :     *
155 :     * @param which The array to add the item to.
156 :     * @param item The item to insert after.
157 :     * @param input The value to set.
158 :     */
159 :     native ArrayInsertStringAfter(Array:which, item, const input[]);
160 :    
161 :     /**
162 :     * Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
163 :     * The buffer size must match what the cellsize that the array was created with!
164 :     *
165 :     * @param which The array to add the item to.
166 :     * @param item The item to insert before.
167 :     * @param input The input buffer to store.
168 :     */
169 :     native ArrayInsertArrayBefore(Array:which, item, const any:input[]);
170 :    
171 :     /**
172 :     * Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
173 :     * Use this only on an array that was created with a cellsize of 1!
174 :     *
175 :     * @param which The array to add the item to.
176 :     * @param item The item to insert after.
177 :     * @param input The value to set.
178 :     */
179 :     native ArrayInsertCellBefore(Array:which, item, const any:input);
180 :    
181 :     /**
182 :     * Inserts an item before the selected item. All items beyond it, and the selected item get shifted up 1 space.
183 :     * The stored string will be truncated if it is longer than the cellsize the array was created with!
184 :     *
185 :     * @param which The array to add the item to.
186 :     * @param item The item to insert before.
187 :     * @param input The value to set.
188 :     */
189 :     native ArrayInsertStringBefore(Array:which, item, const input[]);
190 :    
191 :     /**
192 :     * Swaps the position of two items.
193 :     *
194 :     * @param which The array that contains the items.
195 :     * @param item1 The first item to swap.
196 :     * @param item2 The second item to swap.
197 :     */
198 :     native ArraySwap(Array:which, item1, item2);
199 :    
200 :     /**
201 :     * Deletes an item from the array. All items beyond it get shifted down 1 space.
202 :     *
203 :     * @param which The array that contains the item to delete.
204 :     * @param item The item to delete.
205 :     */
206 :     native ArrayDeleteItem(Array:which, item);
207 :    
208 :     /**
209 :     * Creates a handle that is passable to a format compliant routine for printing as a string (with the %a format option).
210 :     * It is suggested to pass the function directly as a parameter to the format routine.
211 :     * The array contents must be a null-terminated string!
212 :     *
213 :     * An example usage: client_print(id, print_chat, "%a", ArrayGetStringHandle(MessageArray, i));
214 :     *
215 :     * @param which The array the string is stored in.
216 :     * @param item Which item to print the string value of.
217 :     * @return Handle to the item directly. Do not use or save stale handles.
218 :     */
219 :     native DoNotUse:ArrayGetStringHandle(Array:which, item);
220 :    
221 :     /**
222 :     * Destroys the array, and resets the handle to 0 to prevent accidental usage after it is destroyed.
223 :     *
224 :     * @param which The array to destroy.
225 :     */
226 :     native ArrayDestroy(&Array:which);
227 :    
228 :    
229 :    
230 :     /**
231 :     * Similar to sorting.inc's CustomSort.
232 :     * The sorting algorithm then uses your comparison function to sort the data.
233 :     * The function is called in the following manner:
234 :     *
235 :     * public MySortFunc(Array:array, item1, item2, const data[], data_size)
236 :     *
237 :     * array - Array handle in its current un-sorted state.
238 :     * item1, item2 - Current item pair being compared
239 :     * data[] - Extra data array you passed to the sort func.
240 :     * data_size - Size of extra data you passed to the sort func.
241 :     *
242 :     * Your function should return:
243 :     * -1 if item1 should go before item2
244 :     * 0 if item1 and item2 are equal
245 :     * 1 if item1 should go after item2
246 :     * Note that the parameters after item2 are all optional and you do not need to specify them.
247 :     *
248 :     * Note that unlike the sorting.inc versions, the array passed to the callback is not in mid-sorted state.
249 :     */
250 :     native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0);

Contact
ViewVC Help
Powered by ViewVC 1.0.4