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