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