1 .\" $NetBSD: prop_array.3,v 1.8 2008/04/30 13:10:46 martin Exp $
3 .\" Copyright (c) 2006 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 ,
54 .Nd array property collection object
61 .Fn prop_array_create "void"
63 .Fn prop_array_create_with_capacity "unsigned int capacity"
66 .Fn prop_array_copy "prop_array_t array"
68 .Fn prop_array_copy_mutable "prop_array_t array"
71 .Fn prop_array_capacity "prop_array_t array"
73 .Fn prop_array_count "prop_array_t array"
75 .Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
77 .Ft prop_object_iterator_t
78 .Fn prop_array_iterator "prop_array_t array"
81 .Fn prop_array_make_immutable "prop_array_t array"
83 .Fn prop_array_mutable "prop_array_t array"
86 .Fn prop_array_get "prop_array_t array" "unsigned int index"
88 .Fn prop_array_set "prop_array_t array" "unsigned int index" "prop_object_t obj"
90 .Fn prop_array_add "prop_array_t array" "prop_object_t obj"
92 .Fn prop_array_remove "prop_array_t array" "unsigned int index"
95 .Fn prop_array_externalize "prop_array_t array"
97 .Fn prop_array_internalize "const char *xml"
100 .Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
102 .Fn prop_array_internalize_from_file "const char *path"
105 .Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
109 family of functions operate on the array property collection object type.
110 An array is an ordered set; an iterated array will return objects in the
111 same order with which they were stored.
112 .Bl -tag -width "xxxxx"
113 .It Fn prop_array_create "void"
114 Create an empty array.
115 The array initially has no capacity.
119 .It Fn prop_array_create_with_capacity "unsigned int capacity"
120 Create an array with the capacity to store
126 .It Fn prop_array_copy "prop_array_t array"
128 The new array has an initial capacity equal to the number of objects stored
129 in the array being copied.
130 The new array contains references to the original array's objects, not
131 copies of those objects
132 .Pq i.e. a shallow copy is made .
133 If the original array is immutable, the resulting array is also immutable.
137 .It Fn prop_array_copy_mutable "prop_array_t array"
139 .Fn prop_array_copy ,
140 except the resulting array is always mutable.
141 .It Fn prop_array_capacity "prop_array_t array"
142 Returns the total capacity of the array, including objects already stored
144 If the supplied object isn't an array, zero is returned.
145 .It Fn prop_array_count "prop_array_t array"
146 Returns the number of objects stored in the array.
147 If the supplied object isn't an array, zero is returned.
148 .It Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
149 Ensure that the array has a total capacity of
151 including objects already stored in the array.
154 if the capacity of the array is greater or equal to
156 or if expansion of the array's capacity was successful
160 .It Fn prop_array_iterator "prop_array_t array"
161 Create an iterator for the array.
162 The array is retained by the iterator.
163 An array iterator returns the object references stored in the array.
164 Storing to or removing from the array invalidates any active iterators for
169 .It Fn prop_array_make_immutable "prop_array_t array"
173 .It Fn prop_array_mutable "prop_array_t array"
176 if the array is mutable.
177 .It Fn prop_array_get "prop_array_t array" "unsigned int index"
178 Return the object stored at the array index
183 .It Fn prop_array_set "prop_array_t array" "unsigned int index" \
185 Store a reference to the object
189 This function is not allowed to create holes in the array;
190 the caller must either be setting the object just beyond the existing
191 count or replacing an already existing object reference.
192 The object will be retained by the array.
193 If an existing object reference is being replaced, that object will be
197 if storing the object was successful and
200 .It Fn prop_array_add "prop_array_t array" "prop_object_t obj"
201 Add a reference to the object
203 to the array, appending to the end and growing the array's capacity if
205 The object will be retained by the array.
208 if storing the object was successful and
212 During expansion, array's capacity is augmented by the
214 constant, as defined in
215 .Pa libprop/prop_array.c
218 #define EXPAND_STEP 16
219 .It Fn prop_array_remove "prop_array_t array" "unsigned int index"
220 Remove the reference to the object stored at array index
222 The object will be released and the array compacted following
224 .It Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
227 if the two arrays are equivalent.
228 If at least one of the supplied objects isn't an array,
231 Note: Objects contained in the array are compared by value, not by reference.
232 .It Fn prop_array_externalize "prop_array_t array"
233 Externalizes an array, returning a NUL-terminated buffer containing
234 the XML representation of the array.
235 The caller is responsible for freeing the returned buffer.
236 If converting to the external representation fails for any reason,
240 In user space, the buffer is allocated using
242 In the kernel, the buffer is allocated using
244 using the malloc type
246 .It Fn prop_array_internalize "const char *xml"
247 Parse the XML representation of a property list in the NUL-terminated
250 and return the corresponding array.
253 if parsing fails for any reason.
254 .It Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
255 Externalizes an array and writes it to the file specified by
257 The file is saved with the mode
259 as modified by the process's file creation mask
261 and is written atomically.
264 if externalizing or writing the array fails for any reason.
265 .It Fn prop_array_internalize_from_file "const char *path"
266 Reads the XML property list contained in the file specified by
268 internalizes it, and returns the corresponding array.
276 .Xr prop_dictionary 3 ,
284 property container object library first appeared in