]>
Commit | Line | Data |
---|---|---|
745129be | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
ef416fc2 | 2 | <html> |
3 | <!-- SECTION: Programming --> | |
4 | <head> | |
0268488e MS |
5 | <title>Array API </title> |
6 | <meta name="keywords" content="Programming"> | |
7 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
dd3fdd2c | 8 | <meta name="creator" content="Mini-XML v2.7"> |
5a738aea MS |
9 | <style type="text/css"><!-- |
10 | BODY { | |
11 | font-family: lucida grande, geneva, helvetica, arial, sans-serif; | |
12 | } | |
13 | ||
14 | H1, H2, H3, H4, H5, H6, P, TD, TH { | |
15 | font-family: lucida grande, geneva, helvetica, arial, sans-serif; | |
16 | } | |
17 | ||
18 | KBD { | |
19 | font-family: monaco, courier, monospace; | |
20 | font-weight: bold; | |
21 | } | |
22 | ||
23 | PRE { | |
24 | font-family: monaco, courier, monospace; | |
25 | } | |
26 | ||
27 | PRE.command { | |
10d09e33 | 28 | border: dotted thin #7f7f7f; |
5a738aea | 29 | margin-left: 36pt; |
10d09e33 | 30 | padding: 10px; |
5a738aea MS |
31 | } |
32 | ||
f11a948a MS |
33 | P.compact { |
34 | margin: 0; | |
35 | } | |
36 | ||
e4572d57 MS |
37 | P.example { |
38 | font-style: italic; | |
39 | margin-left: 36pt; | |
40 | } | |
ca6b43fc | 41 | |
240214ef MS |
42 | DL.man DD { |
43 | margin-left: 5em; | |
44 | } | |
45 | ||
46 | DL.man DT { | |
47 | margin-left: 0; | |
48 | } | |
49 | ||
50 | PRE.man { | |
51 | margin: 0; | |
52 | } | |
53 | ||
5a738aea MS |
54 | PRE.example { |
55 | background: #eeeeee; | |
56 | border: dotted thin #999999; | |
57 | margin-left: 36pt; | |
178cb736 | 58 | padding: 10pt; |
5a738aea MS |
59 | } |
60 | ||
61 | PRE.command EM, PRE.example EM { | |
62 | font-family: lucida grande, geneva, helvetica, arial, sans-serif; | |
63 | } | |
64 | ||
65 | P.command { | |
66 | font-family: monaco, courier, monospace; | |
67 | margin-left: 36pt; | |
68 | } | |
69 | ||
70 | P.formula { | |
71 | font-style: italic; | |
72 | margin-left: 36pt; | |
73 | } | |
74 | ||
75 | BLOCKQUOTE { | |
178cb736 | 76 | background: #eeeeee; |
5a738aea MS |
77 | border: solid thin #999999; |
78 | padding: 10pt; | |
79 | } | |
80 | ||
e4572d57 MS |
81 | A IMG { |
82 | border: none; | |
83 | } | |
84 | ||
85 | A:link:hover IMG { | |
86 | background: #f0f0f0; | |
87 | border-radius: 10px; | |
88 | -moz-border-radius: 10px; | |
89 | } | |
90 | ||
5a738aea | 91 | A:link, A:visited { |
ca6b43fc | 92 | font-weight: inherit; |
5a738aea | 93 | text-decoration: none; |
5a738aea MS |
94 | } |
95 | ||
96 | A:link:hover, A:visited:hover, A:active { | |
97 | text-decoration: underline; | |
5a738aea MS |
98 | } |
99 | ||
100 | SUB, SUP { | |
101 | font-size: 50%; | |
102 | } | |
103 | ||
e4572d57 MS |
104 | TR.data, TD.data, TR.data TD { |
105 | margin-top: 10pt; | |
106 | padding: 5pt; | |
107 | border-bottom: solid 1pt #999999; | |
108 | } | |
109 | ||
110 | TR.data TH { | |
111 | border-bottom: solid 1pt #999999; | |
112 | padding-top: 10pt; | |
113 | padding-left: 5pt; | |
114 | text-align: left; | |
115 | } | |
116 | ||
5a738aea MS |
117 | DIV.table TABLE { |
118 | border: solid thin #999999; | |
119 | border-collapse: collapse; | |
120 | border-spacing: 0; | |
121 | margin-left: auto; | |
122 | margin-right: auto; | |
123 | } | |
124 | ||
125 | DIV.table CAPTION { | |
126 | caption-side: top; | |
127 | font-size: 120%; | |
128 | font-style: italic; | |
129 | font-weight: bold; | |
130 | margin-left: auto; | |
131 | margin-right: auto; | |
132 | } | |
133 | ||
134 | DIV.table TABLE TD { | |
135 | border: solid thin #cccccc; | |
136 | padding-top: 5pt; | |
137 | } | |
138 | ||
139 | DIV.table TABLE TH { | |
140 | background: #cccccc; | |
141 | border: none; | |
142 | border-bottom: solid thin #999999; | |
143 | } | |
144 | ||
145 | DIV.figure TABLE { | |
146 | margin-left: auto; | |
147 | margin-right: auto; | |
148 | } | |
149 | ||
150 | DIV.figure CAPTION { | |
151 | caption-side: bottom; | |
152 | font-size: 120%; | |
153 | font-style: italic; | |
154 | font-weight: bold; | |
155 | margin-left: auto; | |
156 | margin-right: auto; | |
157 | } | |
158 | ||
159 | TH.label { | |
5a738aea MS |
160 | text-align: right; |
161 | vertical-align: top; | |
162 | } | |
163 | ||
e4572d57 MS |
164 | TH.sublabel { |
165 | text-align: right; | |
166 | font-weight: normal; | |
167 | } | |
168 | ||
5a738aea MS |
169 | HR { |
170 | border: solid thin; | |
171 | } | |
172 | ||
173 | SPAN.info { | |
e4572d57 MS |
174 | background: black; |
175 | border: thin solid black; | |
176 | color: white; | |
5a738aea MS |
177 | font-size: 80%; |
178 | font-style: italic; | |
179 | font-weight: bold; | |
180 | white-space: nowrap; | |
181 | } | |
182 | ||
183 | H2 SPAN.info, H3 SPAN.info, H4 SPAN.info { | |
184 | float: right; | |
185 | font-size: 100%; | |
186 | } | |
187 | ||
178cb736 MS |
188 | H1.title { |
189 | } | |
190 | ||
5a738aea MS |
191 | H2.title, H3.title { |
192 | border-bottom: solid 2pt #000000; | |
193 | } | |
194 | ||
e4572d57 MS |
195 | DIV.indent, TABLE.indent { |
196 | margin-top: 2em; | |
197 | margin-left: auto; | |
198 | margin-right: auto; | |
199 | width: 90%; | |
200 | } | |
201 | ||
202 | TABLE.indent { | |
203 | border-collapse: collapse; | |
204 | } | |
205 | ||
206 | TABLE.indent TD, TABLE.indent TH { | |
207 | padding: 0; | |
208 | } | |
209 | ||
210 | TABLE.list { | |
211 | border-collapse: collapse; | |
212 | margin-left: auto; | |
213 | margin-right: auto; | |
214 | width: 90%; | |
215 | } | |
216 | ||
217 | TABLE.list TH { | |
218 | background: white; | |
219 | border-bottom: solid thin #cccccc; | |
220 | color: #444444; | |
221 | padding-top: 10pt; | |
222 | padding-left: 5pt; | |
223 | text-align: left; | |
224 | vertical-align: bottom; | |
225 | white-space: nowrap; | |
226 | } | |
227 | ||
228 | TABLE.list TH A { | |
229 | color: #4444cc; | |
230 | } | |
231 | ||
232 | TABLE.list TD { | |
233 | border-bottom: solid thin #eeeeee; | |
234 | padding-top: 5pt; | |
235 | padding-left: 5pt; | |
236 | } | |
237 | ||
238 | TABLE.list TR:nth-child(even) { | |
239 | background: #f8f8f8; | |
240 | } | |
241 | ||
242 | TABLE.list TR:nth-child(odd) { | |
243 | background: #f4f4f4; | |
244 | } | |
245 | ||
5a738aea MS |
246 | DT { |
247 | margin-left: 36pt; | |
248 | margin-top: 12pt; | |
249 | } | |
250 | ||
251 | DD { | |
252 | margin-left: 54pt; | |
253 | } | |
254 | ||
255 | DL.category DT { | |
256 | font-weight: bold; | |
257 | } | |
258 | ||
259 | P.summary { | |
260 | margin-left: 36pt; | |
261 | font-family: monaco, courier, monospace; | |
262 | } | |
263 | ||
5a738aea MS |
264 | DIV.summary TABLE { |
265 | border: solid thin #999999; | |
266 | border-collapse: collapse; | |
267 | border-spacing: 0; | |
268 | margin: 10px; | |
269 | } | |
270 | ||
271 | DIV.summary TABLE TD, DIV.summary TABLE TH { | |
272 | border: solid thin #999999; | |
273 | padding: 5px; | |
274 | text-align: left; | |
275 | vertical-align: top; | |
276 | } | |
277 | ||
278 | DIV.summary TABLE THEAD TH { | |
279 | background: #eeeeee; | |
280 | } | |
281 | ||
282 | /* API documentation styles... */ | |
283 | div.body h1 { | |
284 | margin: 0; | |
285 | } | |
286 | div.body h2 { | |
287 | margin-top: 1.5em; | |
288 | } | |
289 | div.body h3, div.body h4, div.body h5 { | |
290 | margin-bottom: 0.5em; | |
291 | margin-top: 1.5em; | |
292 | } | |
293 | .class, .enumeration, .function, .struct, .typedef, .union { | |
294 | border-bottom: solid thin #999999; | |
295 | margin-bottom: 0; | |
296 | margin-top: 2em; | |
297 | } | |
298 | .description { | |
299 | margin-top: 0.5em; | |
300 | } | |
301 | code, p.code, pre, ul.code li { | |
302 | font-family: monaco, courier, monospace; | |
303 | font-size: 90%; | |
304 | } | |
305 | ul.code, ul.contents, ul.subcontents { | |
306 | list-style-type: none; | |
307 | margin: 0; | |
308 | padding-left: 0; | |
309 | } | |
310 | ul.code li { | |
311 | margin: 0; | |
312 | } | |
313 | ul.contents > li { | |
314 | margin-top: 1em; | |
315 | } | |
316 | ul.contents li ul.code, ul.contents li ul.subcontents { | |
317 | padding-left: 2em; | |
318 | } | |
319 | div.body dl { | |
320 | margin-left: 0; | |
321 | margin-top: 0; | |
322 | } | |
323 | div.body dt { | |
324 | font-style: italic; | |
325 | margin-left: 0; | |
326 | margin-top: 0; | |
327 | } | |
328 | div.body dd { | |
329 | margin-bottom: 0.5em; | |
330 | } | |
331 | ||
332 | /* This is just for the HTML files generated with the framedhelp target */ | |
333 | div.contents { | |
334 | background: #e8e8e8; | |
335 | border: solid thin black; | |
336 | padding: 10px; | |
337 | } | |
338 | div.contents h1 { | |
339 | font-size: 110%; | |
340 | } | |
341 | div.contents h2 { | |
342 | font-size: 100%; | |
343 | } | |
344 | div.contents ul.contents { | |
345 | font-size: 80%; | |
346 | } | |
ac884b6a MS |
347 | div.contents ul.subcontents li { |
348 | margin-left: 1em; | |
349 | text-indent: -1em; | |
350 | } | |
5a738aea | 351 | --></style> |
ef416fc2 | 352 | </head> |
353 | <body> | |
5a738aea MS |
354 | <div class='body'> |
355 | <!-- | |
321d8d57 | 356 | Array API header for CUPS. |
5a738aea | 357 | |
321d8d57 | 358 | Copyright 2008-2011 by Apple Inc. |
5a738aea MS |
359 | |
360 | These coded instructions, statements, and computer programs are the | |
361 | property of Apple Inc. and are protected by Federal copyright | |
362 | law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
363 | which should have been included with this file. If this file is | |
364 | file is missing or damaged, see the license at "http://www.cups.org/". | |
365 | --> | |
366 | ||
178cb736 MS |
367 | <h1 class='title'>Array API</h1> |
368 | ||
5a738aea MS |
369 | <div class='summary'><table summary='General Information'> |
370 | <thead> | |
371 | <tr> | |
372 | <th>Header</th> | |
373 | <th>cups/array.h</th> | |
374 | </tr> | |
375 | </thead> | |
376 | <tbody> | |
377 | <tr> | |
378 | <th>Library</th> | |
379 | <td>-lcups</td> | |
380 | </tr> | |
381 | <tr> | |
382 | <th>See Also</th> | |
383 | <td>Programming: <a href='api-overview.html' target='_top'>Introduction to CUPS Programming</a></td> | |
384 | </tr> | |
385 | </tbody> | |
386 | </table></div> | |
387 | <h2 class="title">Contents</h2> | |
388 | <ul class="contents"> | |
5a738aea | 389 | <li><a href="#OVERVIEW">Overview</a><ul class="subcontents"> |
0268488e MS |
390 | <li><a href="#MANAGING_ARRAYS">Managing Arrays</a></li> |
391 | <li><a href="#FINDING_AND_ENUMERATING">Finding and Enumerating Elements</a></li> | |
5a738aea MS |
392 | </ul></li> |
393 | <li><a href="#FUNCTIONS">Functions</a><ul class="code"> | |
0268488e MS |
394 | <li><a href="#cupsArrayAdd" title="Add an element to the array.">cupsArrayAdd</a></li> |
395 | <li><a href="#cupsArrayClear" title="Clear the array.">cupsArrayClear</a></li> | |
396 | <li><a href="#cupsArrayCount" title="Get the number of elements in the array.">cupsArrayCount</a></li> | |
397 | <li><a href="#cupsArrayCurrent" title="Return the current element in the array.">cupsArrayCurrent</a></li> | |
398 | <li><a href="#cupsArrayDelete" title="Free all memory used by the array.">cupsArrayDelete</a></li> | |
399 | <li><a href="#cupsArrayDup" title="Duplicate the array.">cupsArrayDup</a></li> | |
400 | <li><a href="#cupsArrayFind" title="Find an element in the array.">cupsArrayFind</a></li> | |
401 | <li><a href="#cupsArrayFirst" title="Get the first element in the array.">cupsArrayFirst</a></li> | |
402 | <li><a href="#cupsArrayGetIndex" title="Get the index of the current element.">cupsArrayGetIndex</a></li> | |
403 | <li><a href="#cupsArrayGetInsert" title="Get the index of the last inserted element.">cupsArrayGetInsert</a></li> | |
404 | <li><a href="#cupsArrayIndex" title="Get the N-th element in the array.">cupsArrayIndex</a></li> | |
405 | <li><a href="#cupsArrayInsert" title="Insert an element in the array.">cupsArrayInsert</a></li> | |
406 | <li><a href="#cupsArrayLast" title="Get the last element in the array.">cupsArrayLast</a></li> | |
407 | <li><a href="#cupsArrayNew" title="Create a new array.">cupsArrayNew</a></li> | |
408 | <li><a href="#cupsArrayNew2" title="Create a new array with hash.">cupsArrayNew2</a></li> | |
409 | <li><a href="#cupsArrayNew3" title="Create a new array with hash and/or free function.">cupsArrayNew3</a></li> | |
410 | <li><a href="#cupsArrayNext" title="Get the next element in the array.">cupsArrayNext</a></li> | |
411 | <li><a href="#cupsArrayPrev" title="Get the previous element in the array.">cupsArrayPrev</a></li> | |
412 | <li><a href="#cupsArrayRemove" title="Remove an element from the array.">cupsArrayRemove</a></li> | |
413 | <li><a href="#cupsArrayRestore" title="Reset the current element to the last cupsArraySave.">cupsArrayRestore</a></li> | |
414 | <li><a href="#cupsArraySave" title="Mark the current element for a later cupsArrayRestore.">cupsArraySave</a></li> | |
415 | <li><a href="#cupsArrayUserData" title="Return the user data for an array.">cupsArrayUserData</a></li> | |
8b450588 | 416 | </ul></li> |
5a738aea | 417 | <li><a href="#TYPES">Data Types</a><ul class="code"> |
10d09e33 MS |
418 | <li><a href="#cups_acopy_func_t" title="Array element copy function">cups_acopy_func_t</a></li> |
419 | <li><a href="#cups_afree_func_t" title="Array element free function">cups_afree_func_t</a></li> | |
5a738aea MS |
420 | <li><a href="#cups_ahash_func_t" title="Array hash function">cups_ahash_func_t</a></li> |
421 | <li><a href="#cups_array_func_t" title="Array comparison function">cups_array_func_t</a></li> | |
422 | <li><a href="#cups_array_t" title="CUPS array type">cups_array_t</a></li> | |
423 | </ul></li> | |
0268488e | 424 | </ul> |
ef416fc2 | 425 | <!-- |
eac3a0a0 | 426 | Array API introduction for CUPS. |
ef416fc2 | 427 | |
eac3a0a0 | 428 | Copyright 2007-2011 by Apple Inc. |
bc44d920 | 429 | Copyright 1997-2006 by Easy Software Products, all rights reserved. |
ef416fc2 | 430 | |
431 | These coded instructions, statements, and computer programs are the | |
bc44d920 | 432 | property of Apple Inc. and are protected by Federal copyright |
433 | law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
434 | which should have been included with this file. If this file is | |
435 | file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 436 | --> |
437 | ||
5a738aea | 438 | <h2 class='title'><a name='OVERVIEW'>Overview</a></h2> |
ef416fc2 | 439 | |
5a738aea MS |
440 | <p>The CUPS array API provides a high-performance generic array container. |
441 | The contents of the array container can be sorted and the container itself is | |
442 | designed for optimal speed and memory usage under a wide variety of conditions. | |
443 | Sorted arrays use a binary search algorithm from the last found or inserted | |
444 | element to quickly find matching elements in the array. Arrays created with the | |
445 | optional hash function can often find elements with a single lookup. The | |
446 | <a href='#cups_array_t'><code>cups_array_t</code></a> type is used when | |
447 | referring to a CUPS array.</p> | |
ef416fc2 | 448 | |
449 | <p>The CUPS scheduler (<tt>cupsd</tt>) and many of the CUPS API | |
450 | functions use the array API to efficiently manage large lists of | |
451 | data.</p> | |
452 | ||
5a738aea MS |
453 | <h3><a name='MANAGING_ARRAYS'>Managing Arrays</a></h3> |
454 | ||
455 | <p>Arrays are created using either the | |
10d09e33 MS |
456 | <a href='#cupsArrayNew'><code>cupsArrayNew</code></a>, |
457 | <a href='#cupsArrayNew2'><code>cupsArrayNew2</code></a>, or | |
458 | <a href='#cupsArrayNew2'><code>cupsArrayNew3</code></a> functions. The | |
5a738aea MS |
459 | first function creates a new array with the specified callback function |
460 | and user data pointer:</p> | |
ef416fc2 | 461 | |
5a738aea MS |
462 | <pre class='example'> |
463 | #include <cups/array.h> | |
ef416fc2 | 464 | |
5a738aea | 465 | static int compare_func(void *first, void *second, void *user_data); |
ef416fc2 | 466 | |
5a738aea MS |
467 | void *user_data; |
468 | <a href='#cups_array_t'>cups_array_t</a> *array = <a href='#cupsArrayNew'>cupsArrayNew</a>(compare_func, user_data); | |
ef416fc2 | 469 | </pre> |
470 | ||
5a738aea MS |
471 | <p>The comparison function (type |
472 | <a href="#cups_arrayfunc_t"><code>cups_arrayfunc_t</code></a>) is called | |
473 | whenever an element is added to the array and can be <code>NULL</code> to | |
474 | create an unsorted array. The function returns -1 if the first element should | |
475 | come before the second, 0 if the first and second elements should have the same | |
476 | ordering, and 1 if the first element should come after the second.</p> | |
ef416fc2 | 477 | |
5a738aea MS |
478 | <p>The "user_data" pointer is passed to your comparison function. Pass |
479 | <code>NULL</code> if you do not need to associate the elements in your array | |
480 | with additional information.</p> | |
481 | ||
482 | <p>The <a href='#cupsArrayNew2'><code>cupsArrayNew2</code></a> function adds | |
483 | two more arguments to support hashed lookups, which can potentially provide | |
484 | instantaneous ("O(1)") lookups in your array:</p> | |
485 | ||
486 | <pre class='example'> | |
487 | #include <cups/array.h> | |
488 | ||
489 | #define HASH_SIZE 512 /* Size of hash table */ | |
490 | ||
491 | static int compare_func(void *first, void *second, void *user_data); | |
492 | static int hash_func(void *element, void *user_data); | |
493 | ||
494 | void *user_data; | |
10d09e33 | 495 | <a href='#cups_array_t'>cups_array_t</a> *hash_array = <a href='#cupsArrayNew2'>cupsArrayNew2</a>(compare_func, user_data, hash_func, HASH_SIZE); |
5a738aea MS |
496 | </pre> |
497 | ||
498 | <p>The hash function (type | |
79e1d494 | 499 | <a href="#cups_ahash_func_t"><code>cups_ahash_func_t</code></a>) should return a |
5a738aea MS |
500 | number from 0 to (hash_size-1) that (hopefully) uniquely identifies the |
501 | element and is called whenever you look up an element in the array with | |
502 | <a href='#cupsArrayFind'><code>cupsArrayFind</code></a>. The hash size is | |
503 | only limited by available memory, but generally should not be larger than | |
504 | 16384 to realize any performance improvement.</p> | |
505 | ||
10d09e33 MS |
506 | <p>The <a href='#cupsArrayNew3'><code>cupsArrayNew3</code></a> function adds |
507 | copy and free callbacks to support basic memory management of elements:</p> | |
508 | ||
509 | <pre class='example'> | |
510 | #include <cups/array.h> | |
511 | ||
512 | #define HASH_SIZE 512 /* Size of hash table */ | |
513 | ||
514 | static int compare_func(void *first, void *second, void *user_data); | |
515 | static void *copy_func(void *element, void *user_data); | |
516 | static void free_func(void *element, void *user_data); | |
517 | static int hash_func(void *element, void *user_data); | |
518 | ||
519 | void *user_data; | |
520 | <a href='#cups_array_t'>cups_array_t</a> *array = <a href='#cupsArrayNew3'>cupsArrayNew3</a>(compare_func, user_data, NULL, 0, copy_func, free_func); | |
521 | ||
522 | <a href='#cups_array_t'>cups_array_t</a> *hash_array = <a href='#cupsArrayNew3'>cupsArrayNew3</a>(compare_func, user_data, hash_func, HASH_SIZE, copy_func, free_func); | |
523 | </pre> | |
524 | ||
5a738aea MS |
525 | <p>Once you have created the array, you add elements using the |
526 | <a href='#cupsArrayAdd'><code>cupsArrayAdd</code></a> | |
527 | <a href='#cupsArrayInsert'><code>cupsArrayInsert</code></a> functions. | |
528 | The first function adds an element to the array, adding the new element | |
529 | after any elements that have the same order, while the second inserts the | |
530 | element before others with the same order. For unsorted arrays, | |
79e1d494 | 531 | <a href='#cupsArrayAdd'><code>cupsArrayAdd</code></a> appends the element to |
5a738aea MS |
532 | the end of the array while |
533 | <a href='#cupsArrayInsert'><code>cupsArrayInsert</code></a> inserts the | |
534 | element at the beginning of the array. For example, the following code | |
535 | creates a sorted array of character strings:</p> | |
536 | ||
537 | <pre class='example'> | |
538 | #include <cups/array.h> | |
539 | ||
540 | /* Use strcmp() to compare strings - it will ignore the user_data pointer */ | |
541 | <a href='#cups_array_t'>cups_array_t</a> *array = <a href='#cupsArrayNew'>cupsArrayNew</a>((<a href='#cups_array_func_t'>cups_array_func_t</a>)strcmp, NULL); | |
542 | ||
543 | /* Add four strings to the array */ | |
544 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "One Fish"); | |
545 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Two Fish"); | |
546 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Red Fish"); | |
547 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Blue Fish"); | |
548 | </pre> | |
549 | ||
550 | <p>Elements are removed using the | |
551 | <a href='#cupsArrayRemove'><code>cupsArrayRemove</code></a> function, for | |
552 | example:</p> | |
553 | ||
554 | <pre class='example'> | |
555 | #include <cups/array.h> | |
556 | ||
557 | /* Use strcmp() to compare strings - it will ignore the user_data pointer */ | |
558 | <a href='#cups_array_t'>cups_array_t</a> *array = <a href='#cupsArrayNew'>cupsArrayNew</a>((<a href='#cups_array_func_t'>cups_array_func_t</a>)strcmp, NULL); | |
559 | ||
560 | /* Add four strings to the array */ | |
561 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "One Fish"); | |
562 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Two Fish"); | |
563 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Red Fish"); | |
564 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Blue Fish"); | |
565 | ||
566 | /* Remove "Red Fish" */ | |
567 | <a href='#cupsArrayRemove'>cupsArrayRemove</a>(array, "Red Fish"); | |
568 | </pre> | |
569 | ||
570 | <p>Finally, you free the memory used by the array using the | |
571 | <a href='#cupsArrayDelete'><code>cupsArrayDelete</code></a> function. All | |
572 | of the memory for the array and hash table (if any) is freed, however <em>CUPS | |
10d09e33 | 573 | does not free the elements unless you provide copy and free functions</em>.</p> |
5a738aea MS |
574 | |
575 | <h3><a name='FINDING_AND_ENUMERATING'>Finding and Enumerating Elements</a></h3> | |
576 | ||
577 | <p>CUPS provides several functions to find and enumerate elements in an | |
578 | array. Each one sets or updates a "current index" into the array, such that | |
579 | future lookups will start where the last one left off:</p> | |
580 | ||
581 | <dl> | |
582 | <dt><a href='#cupsArrayFind'><code>cupsArrayFind</code></a></dt> | |
79e1d494 | 583 | <dd>Returns the first matching element.</dd> |
5a738aea MS |
584 | <dt><a href='#cupsArrayFirst'><code>cupsArrayFirst</code></a></dt> |
585 | <dd>Returns the first element in the array.</dd> | |
586 | <dt><a href='#cupsArrayIndex'><code>cupsArrayIndex</code></a></dt> | |
79e1d494 | 587 | <dd>Returns the Nth element in the array, starting at 0.</dd> |
5a738aea MS |
588 | <dt><a href='#cupsArrayLast'><code>cupsArrayLast</code></a></dt> |
589 | <dd>Returns the last element in the array.</dd> | |
590 | <dt><a href='#cupsArrayNext'><code>cupsArrayNext</code></a></dt> | |
591 | <dd>Returns the next element in the array.</dd> | |
592 | <dt><a href='#cupsArrayPrev'><code>cupsArrayPrev</code></a></dt> | |
593 | <dd>Returns the previous element in the array.</dd> | |
594 | </dl> | |
595 | ||
596 | <p>Each of these functions returns <code>NULL</code> when there is no | |
597 | corresponding element. For example, a simple <code>for</code> loop using the | |
598 | <a href='#cupsArrayFirst'><code>cupsArrayFirst</code></a> and | |
599 | <a href='#cupsArrayNext'><code>cupsArrayNext</code></a> functions will | |
600 | enumerate all of the strings in our previous example:</p> | |
601 | ||
602 | <pre class='example'> | |
603 | #include <cups/array.h> | |
604 | ||
605 | /* Use strcmp() to compare strings - it will ignore the user_data pointer */ | |
606 | <a href='#cups_array_t'>cups_array_t</a> *array = <a href='#cupsArrayNew'>cupsArrayNew</a>((<a href='#cups_array_func_t'>cups_array_func_t</a>)strcmp, NULL); | |
607 | ||
608 | /* Add four strings to the array */ | |
609 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "One Fish"); | |
610 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Two Fish"); | |
611 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Red Fish"); | |
612 | <a href='#cupsArrayAdd'>cupsArrayAdd</a>(array, "Blue Fish"); | |
613 | ||
614 | /* Show all of the strings in the array */ | |
615 | char *s; | |
616 | for (s = (char *)<a href='#cupsArrayFirst'>cupsArrayFirst</a>(array); s != NULL; s = (char *)<a href='#cupsArrayNext'>cupsArrayNext</a>(array)) | |
617 | puts(s); | |
618 | </pre> | |
619 | <h2 class="title"><a name="FUNCTIONS">Functions</a></h2> | |
f3c17241 | 620 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayAdd">cupsArrayAdd</a></h3> |
5a738aea MS |
621 | <p class="description">Add an element to the array.</p> |
622 | <p class="code"> | |
623 | int cupsArrayAdd (<br> | |
624 | <a href="#cups_array_t">cups_array_t</a> *a,<br> | |
625 | void *e<br> | |
626 | );</p> | |
627 | <h4 class="parameters">Parameters</h4> | |
628 | <dl> | |
629 | <dt>a</dt> | |
630 | <dd class="description">Array</dd> | |
631 | <dt>e</dt> | |
632 | <dd class="description">Element</dd> | |
633 | </dl> | |
634 | <h4 class="returnvalue">Return Value</h4> | |
635 | <p class="description">1 on success, 0 on failure</p> | |
636 | <h4 class="discussion">Discussion</h4> | |
637 | <p class="discussion">When adding an element to a sorted array, non-unique elements are | |
79e1d494 MS |
638 | appended at the end of the run of identical elements. For unsorted arrays, |
639 | the element is appended to the end of the array. | |
5a738aea MS |
640 | |
641 | </p> | |
f3c17241 | 642 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayClear">cupsArrayClear</a></h3> |
5a738aea MS |
643 | <p class="description">Clear the array.</p> |
644 | <p class="code"> | |
645 | void cupsArrayClear (<br> | |
646 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
647 | );</p> | |
648 | <h4 class="parameters">Parameters</h4> | |
649 | <dl> | |
650 | <dt>a</dt> | |
651 | <dd class="description">Array</dd> | |
652 | </dl> | |
79e1d494 MS |
653 | <h4 class="discussion">Discussion</h4> |
654 | <p class="discussion">This function is equivalent to removing all elements in the array. | |
655 | The caller is responsible for freeing the memory used by the | |
656 | elements themselves. | |
657 | ||
658 | </p> | |
f3c17241 | 659 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayCount">cupsArrayCount</a></h3> |
5a738aea MS |
660 | <p class="description">Get the number of elements in the array.</p> |
661 | <p class="code"> | |
662 | int cupsArrayCount (<br> | |
663 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
664 | );</p> | |
665 | <h4 class="parameters">Parameters</h4> | |
666 | <dl> | |
667 | <dt>a</dt> | |
668 | <dd class="description">Array</dd> | |
669 | </dl> | |
670 | <h4 class="returnvalue">Return Value</h4> | |
671 | <p class="description">Number of elements</p> | |
f3c17241 | 672 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayCurrent">cupsArrayCurrent</a></h3> |
5a738aea MS |
673 | <p class="description">Return the current element in the array.</p> |
674 | <p class="code"> | |
675 | void *cupsArrayCurrent (<br> | |
676 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
677 | );</p> | |
678 | <h4 class="parameters">Parameters</h4> | |
679 | <dl> | |
680 | <dt>a</dt> | |
681 | <dd class="description">Array</dd> | |
682 | </dl> | |
683 | <h4 class="returnvalue">Return Value</h4> | |
684 | <p class="description">Element</p> | |
79e1d494 MS |
685 | <h4 class="discussion">Discussion</h4> |
686 | <p class="discussion">The current element is undefined until you call <a href="#cupsArrayFind"><code>cupsArrayFind</code></a>, | |
687 | <a href="#cupsArrayFirst"><code>cupsArrayFirst</code></a>, or <a href="#cupsArrayIndex"><code>cupsArrayIndex</code></a>, or <a href="#cupsArrayLast"><code>cupsArrayLast</code></a>. | |
688 | ||
689 | </p> | |
f3c17241 | 690 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayDelete">cupsArrayDelete</a></h3> |
5a738aea MS |
691 | <p class="description">Free all memory used by the array.</p> |
692 | <p class="code"> | |
693 | void cupsArrayDelete (<br> | |
694 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
695 | );</p> | |
696 | <h4 class="parameters">Parameters</h4> | |
697 | <dl> | |
698 | <dt>a</dt> | |
699 | <dd class="description">Array</dd> | |
700 | </dl> | |
79e1d494 MS |
701 | <h4 class="discussion">Discussion</h4> |
702 | <p class="discussion">The caller is responsible for freeing the memory used by the | |
703 | elements themselves. | |
704 | ||
705 | </p> | |
f3c17241 | 706 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayDup">cupsArrayDup</a></h3> |
5a738aea MS |
707 | <p class="description">Duplicate the array.</p> |
708 | <p class="code"> | |
709 | <a href="#cups_array_t">cups_array_t</a> *cupsArrayDup (<br> | |
710 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
711 | );</p> | |
712 | <h4 class="parameters">Parameters</h4> | |
713 | <dl> | |
714 | <dt>a</dt> | |
715 | <dd class="description">Array</dd> | |
716 | </dl> | |
717 | <h4 class="returnvalue">Return Value</h4> | |
718 | <p class="description">Duplicate array</p> | |
f3c17241 | 719 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayFind">cupsArrayFind</a></h3> |
5a738aea MS |
720 | <p class="description">Find an element in the array.</p> |
721 | <p class="code"> | |
722 | void *cupsArrayFind (<br> | |
723 | <a href="#cups_array_t">cups_array_t</a> *a,<br> | |
724 | void *e<br> | |
725 | );</p> | |
726 | <h4 class="parameters">Parameters</h4> | |
727 | <dl> | |
728 | <dt>a</dt> | |
729 | <dd class="description">Array</dd> | |
730 | <dt>e</dt> | |
731 | <dd class="description">Element</dd> | |
732 | </dl> | |
733 | <h4 class="returnvalue">Return Value</h4> | |
734 | <p class="description">Element found or <code>NULL</code></p> | |
f3c17241 | 735 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayFirst">cupsArrayFirst</a></h3> |
5a738aea MS |
736 | <p class="description">Get the first element in the array.</p> |
737 | <p class="code"> | |
738 | void *cupsArrayFirst (<br> | |
739 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
740 | );</p> | |
741 | <h4 class="parameters">Parameters</h4> | |
742 | <dl> | |
743 | <dt>a</dt> | |
744 | <dd class="description">Array</dd> | |
745 | </dl> | |
746 | <h4 class="returnvalue">Return Value</h4> | |
79e1d494 | 747 | <p class="description">First element or <code>NULL</code> if the array is empty</p> |
f3c17241 | 748 | <h3 class="function"><span class="info"> CUPS 1.3/OS X 10.5 </span><a name="cupsArrayGetIndex">cupsArrayGetIndex</a></h3> |
5a738aea MS |
749 | <p class="description">Get the index of the current element.</p> |
750 | <p class="code"> | |
751 | int cupsArrayGetIndex (<br> | |
752 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
753 | );</p> | |
754 | <h4 class="parameters">Parameters</h4> | |
755 | <dl> | |
756 | <dt>a</dt> | |
757 | <dd class="description">Array</dd> | |
758 | </dl> | |
759 | <h4 class="returnvalue">Return Value</h4> | |
79e1d494 MS |
760 | <p class="description">Index of the current element, starting at 0</p> |
761 | <h4 class="discussion">Discussion</h4> | |
762 | <p class="discussion">The current element is undefined until you call <a href="#cupsArrayFind"><code>cupsArrayFind</code></a>, | |
763 | <a href="#cupsArrayFirst"><code>cupsArrayFirst</code></a>, or <a href="#cupsArrayIndex"><code>cupsArrayIndex</code></a>, or <a href="#cupsArrayLast"><code>cupsArrayLast</code></a>. | |
764 | ||
765 | </p> | |
f3c17241 | 766 | <h3 class="function"><span class="info"> CUPS 1.3/OS X 10.5 </span><a name="cupsArrayGetInsert">cupsArrayGetInsert</a></h3> |
5a738aea MS |
767 | <p class="description">Get the index of the last inserted element.</p> |
768 | <p class="code"> | |
769 | int cupsArrayGetInsert (<br> | |
770 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
771 | );</p> | |
772 | <h4 class="parameters">Parameters</h4> | |
773 | <dl> | |
774 | <dt>a</dt> | |
775 | <dd class="description">Array</dd> | |
776 | </dl> | |
777 | <h4 class="returnvalue">Return Value</h4> | |
79e1d494 | 778 | <p class="description">Index of the last inserted element, starting at 0</p> |
f3c17241 | 779 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayIndex">cupsArrayIndex</a></h3> |
5a738aea MS |
780 | <p class="description">Get the N-th element in the array.</p> |
781 | <p class="code"> | |
782 | void *cupsArrayIndex (<br> | |
783 | <a href="#cups_array_t">cups_array_t</a> *a,<br> | |
784 | int n<br> | |
785 | );</p> | |
786 | <h4 class="parameters">Parameters</h4> | |
787 | <dl> | |
788 | <dt>a</dt> | |
789 | <dd class="description">Array</dd> | |
790 | <dt>n</dt> | |
791 | <dd class="description">Index into array, starting at 0</dd> | |
792 | </dl> | |
793 | <h4 class="returnvalue">Return Value</h4> | |
794 | <p class="description">N-th element or <code>NULL</code></p> | |
f3c17241 | 795 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayInsert">cupsArrayInsert</a></h3> |
5a738aea MS |
796 | <p class="description">Insert an element in the array.</p> |
797 | <p class="code"> | |
798 | int cupsArrayInsert (<br> | |
799 | <a href="#cups_array_t">cups_array_t</a> *a,<br> | |
800 | void *e<br> | |
801 | );</p> | |
802 | <h4 class="parameters">Parameters</h4> | |
803 | <dl> | |
804 | <dt>a</dt> | |
805 | <dd class="description">Array</dd> | |
806 | <dt>e</dt> | |
807 | <dd class="description">Element</dd> | |
808 | </dl> | |
809 | <h4 class="returnvalue">Return Value</h4> | |
810 | <p class="description">0 on failure, 1 on success</p> | |
811 | <h4 class="discussion">Discussion</h4> | |
812 | <p class="discussion">When inserting an element in a sorted array, non-unique elements are | |
79e1d494 MS |
813 | inserted at the beginning of the run of identical elements. For unsorted |
814 | arrays, the element is inserted at the beginning of the array. | |
5a738aea MS |
815 | |
816 | </p> | |
f3c17241 | 817 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayLast">cupsArrayLast</a></h3> |
5a738aea MS |
818 | <p class="description">Get the last element in the array.</p> |
819 | <p class="code"> | |
820 | void *cupsArrayLast (<br> | |
821 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
822 | );</p> | |
823 | <h4 class="parameters">Parameters</h4> | |
824 | <dl> | |
825 | <dt>a</dt> | |
826 | <dd class="description">Array</dd> | |
827 | </dl> | |
828 | <h4 class="returnvalue">Return Value</h4> | |
79e1d494 | 829 | <p class="description">Last element or <code>NULL</code> if the array is empty</p> |
f3c17241 | 830 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayNew">cupsArrayNew</a></h3> |
5a738aea MS |
831 | <p class="description">Create a new array.</p> |
832 | <p class="code"> | |
833 | <a href="#cups_array_t">cups_array_t</a> *cupsArrayNew (<br> | |
834 | <a href="#cups_array_func_t">cups_array_func_t</a> f,<br> | |
835 | void *d<br> | |
836 | );</p> | |
837 | <h4 class="parameters">Parameters</h4> | |
838 | <dl> | |
839 | <dt>f</dt> | |
79e1d494 | 840 | <dd class="description">Comparison function or <code>NULL</code> for an unsorted array</dd> |
5a738aea | 841 | <dt>d</dt> |
79e1d494 | 842 | <dd class="description">User data pointer or <code>NULL</code></dd> |
5a738aea MS |
843 | </dl> |
844 | <h4 class="returnvalue">Return Value</h4> | |
845 | <p class="description">Array</p> | |
79e1d494 MS |
846 | <h4 class="discussion">Discussion</h4> |
847 | <p class="discussion">The comparison function ("f") is used to create a sorted array. The function | |
848 | receives pointers to two elements and the user data pointer ("d") - the user | |
849 | data pointer argument can safely be omitted when not required so functions | |
850 | like <code>strcmp</code> can be used for sorted string arrays. | |
851 | ||
852 | </p> | |
f3c17241 | 853 | <h3 class="function"><span class="info"> CUPS 1.3/OS X 10.5 </span><a name="cupsArrayNew2">cupsArrayNew2</a></h3> |
5a738aea MS |
854 | <p class="description">Create a new array with hash.</p> |
855 | <p class="code"> | |
856 | <a href="#cups_array_t">cups_array_t</a> *cupsArrayNew2 (<br> | |
857 | <a href="#cups_array_func_t">cups_array_func_t</a> f,<br> | |
858 | void *d,<br> | |
859 | <a href="#cups_ahash_func_t">cups_ahash_func_t</a> h,<br> | |
860 | int hsize<br> | |
861 | );</p> | |
862 | <h4 class="parameters">Parameters</h4> | |
863 | <dl> | |
864 | <dt>f</dt> | |
79e1d494 | 865 | <dd class="description">Comparison function or <code>NULL</code> for an unsorted array</dd> |
5a738aea | 866 | <dt>d</dt> |
79e1d494 | 867 | <dd class="description">User data or <code>NULL</code></dd> |
5a738aea | 868 | <dt>h</dt> |
79e1d494 | 869 | <dd class="description">Hash function or <code>NULL</code> for unhashed lookups</dd> |
5a738aea | 870 | <dt>hsize</dt> |
79e1d494 | 871 | <dd class="description">Hash size (>= 0)</dd> |
5a738aea MS |
872 | </dl> |
873 | <h4 class="returnvalue">Return Value</h4> | |
874 | <p class="description">Array</p> | |
79e1d494 MS |
875 | <h4 class="discussion">Discussion</h4> |
876 | <p class="discussion">The comparison function ("f") is used to create a sorted array. The function | |
877 | receives pointers to two elements and the user data pointer ("d") - the user | |
878 | data pointer argument can safely be omitted when not required so functions | |
879 | like <code>strcmp</code> can be used for sorted string arrays.<br> | |
880 | <br> | |
881 | The hash function ("h") is used to implement cached lookups with the | |
882 | specified hash size ("hsize"). | |
883 | ||
10d09e33 | 884 | </p> |
f3c17241 | 885 | <h3 class="function"><span class="info"> CUPS 1.5/OS X 10.7 </span><a name="cupsArrayNew3">cupsArrayNew3</a></h3> |
10d09e33 MS |
886 | <p class="description">Create a new array with hash and/or free function.</p> |
887 | <p class="code"> | |
888 | <a href="#cups_array_t">cups_array_t</a> *cupsArrayNew3 (<br> | |
889 | <a href="#cups_array_func_t">cups_array_func_t</a> f,<br> | |
890 | void *d,<br> | |
891 | <a href="#cups_ahash_func_t">cups_ahash_func_t</a> h,<br> | |
892 | int hsize,<br> | |
893 | <a href="#cups_acopy_func_t">cups_acopy_func_t</a> cf,<br> | |
894 | <a href="#cups_afree_func_t">cups_afree_func_t</a> ff<br> | |
895 | );</p> | |
896 | <h4 class="parameters">Parameters</h4> | |
897 | <dl> | |
898 | <dt>f</dt> | |
899 | <dd class="description">Comparison function or <code>NULL</code> for an unsorted array</dd> | |
900 | <dt>d</dt> | |
901 | <dd class="description">User data or <code>NULL</code></dd> | |
902 | <dt>h</dt> | |
903 | <dd class="description">Hash function or <code>NULL</code> for unhashed lookups</dd> | |
904 | <dt>hsize</dt> | |
905 | <dd class="description">Hash size (>= 0)</dd> | |
906 | <dt>cf</dt> | |
907 | <dd class="description">Copy function</dd> | |
908 | <dt>ff</dt> | |
909 | <dd class="description">Free function</dd> | |
910 | </dl> | |
911 | <h4 class="returnvalue">Return Value</h4> | |
912 | <p class="description">Array</p> | |
913 | <h4 class="discussion">Discussion</h4> | |
914 | <p class="discussion">The comparison function ("f") is used to create a sorted array. The function | |
915 | receives pointers to two elements and the user data pointer ("d") - the user | |
916 | data pointer argument can safely be omitted when not required so functions | |
917 | like <code>strcmp</code> can be used for sorted string arrays.<br> | |
918 | <br> | |
919 | The hash function ("h") is used to implement cached lookups with the | |
920 | specified hash size ("hsize").<br> | |
921 | <br> | |
922 | The copy function ("cf") is used to automatically copy/retain elements when | |
923 | added or the array is copied.<br> | |
924 | <br> | |
925 | The free function ("cf") is used to automatically free/release elements when | |
926 | removed or the array is deleted. | |
927 | ||
79e1d494 | 928 | </p> |
f3c17241 | 929 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayNext">cupsArrayNext</a></h3> |
5a738aea MS |
930 | <p class="description">Get the next element in the array.</p> |
931 | <p class="code"> | |
932 | void *cupsArrayNext (<br> | |
933 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
934 | );</p> | |
935 | <h4 class="parameters">Parameters</h4> | |
936 | <dl> | |
937 | <dt>a</dt> | |
938 | <dd class="description">Array</dd> | |
939 | </dl> | |
940 | <h4 class="returnvalue">Return Value</h4> | |
941 | <p class="description">Next element or <code>NULL</code></p> | |
79e1d494 MS |
942 | <h4 class="discussion">Discussion</h4> |
943 | <p class="discussion">This function is equivalent to "cupsArrayIndex(a, cupsArrayGetIndex(a) + 1)".<br> | |
944 | <br> | |
945 | The next element is undefined until you call <a href="#cupsArrayFind"><code>cupsArrayFind</code></a>, | |
946 | <a href="#cupsArrayFirst"><code>cupsArrayFirst</code></a>, or <a href="#cupsArrayIndex"><code>cupsArrayIndex</code></a>, or <a href="#cupsArrayLast"><code>cupsArrayLast</code></a> | |
947 | to set the current element. | |
948 | ||
949 | </p> | |
f3c17241 | 950 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayPrev">cupsArrayPrev</a></h3> |
5a738aea MS |
951 | <p class="description">Get the previous element in the array.</p> |
952 | <p class="code"> | |
953 | void *cupsArrayPrev (<br> | |
954 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
955 | );</p> | |
956 | <h4 class="parameters">Parameters</h4> | |
957 | <dl> | |
958 | <dt>a</dt> | |
959 | <dd class="description">Array</dd> | |
960 | </dl> | |
961 | <h4 class="returnvalue">Return Value</h4> | |
962 | <p class="description">Previous element or <code>NULL</code></p> | |
79e1d494 MS |
963 | <h4 class="discussion">Discussion</h4> |
964 | <p class="discussion">This function is equivalent to "cupsArrayIndex(a, cupsArrayGetIndex(a) - 1)".<br> | |
965 | <br> | |
966 | The previous element is undefined until you call <a href="#cupsArrayFind"><code>cupsArrayFind</code></a>, | |
967 | <a href="#cupsArrayFirst"><code>cupsArrayFirst</code></a>, or <a href="#cupsArrayIndex"><code>cupsArrayIndex</code></a>, or <a href="#cupsArrayLast"><code>cupsArrayLast</code></a> | |
968 | to set the current element. | |
969 | ||
970 | </p> | |
f3c17241 | 971 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayRemove">cupsArrayRemove</a></h3> |
5a738aea MS |
972 | <p class="description">Remove an element from the array.</p> |
973 | <p class="code"> | |
974 | int cupsArrayRemove (<br> | |
975 | <a href="#cups_array_t">cups_array_t</a> *a,<br> | |
976 | void *e<br> | |
977 | );</p> | |
978 | <h4 class="parameters">Parameters</h4> | |
979 | <dl> | |
980 | <dt>a</dt> | |
981 | <dd class="description">Array</dd> | |
982 | <dt>e</dt> | |
983 | <dd class="description">Element</dd> | |
984 | </dl> | |
985 | <h4 class="returnvalue">Return Value</h4> | |
986 | <p class="description">1 on success, 0 on failure</p> | |
79e1d494 MS |
987 | <h4 class="discussion">Discussion</h4> |
988 | <p class="discussion">If more than one element matches "e", only the first matching element is | |
989 | removed.<br> | |
990 | <br> | |
991 | The caller is responsible for freeing the memory used by the | |
992 | removed element. | |
993 | ||
994 | </p> | |
f3c17241 | 995 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayRestore">cupsArrayRestore</a></h3> |
79e1d494 | 996 | <p class="description">Reset the current element to the last <a href="#cupsArraySave"><code>cupsArraySave</code></a>.</p> |
5a738aea MS |
997 | <p class="code"> |
998 | void *cupsArrayRestore (<br> | |
999 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
1000 | );</p> | |
1001 | <h4 class="parameters">Parameters</h4> | |
1002 | <dl> | |
1003 | <dt>a</dt> | |
1004 | <dd class="description">Array</dd> | |
1005 | </dl> | |
1006 | <h4 class="returnvalue">Return Value</h4> | |
1007 | <p class="description">New current element</p> | |
f3c17241 | 1008 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArraySave">cupsArraySave</a></h3> |
79e1d494 | 1009 | <p class="description">Mark the current element for a later <a href="#cupsArrayRestore"><code>cupsArrayRestore</code></a>.</p> |
5a738aea MS |
1010 | <p class="code"> |
1011 | int cupsArraySave (<br> | |
1012 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
1013 | );</p> | |
1014 | <h4 class="parameters">Parameters</h4> | |
1015 | <dl> | |
1016 | <dt>a</dt> | |
1017 | <dd class="description">Array</dd> | |
1018 | </dl> | |
1019 | <h4 class="returnvalue">Return Value</h4> | |
1020 | <p class="description">1 on success, 0 on failure</p> | |
1021 | <h4 class="discussion">Discussion</h4> | |
79e1d494 MS |
1022 | <p class="discussion">The current element is undefined until you call <a href="#cupsArrayFind"><code>cupsArrayFind</code></a>, |
1023 | <a href="#cupsArrayFirst"><code>cupsArrayFirst</code></a>, or <a href="#cupsArrayIndex"><code>cupsArrayIndex</code></a>, or <a href="#cupsArrayLast"><code>cupsArrayLast</code></a> | |
1024 | to set the current element.<br> | |
1025 | <br> | |
1026 | The save/restore stack is guaranteed to be at least 32 elements deep. | |
5a738aea MS |
1027 | |
1028 | </p> | |
f3c17241 | 1029 | <h3 class="function"><span class="info"> CUPS 1.2/OS X 10.5 </span><a name="cupsArrayUserData">cupsArrayUserData</a></h3> |
5a738aea MS |
1030 | <p class="description">Return the user data for an array.</p> |
1031 | <p class="code"> | |
1032 | void *cupsArrayUserData (<br> | |
1033 | <a href="#cups_array_t">cups_array_t</a> *a<br> | |
1034 | );</p> | |
1035 | <h4 class="parameters">Parameters</h4> | |
1036 | <dl> | |
1037 | <dt>a</dt> | |
1038 | <dd class="description">Array</dd> | |
1039 | </dl> | |
1040 | <h4 class="returnvalue">Return Value</h4> | |
1041 | <p class="description">User data</p> | |
1042 | <h2 class="title"><a name="TYPES">Data Types</a></h2> | |
10d09e33 MS |
1043 | <h3 class="typedef"><a name="cups_acopy_func_t">cups_acopy_func_t</a></h3> |
1044 | <p class="description">Array element copy function</p> | |
1045 | <p class="code"> | |
1046 | typedef void *(*cups_acopy_func_t)(void *element, void *data); | |
1047 | </p> | |
1048 | <h3 class="typedef"><a name="cups_afree_func_t">cups_afree_func_t</a></h3> | |
1049 | <p class="description">Array element free function</p> | |
1050 | <p class="code"> | |
1051 | typedef void (*cups_afree_func_t)(void *element, void *data); | |
1052 | </p> | |
5a738aea MS |
1053 | <h3 class="typedef"><a name="cups_ahash_func_t">cups_ahash_func_t</a></h3> |
1054 | <p class="description">Array hash function</p> | |
1055 | <p class="code"> | |
bc44d920 | 1056 | typedef int (*cups_ahash_func_t)(void *element, void *data); |
5a738aea MS |
1057 | </p> |
1058 | <h3 class="typedef"><a name="cups_array_func_t">cups_array_func_t</a></h3> | |
1059 | <p class="description">Array comparison function</p> | |
1060 | <p class="code"> | |
ef416fc2 | 1061 | typedef int (*cups_array_func_t)(void *first, void *second, void *data); |
5a738aea MS |
1062 | </p> |
1063 | <h3 class="typedef"><a name="cups_array_t">cups_array_t</a></h3> | |
1064 | <p class="description">CUPS array type</p> | |
1065 | <p class="code"> | |
ef416fc2 | 1066 | typedef struct _cups_array_s cups_array_t; |
5a738aea MS |
1067 | </p> |
1068 | </div> | |
ef416fc2 | 1069 | </body> |
1070 | </html> |