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