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