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