1 .\" $NetBSD: prop_array.3,v 1.10 2009/10/10 18:06:54 bad Exp $
3 .\" Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nm prop_array_create ,
36 .Nm prop_array_create_with_capacity ,
38 .Nm prop_array_copy_mutable ,
39 .Nm prop_array_capacity ,
40 .Nm prop_array_count ,
41 .Nm prop_array_ensure_capacity ,
42 .Nm prop_array_iterator ,
43 .Nm prop_array_make_immutable ,
44 .Nm prop_array_mutable ,
48 .Nm prop_array_remove ,
49 .Nm prop_array_externalize ,
50 .Nm prop_array_internalize ,
51 .Nm prop_array_externalize_to_file ,
52 .Nm prop_array_internalize_from_file ,
53 .Nm prop_array_externalize_to_pref ,
55 .Nd array property collection object
62 .Fn prop_array_create "void"
64 .Fn prop_array_create_with_capacity "unsigned int capacity"
67 .Fn prop_array_copy "prop_array_t array"
69 .Fn prop_array_copy_mutable "prop_array_t array"
72 .Fn prop_array_capacity "prop_array_t array"
74 .Fn prop_array_count "prop_array_t array"
76 .Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
78 .Ft prop_object_iterator_t
79 .Fn prop_array_iterator "prop_array_t array"
82 .Fn prop_array_make_immutable "prop_array_t array"
84 .Fn prop_array_mutable "prop_array_t array"
87 .Fn prop_array_get "prop_array_t array" "unsigned int index"
89 .Fn prop_array_set "prop_array_t array" "unsigned int index" "prop_object_t obj"
91 .Fn prop_array_add "prop_array_t array" "prop_object_t obj"
93 .Fn prop_array_remove "prop_array_t array" "unsigned int index"
96 .Fn prop_array_externalize "prop_array_t array"
98 .Fn prop_array_internalize "const char *xml"
101 .Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
103 .Fn prop_array_internalize_from_file "const char *path"
106 .Fn prop_array_externalize_to_pref "prop_array_t array" "struct plistref *pref"
109 .Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
113 family of functions operate on the array property collection object type.
114 An array is an ordered set; an iterated array will return objects in the
115 same order with which they were stored.
116 .Bl -tag -width "xxxxx"
117 .It Fn prop_array_create "void"
118 Create an empty array.
119 The array initially has no capacity.
123 .It Fn prop_array_create_with_capacity "unsigned int capacity"
124 Create an array with the capacity to store
130 .It Fn prop_array_copy "prop_array_t array"
132 The new array has an initial capacity equal to the number of objects stored
133 in the array being copied.
134 The new array contains references to the original array's objects, not
135 copies of those objects
136 .Pq i.e. a shallow copy is made .
137 If the original array is immutable, the resulting array is also immutable.
141 .It Fn prop_array_copy_mutable "prop_array_t array"
143 .Fn prop_array_copy ,
144 except the resulting array is always mutable.
145 .It Fn prop_array_capacity "prop_array_t array"
146 Returns the total capacity of the array, including objects already stored
148 If the supplied object isn't an array, zero is returned.
149 .It Fn prop_array_count "prop_array_t array"
150 Returns the number of objects stored in the array.
151 If the supplied object isn't an array, zero is returned.
152 .It Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
153 Ensure that the array has a total capacity of
155 including objects already stored in the array.
158 if the capacity of the array is greater or equal to
160 or if expansion of the array's capacity was successful
164 .It Fn prop_array_iterator "prop_array_t array"
165 Create an iterator for the array.
166 The array is retained by the iterator.
167 An array iterator returns the object references stored in the array.
168 Storing to or removing from the array invalidates any active iterators for
173 .It Fn prop_array_make_immutable "prop_array_t array"
177 .It Fn prop_array_mutable "prop_array_t array"
180 if the array is mutable.
181 .It Fn prop_array_get "prop_array_t array" "unsigned int index"
182 Return the object stored at the array index
187 .It Fn prop_array_set "prop_array_t array" "unsigned int index" \
189 Store a reference to the object
193 This function is not allowed to create holes in the array;
194 the caller must either be setting the object just beyond the existing
195 count or replacing an already existing object reference.
196 The object will be retained by the array.
197 If an existing object reference is being replaced, that object will be
201 if storing the object was successful and
204 .It Fn prop_array_add "prop_array_t array" "prop_object_t obj"
205 Add a reference to the object
207 to the array, appending to the end and growing the array's capacity if
209 The object will be retained by the array.
212 if storing the object was successful and
216 During expansion, array's capacity is augmented by the
218 constant, as defined in
219 .Pa libprop/prop_array.c
222 .Dl #define EXPAND_STEP 16
223 .It Fn prop_array_remove "prop_array_t array" "unsigned int index"
224 Remove the reference to the object stored at array index
226 The object will be released and the array compacted following
228 .It Fn prop_array_externalize "prop_array_t array"
229 Externalizes an array, returning a NUL-terminated buffer containing
230 the XML representation of the array.
231 The caller is responsible for freeing the returned buffer.
232 If converting to the external representation fails for any reason,
236 In user space, the buffer is allocated using
238 In the kernel, the buffer is allocated using
240 using the malloc type
242 .It Fn prop_array_internalize "const char *xml"
243 Parse the XML representation of a property list in the NUL-terminated
246 and return the corresponding array.
249 if parsing fails for any reason.
250 .It Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
251 Externalizes an array and writes it to the file specified by
253 The file is saved with the mode
255 as modified by the process's file creation mask
257 and is written atomically.
260 if externalizing or writing the array fails for any reason.
261 .It Fn prop_array_internalize_from_file "const char *path"
262 Reads the XML property list contained in the file specified by
264 internalizes it, and returns the corresponding array.
268 .It Fn prop_array_externalize_to_pref "prop_array_t array" \
269 "struct plistref *pref"
270 Externalizes an array and packs it into the plistref specified by
274 if externalizing the array fails for any reason.
275 .It Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
278 if the two arrays are equivalent.
279 If at least one of the supplied objects isn't an array,
282 Note: Objects contained in the array are compared by value, not by reference.
287 .Xr prop_dictionary 3 ,
295 property container object library first appeared in