1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>Array API
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8">
8 <meta name=
"creator" content=
"Mini-XML v2.8">
9 <style type=
"text/css"><!--
11 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
14 H1, H2, H3, H4, H5, H6, P, TD, TH {
15 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
19 font-family: monaco, courier, monospace;
24 font-family: monaco, courier, monospace;
28 border: dotted thin #7f7f7f;
56 border: dotted thin #999999;
61 PRE.command EM, PRE.example EM {
62 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
66 font-family: monaco, courier, monospace;
77 border: solid thin #999999;
88 -moz-border-radius: 10px;
93 text-decoration: none;
96 A:link:hover, A:visited:hover, A:active {
97 text-decoration: underline;
104 TR.data, TD.data, TR.data TD {
107 border-bottom: solid 1pt #999999;
111 border-bottom: solid 1pt #999999;
118 border: solid thin #999999;
119 border-collapse: collapse;
135 border: solid thin #cccccc;
142 border-bottom: solid thin #999999;
151 caption-side: bottom;
175 border: thin solid black;
183 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
192 border-bottom: solid 2pt #000000;
195 DIV.indent, TABLE.indent {
203 border-collapse: collapse;
206 TABLE.indent TD, TABLE.indent TH {
211 border-collapse: collapse;
219 border-bottom: solid thin #cccccc;
224 vertical-align: bottom;
233 border-bottom: solid thin #eeeeee;
238 TABLE.list TR:nth-child(even) {
242 TABLE.list TR:nth-child(odd) {
261 font-family: monaco, courier, monospace;
265 border: solid thin #999999;
266 border-collapse: collapse;
271 DIV.summary TABLE TD, DIV.summary TABLE TH {
272 border: solid thin #999999;
278 DIV.summary TABLE THEAD TH {
282 /* API documentation styles... */
289 div.body h3, div.body h4, div.body h5 {
290 margin-bottom: 0.5em;
293 .class, .enumeration, .function, .struct, .typedef, .union {
294 border-bottom: solid thin #999999;
301 code, p.code, pre, ul.code li {
302 font-family: monaco, courier, monospace;
305 ul.code, ul.contents, ul.subcontents {
306 list-style-type: none;
316 ul.contents li ul.code, ul.contents li ul.subcontents {
329 margin-bottom: 0.5em;
332 /* This is just for the HTML files generated with the framedhelp target */
335 border: solid thin black;
344 div.contents ul.contents {
347 div.contents ul.subcontents li {
356 Array API header for CUPS.
358 Copyright 2008-2011 by Apple Inc.
360 These coded instructions, statements, and computer programs are the
361 property of Apple Inc. and are protected by Federal copyright
362 law. Distribution and use rights are outlined in the file "LICENSE.txt"
363 which should have been included with this file. If this file is
364 file is missing or damaged, see the license at "http://www.cups.org/".
367 <h1 class='title'
>Array API
</h1>
369 <div class='summary'
><table summary='General Information'
>
373 <th>cups/array.h
</th>
383 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
387 <h2 class=
"title">Contents
</h2>
388 <ul class=
"contents">
389 <li><a href=
"#OVERVIEW">Overview
</a><ul class=
"subcontents">
390 <li><a href=
"#MANAGING_ARRAYS">Managing Arrays
</a></li>
391 <li><a href=
"#FINDING_AND_ENUMERATING">Finding and Enumerating Elements
</a></li>
393 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
394 <li><a href=
"#cupsArrayAdd" title=
"Add an element to the array.">cupsArrayAdd
</a></li>
395 <li><a href=
"#cupsArrayClear" title=
"Clear the array.">cupsArrayClear
</a></li>
396 <li><a href=
"#cupsArrayCount" title=
"Get the number of elements in the array.">cupsArrayCount
</a></li>
397 <li><a href=
"#cupsArrayCurrent" title=
"Return the current element in the array.">cupsArrayCurrent
</a></li>
398 <li><a href=
"#cupsArrayDelete" title=
"Free all memory used by the array.">cupsArrayDelete
</a></li>
399 <li><a href=
"#cupsArrayDup" title=
"Duplicate the array.">cupsArrayDup
</a></li>
400 <li><a href=
"#cupsArrayFind" title=
"Find an element in the array.">cupsArrayFind
</a></li>
401 <li><a href=
"#cupsArrayFirst" title=
"Get the first element in the array.">cupsArrayFirst
</a></li>
402 <li><a href=
"#cupsArrayGetIndex" title=
"Get the index of the current element.">cupsArrayGetIndex
</a></li>
403 <li><a href=
"#cupsArrayGetInsert" title=
"Get the index of the last inserted element.">cupsArrayGetInsert
</a></li>
404 <li><a href=
"#cupsArrayIndex" title=
"Get the N-th element in the array.">cupsArrayIndex
</a></li>
405 <li><a href=
"#cupsArrayInsert" title=
"Insert an element in the array.">cupsArrayInsert
</a></li>
406 <li><a href=
"#cupsArrayLast" title=
"Get the last element in the array.">cupsArrayLast
</a></li>
407 <li><a href=
"#cupsArrayNew" title=
"Create a new array.">cupsArrayNew
</a></li>
408 <li><a href=
"#cupsArrayNew2" title=
"Create a new array with hash.">cupsArrayNew2
</a></li>
409 <li><a href=
"#cupsArrayNew3" title=
"Create a new array with hash and/or free function.">cupsArrayNew3
</a></li>
410 <li><a href=
"#cupsArrayNext" title=
"Get the next element in the array.">cupsArrayNext
</a></li>
411 <li><a href=
"#cupsArrayPrev" title=
"Get the previous element in the array.">cupsArrayPrev
</a></li>
412 <li><a href=
"#cupsArrayRemove" title=
"Remove an element from the array.">cupsArrayRemove
</a></li>
413 <li><a href=
"#cupsArrayRestore" title=
"Reset the current element to the last cupsArraySave.">cupsArrayRestore
</a></li>
414 <li><a href=
"#cupsArraySave" title=
"Mark the current element for a later cupsArrayRestore.">cupsArraySave
</a></li>
415 <li><a href=
"#cupsArrayUserData" title=
"Return the user data for an array.">cupsArrayUserData
</a></li>
417 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
418 <li><a href=
"#cups_acopy_func_t" title=
"Array element copy function">cups_acopy_func_t
</a></li>
419 <li><a href=
"#cups_afree_func_t" title=
"Array element free function">cups_afree_func_t
</a></li>
420 <li><a href=
"#cups_ahash_func_t" title=
"Array hash function">cups_ahash_func_t
</a></li>
421 <li><a href=
"#cups_array_func_t" title=
"Array comparison function">cups_array_func_t
</a></li>
422 <li><a href=
"#cups_array_t" title=
"CUPS array type">cups_array_t
</a></li>
426 Array API introduction for CUPS.
428 Copyright 2007-2011 by Apple Inc.
429 Copyright 1997-2006 by Easy Software Products, all rights reserved.
431 These coded instructions, statements, and computer programs are the
432 property of Apple Inc. and are protected by Federal copyright
433 law. Distribution and use rights are outlined in the file "LICENSE.txt"
434 which should have been included with this file. If this file is
435 file is missing or damaged, see the license at "http://www.cups.org/".
438 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
440 <p>The CUPS array API provides a high-performance generic array container.
441 The contents of the array container can be sorted and the container itself is
442 designed for optimal speed and memory usage under a wide variety of conditions.
443 Sorted arrays use a binary search algorithm from the last found or inserted
444 element to quickly find matching elements in the array. Arrays created with the
445 optional hash function can often find elements with a single lookup. The
446 <a href='#cups_array_t'
><code>cups_array_t
</code></a> type is used when
447 referring to a CUPS array.
</p>
449 <p>The CUPS scheduler (
<tt>cupsd
</tt>) and many of the CUPS API
450 functions use the array API to efficiently manage large lists of
453 <h3><a name='MANAGING_ARRAYS'
>Managing Arrays
</a></h3>
455 <p>Arrays are created using either the
456 <a href='#cupsArrayNew'
><code>cupsArrayNew
</code></a>,
457 <a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a>, or
458 <a href='#cupsArrayNew2'
><code>cupsArrayNew3
</code></a> functions. The
459 first function creates a new array with the specified callback function
460 and user data pointer:
</p>
462 <pre class='example'
>
463 #include
<cups/array.h
>
465 static int compare_func(void *first, void *second, void *user_data);
468 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>(compare_func, user_data);
471 <p>The comparison function (type
472 <a href=
"#cups_arrayfunc_t"><code>cups_arrayfunc_t
</code></a>) is called
473 whenever an element is added to the array and can be
<code>NULL
</code> to
474 create an unsorted array. The function returns -
1 if the first element should
475 come before the second,
0 if the first and second elements should have the same
476 ordering, and
1 if the first element should come after the second.
</p>
478 <p>The
"user_data" pointer is passed to your comparison function. Pass
479 <code>NULL
</code> if you do not need to associate the elements in your array
480 with additional information.
</p>
482 <p>The
<a href='#cupsArrayNew2'
><code>cupsArrayNew2
</code></a> function adds
483 two more arguments to support hashed lookups, which can potentially provide
484 instantaneous (
"O(1)") lookups in your array:
</p>
486 <pre class='example'
>
487 #include
<cups/array.h
>
489 #define HASH_SIZE
512 /* Size of hash table */
491 static int compare_func(void *first, void *second, void *user_data);
492 static int hash_func(void *element, void *user_data);
495 <a href='#cups_array_t'
>cups_array_t
</a> *hash_array =
<a href='#cupsArrayNew2'
>cupsArrayNew2
</a>(compare_func, user_data, hash_func, HASH_SIZE);
498 <p>The hash function (type
499 <a href=
"#cups_ahash_func_t"><code>cups_ahash_func_t
</code></a>) should return a
500 number from
0 to (hash_size-
1) that (hopefully) uniquely identifies the
501 element and is called whenever you look up an element in the array with
502 <a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a>. The hash size is
503 only limited by available memory, but generally should not be larger than
504 16384 to realize any performance improvement.
</p>
506 <p>The
<a href='#cupsArrayNew3'
><code>cupsArrayNew3
</code></a> function adds
507 copy and free callbacks to support basic memory management of elements:
</p>
509 <pre class='example'
>
510 #include
<cups/array.h
>
512 #define HASH_SIZE
512 /* Size of hash table */
514 static int compare_func(void *first, void *second, void *user_data);
515 static void *copy_func(void *element, void *user_data);
516 static void free_func(void *element, void *user_data);
517 static int hash_func(void *element, void *user_data);
520 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew3'
>cupsArrayNew3
</a>(compare_func, user_data, NULL,
0, copy_func, free_func);
522 <a href='#cups_array_t'
>cups_array_t
</a> *hash_array =
<a href='#cupsArrayNew3'
>cupsArrayNew3
</a>(compare_func, user_data, hash_func, HASH_SIZE, copy_func, free_func);
525 <p>Once you have created the array, you add elements using the
526 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a>
527 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> functions.
528 The first function adds an element to the array, adding the new element
529 after any elements that have the same order, while the second inserts the
530 element before others with the same order. For unsorted arrays,
531 <a href='#cupsArrayAdd'
><code>cupsArrayAdd
</code></a> appends the element to
532 the end of the array while
533 <a href='#cupsArrayInsert'
><code>cupsArrayInsert
</code></a> inserts the
534 element at the beginning of the array. For example, the following code
535 creates a sorted array of character strings:
</p>
537 <pre class='example'
>
538 #include
<cups/array.h
>
540 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
541 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
543 /* Add four strings to the array */
544 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
545 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
546 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
547 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
550 <p>Elements are removed using the
551 <a href='#cupsArrayRemove'
><code>cupsArrayRemove
</code></a> function, for
554 <pre class='example'
>
555 #include
<cups/array.h
>
557 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
558 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
560 /* Add four strings to the array */
561 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
562 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
563 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
564 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
566 /* Remove
"Red Fish" */
567 <a href='#cupsArrayRemove'
>cupsArrayRemove
</a>(array,
"Red Fish");
570 <p>Finally, you free the memory used by the array using the
571 <a href='#cupsArrayDelete'
><code>cupsArrayDelete
</code></a> function. All
572 of the memory for the array and hash table (if any) is freed, however
<em>CUPS
573 does not free the elements unless you provide copy and free functions
</em>.
</p>
575 <h3><a name='FINDING_AND_ENUMERATING'
>Finding and Enumerating Elements
</a></h3>
577 <p>CUPS provides several functions to find and enumerate elements in an
578 array. Each one sets or updates a
"current index" into the array, such that
579 future lookups will start where the last one left off:
</p>
582 <dt><a href='#cupsArrayFind'
><code>cupsArrayFind
</code></a></dt>
583 <dd>Returns the first matching element.
</dd>
584 <dt><a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a></dt>
585 <dd>Returns the first element in the array.
</dd>
586 <dt><a href='#cupsArrayIndex'
><code>cupsArrayIndex
</code></a></dt>
587 <dd>Returns the Nth element in the array, starting at
0.
</dd>
588 <dt><a href='#cupsArrayLast'
><code>cupsArrayLast
</code></a></dt>
589 <dd>Returns the last element in the array.
</dd>
590 <dt><a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a></dt>
591 <dd>Returns the next element in the array.
</dd>
592 <dt><a href='#cupsArrayPrev'
><code>cupsArrayPrev
</code></a></dt>
593 <dd>Returns the previous element in the array.
</dd>
596 <p>Each of these functions returns
<code>NULL
</code> when there is no
597 corresponding element. For example, a simple
<code>for
</code> loop using the
598 <a href='#cupsArrayFirst'
><code>cupsArrayFirst
</code></a> and
599 <a href='#cupsArrayNext'
><code>cupsArrayNext
</code></a> functions will
600 enumerate all of the strings in our previous example:
</p>
602 <pre class='example'
>
603 #include
<cups/array.h
>
605 /* Use strcmp() to compare strings - it will ignore the user_data pointer */
606 <a href='#cups_array_t'
>cups_array_t
</a> *array =
<a href='#cupsArrayNew'
>cupsArrayNew
</a>((
<a href='#cups_array_func_t'
>cups_array_func_t
</a>)strcmp, NULL);
608 /* Add four strings to the array */
609 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"One Fish");
610 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Two Fish");
611 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Red Fish");
612 <a href='#cupsArrayAdd'
>cupsArrayAdd
</a>(array,
"Blue Fish");
614 /* Show all of the strings in the array */
616 for (s = (char *)
<a href='#cupsArrayFirst'
>cupsArrayFirst
</a>(array); s != NULL; s = (char *)
<a href='#cupsArrayNext'
>cupsArrayNext
</a>(array))
619 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
620 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayAdd">cupsArrayAdd
</a></h3>
621 <p class=
"description">Add an element to the array.
</p>
623 int cupsArrayAdd (
<br>
624 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
625 void *e
<br>
627 <h4 class=
"parameters">Parameters
</h4>
630 <dd class=
"description">Array
</dd>
632 <dd class=
"description">Element
</dd>
634 <h4 class=
"returnvalue">Return Value
</h4>
635 <p class=
"description">1 on success,
0 on failure
</p>
636 <h4 class=
"discussion">Discussion
</h4>
637 <p class=
"discussion">When adding an element to a sorted array, non-unique elements are
638 appended at the end of the run of identical elements. For unsorted arrays,
639 the element is appended to the end of the array.
642 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayClear">cupsArrayClear
</a></h3>
643 <p class=
"description">Clear the array.
</p>
645 void cupsArrayClear (
<br>
646 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
648 <h4 class=
"parameters">Parameters
</h4>
651 <dd class=
"description">Array
</dd>
653 <h4 class=
"discussion">Discussion
</h4>
654 <p class=
"discussion">This function is equivalent to removing all elements in the array.
655 The caller is responsible for freeing the memory used by the
659 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayCount">cupsArrayCount
</a></h3>
660 <p class=
"description">Get the number of elements in the array.
</p>
662 int cupsArrayCount (
<br>
663 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
665 <h4 class=
"parameters">Parameters
</h4>
668 <dd class=
"description">Array
</dd>
670 <h4 class=
"returnvalue">Return Value
</h4>
671 <p class=
"description">Number of elements
</p>
672 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayCurrent">cupsArrayCurrent
</a></h3>
673 <p class=
"description">Return the current element in the array.
</p>
675 void *cupsArrayCurrent (
<br>
676 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
678 <h4 class=
"parameters">Parameters
</h4>
681 <dd class=
"description">Array
</dd>
683 <h4 class=
"returnvalue">Return Value
</h4>
684 <p class=
"description">Element
</p>
685 <h4 class=
"discussion">Discussion
</h4>
686 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
687 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
690 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayDelete">cupsArrayDelete
</a></h3>
691 <p class=
"description">Free all memory used by the array.
</p>
693 void cupsArrayDelete (
<br>
694 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
696 <h4 class=
"parameters">Parameters
</h4>
699 <dd class=
"description">Array
</dd>
701 <h4 class=
"discussion">Discussion
</h4>
702 <p class=
"discussion">The caller is responsible for freeing the memory used by the
706 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayDup">cupsArrayDup
</a></h3>
707 <p class=
"description">Duplicate the array.
</p>
709 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayDup (
<br>
710 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
712 <h4 class=
"parameters">Parameters
</h4>
715 <dd class=
"description">Array
</dd>
717 <h4 class=
"returnvalue">Return Value
</h4>
718 <p class=
"description">Duplicate array
</p>
719 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayFind">cupsArrayFind
</a></h3>
720 <p class=
"description">Find an element in the array.
</p>
722 void *cupsArrayFind (
<br>
723 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
724 void *e
<br>
726 <h4 class=
"parameters">Parameters
</h4>
729 <dd class=
"description">Array
</dd>
731 <dd class=
"description">Element
</dd>
733 <h4 class=
"returnvalue">Return Value
</h4>
734 <p class=
"description">Element found or
<code>NULL
</code></p>
735 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayFirst">cupsArrayFirst
</a></h3>
736 <p class=
"description">Get the first element in the array.
</p>
738 void *cupsArrayFirst (
<br>
739 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
741 <h4 class=
"parameters">Parameters
</h4>
744 <dd class=
"description">Array
</dd>
746 <h4 class=
"returnvalue">Return Value
</h4>
747 <p class=
"description">First element or
<code>NULL
</code> if the array is empty
</p>
748 <h3 class=
"function"><span class=
"info"> CUPS
1.3/OS X
10.5 </span><a name=
"cupsArrayGetIndex">cupsArrayGetIndex
</a></h3>
749 <p class=
"description">Get the index of the current element.
</p>
751 int cupsArrayGetIndex (
<br>
752 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
754 <h4 class=
"parameters">Parameters
</h4>
757 <dd class=
"description">Array
</dd>
759 <h4 class=
"returnvalue">Return Value
</h4>
760 <p class=
"description">Index of the current element, starting at
0</p>
761 <h4 class=
"discussion">Discussion
</h4>
762 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
763 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>.
766 <h3 class=
"function"><span class=
"info"> CUPS
1.3/OS X
10.5 </span><a name=
"cupsArrayGetInsert">cupsArrayGetInsert
</a></h3>
767 <p class=
"description">Get the index of the last inserted element.
</p>
769 int cupsArrayGetInsert (
<br>
770 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
772 <h4 class=
"parameters">Parameters
</h4>
775 <dd class=
"description">Array
</dd>
777 <h4 class=
"returnvalue">Return Value
</h4>
778 <p class=
"description">Index of the last inserted element, starting at
0</p>
779 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayIndex">cupsArrayIndex
</a></h3>
780 <p class=
"description">Get the N-th element in the array.
</p>
782 void *cupsArrayIndex (
<br>
783 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
784 int n
<br>
786 <h4 class=
"parameters">Parameters
</h4>
789 <dd class=
"description">Array
</dd>
791 <dd class=
"description">Index into array, starting at
0</dd>
793 <h4 class=
"returnvalue">Return Value
</h4>
794 <p class=
"description">N-th element or
<code>NULL
</code></p>
795 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayInsert">cupsArrayInsert
</a></h3>
796 <p class=
"description">Insert an element in the array.
</p>
798 int cupsArrayInsert (
<br>
799 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
800 void *e
<br>
802 <h4 class=
"parameters">Parameters
</h4>
805 <dd class=
"description">Array
</dd>
807 <dd class=
"description">Element
</dd>
809 <h4 class=
"returnvalue">Return Value
</h4>
810 <p class=
"description">0 on failure,
1 on success
</p>
811 <h4 class=
"discussion">Discussion
</h4>
812 <p class=
"discussion">When inserting an element in a sorted array, non-unique elements are
813 inserted at the beginning of the run of identical elements. For unsorted
814 arrays, the element is inserted at the beginning of the array.
817 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayLast">cupsArrayLast
</a></h3>
818 <p class=
"description">Get the last element in the array.
</p>
820 void *cupsArrayLast (
<br>
821 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
823 <h4 class=
"parameters">Parameters
</h4>
826 <dd class=
"description">Array
</dd>
828 <h4 class=
"returnvalue">Return Value
</h4>
829 <p class=
"description">Last element or
<code>NULL
</code> if the array is empty
</p>
830 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayNew">cupsArrayNew
</a></h3>
831 <p class=
"description">Create a new array.
</p>
833 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew (
<br>
834 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
835 void *d
<br>
837 <h4 class=
"parameters">Parameters
</h4>
840 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
842 <dd class=
"description">User data pointer or
<code>NULL
</code></dd>
844 <h4 class=
"returnvalue">Return Value
</h4>
845 <p class=
"description">Array
</p>
846 <h4 class=
"discussion">Discussion
</h4>
847 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
848 receives pointers to two elements and the user data pointer (
"d
") - the user
849 data pointer argument can safely be omitted when not required so functions
850 like
<code>strcmp
</code> can be used for sorted string arrays.
853 <h3 class=
"function"><span class=
"info"> CUPS
1.3/OS X
10.5 </span><a name=
"cupsArrayNew2">cupsArrayNew2
</a></h3>
854 <p class=
"description">Create a new array with hash.
</p>
856 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew2 (
<br>
857 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
858 void *d,
<br>
859 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
860 int hsize
<br>
862 <h4 class=
"parameters">Parameters
</h4>
865 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
867 <dd class=
"description">User data or
<code>NULL
</code></dd>
869 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
871 <dd class=
"description">Hash size (
>=
0)
</dd>
873 <h4 class=
"returnvalue">Return Value
</h4>
874 <p class=
"description">Array
</p>
875 <h4 class=
"discussion">Discussion
</h4>
876 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
877 receives pointers to two elements and the user data pointer (
"d
") - the user
878 data pointer argument can safely be omitted when not required so functions
879 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
881 The hash function (
"h
") is used to implement cached lookups with the
882 specified hash size (
"hsize
").
885 <h3 class=
"function"><span class=
"info"> CUPS
1.5/OS X
10.7 </span><a name=
"cupsArrayNew3">cupsArrayNew3
</a></h3>
886 <p class=
"description">Create a new array with hash and/or free function.
</p>
888 <a href=
"#cups_array_t">cups_array_t
</a> *cupsArrayNew3 (
<br>
889 <a href=
"#cups_array_func_t">cups_array_func_t
</a> f,
<br>
890 void *d,
<br>
891 <a href=
"#cups_ahash_func_t">cups_ahash_func_t
</a> h,
<br>
892 int hsize,
<br>
893 <a href=
"#cups_acopy_func_t">cups_acopy_func_t
</a> cf,
<br>
894 <a href=
"#cups_afree_func_t">cups_afree_func_t
</a> ff
<br>
896 <h4 class=
"parameters">Parameters
</h4>
899 <dd class=
"description">Comparison function or
<code>NULL
</code> for an unsorted array
</dd>
901 <dd class=
"description">User data or
<code>NULL
</code></dd>
903 <dd class=
"description">Hash function or
<code>NULL
</code> for unhashed lookups
</dd>
905 <dd class=
"description">Hash size (
>=
0)
</dd>
907 <dd class=
"description">Copy function
</dd>
909 <dd class=
"description">Free function
</dd>
911 <h4 class=
"returnvalue">Return Value
</h4>
912 <p class=
"description">Array
</p>
913 <h4 class=
"discussion">Discussion
</h4>
914 <p class=
"discussion">The comparison function (
"f
") is used to create a sorted array. The function
915 receives pointers to two elements and the user data pointer (
"d
") - the user
916 data pointer argument can safely be omitted when not required so functions
917 like
<code>strcmp
</code> can be used for sorted string arrays.
<br>
919 The hash function (
"h
") is used to implement cached lookups with the
920 specified hash size (
"hsize
").
<br>
922 The copy function (
"cf
") is used to automatically copy/retain elements when
923 added or the array is copied.
<br>
925 The free function (
"cf
") is used to automatically free/release elements when
926 removed or the array is deleted.
929 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayNext">cupsArrayNext
</a></h3>
930 <p class=
"description">Get the next element in the array.
</p>
932 void *cupsArrayNext (
<br>
933 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
935 <h4 class=
"parameters">Parameters
</h4>
938 <dd class=
"description">Array
</dd>
940 <h4 class=
"returnvalue">Return Value
</h4>
941 <p class=
"description">Next element or
<code>NULL
</code></p>
942 <h4 class=
"discussion">Discussion
</h4>
943 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) +
1)
".
<br>
945 The next element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
946 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
947 to set the current element.
950 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayPrev">cupsArrayPrev
</a></h3>
951 <p class=
"description">Get the previous element in the array.
</p>
953 void *cupsArrayPrev (
<br>
954 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
956 <h4 class=
"parameters">Parameters
</h4>
959 <dd class=
"description">Array
</dd>
961 <h4 class=
"returnvalue">Return Value
</h4>
962 <p class=
"description">Previous element or
<code>NULL
</code></p>
963 <h4 class=
"discussion">Discussion
</h4>
964 <p class=
"discussion">This function is equivalent to
"cupsArrayIndex(a, cupsArrayGetIndex(a) -
1)
".
<br>
966 The previous element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
967 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
968 to set the current element.
971 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayRemove">cupsArrayRemove
</a></h3>
972 <p class=
"description">Remove an element from the array.
</p>
974 int cupsArrayRemove (
<br>
975 <a href=
"#cups_array_t">cups_array_t
</a> *a,
<br>
976 void *e
<br>
978 <h4 class=
"parameters">Parameters
</h4>
981 <dd class=
"description">Array
</dd>
983 <dd class=
"description">Element
</dd>
985 <h4 class=
"returnvalue">Return Value
</h4>
986 <p class=
"description">1 on success,
0 on failure
</p>
987 <h4 class=
"discussion">Discussion
</h4>
988 <p class=
"discussion">If more than one element matches
"e
", only the first matching element is
991 The caller is responsible for freeing the memory used by the
995 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayRestore">cupsArrayRestore
</a></h3>
996 <p class=
"description">Reset the current element to the last
<a href=
"#cupsArraySave"><code>cupsArraySave
</code></a>.
</p>
998 void *cupsArrayRestore (
<br>
999 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
1001 <h4 class=
"parameters">Parameters
</h4>
1004 <dd class=
"description">Array
</dd>
1006 <h4 class=
"returnvalue">Return Value
</h4>
1007 <p class=
"description">New current element
</p>
1008 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArraySave">cupsArraySave
</a></h3>
1009 <p class=
"description">Mark the current element for a later
<a href=
"#cupsArrayRestore"><code>cupsArrayRestore
</code></a>.
</p>
1011 int cupsArraySave (
<br>
1012 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
1014 <h4 class=
"parameters">Parameters
</h4>
1017 <dd class=
"description">Array
</dd>
1019 <h4 class=
"returnvalue">Return Value
</h4>
1020 <p class=
"description">1 on success,
0 on failure
</p>
1021 <h4 class=
"discussion">Discussion
</h4>
1022 <p class=
"discussion">The current element is undefined until you call
<a href=
"#cupsArrayFind"><code>cupsArrayFind
</code></a>,
1023 <a href=
"#cupsArrayFirst"><code>cupsArrayFirst
</code></a>, or
<a href=
"#cupsArrayIndex"><code>cupsArrayIndex
</code></a>, or
<a href=
"#cupsArrayLast"><code>cupsArrayLast
</code></a>
1024 to set the current element.
<br>
1026 The save/restore stack is guaranteed to be at least
32 elements deep.
1029 <h3 class=
"function"><span class=
"info"> CUPS
1.2/OS X
10.5 </span><a name=
"cupsArrayUserData">cupsArrayUserData
</a></h3>
1030 <p class=
"description">Return the user data for an array.
</p>
1032 void *cupsArrayUserData (
<br>
1033 <a href=
"#cups_array_t">cups_array_t
</a> *a
<br>
1035 <h4 class=
"parameters">Parameters
</h4>
1038 <dd class=
"description">Array
</dd>
1040 <h4 class=
"returnvalue">Return Value
</h4>
1041 <p class=
"description">User data
</p>
1042 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
1043 <h3 class=
"typedef"><a name=
"cups_acopy_func_t">cups_acopy_func_t
</a></h3>
1044 <p class=
"description">Array element copy function
</p>
1046 typedef void *(*cups_acopy_func_t)(void *element, void *data);
1048 <h3 class=
"typedef"><a name=
"cups_afree_func_t">cups_afree_func_t
</a></h3>
1049 <p class=
"description">Array element free function
</p>
1051 typedef void (*cups_afree_func_t)(void *element, void *data);
1053 <h3 class=
"typedef"><a name=
"cups_ahash_func_t">cups_ahash_func_t
</a></h3>
1054 <p class=
"description">Array hash function
</p>
1056 typedef int (*cups_ahash_func_t)(void *element, void *data);
1058 <h3 class=
"typedef"><a name=
"cups_array_func_t">cups_array_func_t
</a></h3>
1059 <p class=
"description">Array comparison function
</p>
1061 typedef int (*cups_array_func_t)(void *first, void *second, void *data);
1063 <h3 class=
"typedef"><a name=
"cups_array_t">cups_array_t
</a></h3>
1064 <p class=
"description">CUPS array type
</p>
1066 typedef struct _cups_array_s cups_array_t;