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