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