xref: /minix3/common/lib/libprop/prop_array.3 (revision 6b6d114a21a24bee45291fa4af8899e108396c4a)
1*6b6d114aSBen Gras.\"	$NetBSD: prop_array.3,v 1.13 2011/09/30 22:08:18 jym Exp $
2*6b6d114aSBen Gras.\"
3*6b6d114aSBen Gras.\" Copyright (c) 2006, 2009 The NetBSD Foundation, Inc.
4*6b6d114aSBen Gras.\" All rights reserved.
5*6b6d114aSBen Gras.\"
6*6b6d114aSBen Gras.\" This code is derived from software contributed to The NetBSD Foundation
7*6b6d114aSBen Gras.\" by Jason R. Thorpe.
8*6b6d114aSBen Gras.\"
9*6b6d114aSBen Gras.\" Redistribution and use in source and binary forms, with or without
10*6b6d114aSBen Gras.\" modification, are permitted provided that the following conditions
11*6b6d114aSBen Gras.\" are met:
12*6b6d114aSBen Gras.\" 1. Redistributions of source code must retain the above copyright
13*6b6d114aSBen Gras.\" notice, this list of conditions and the following disclaimer.
14*6b6d114aSBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
15*6b6d114aSBen Gras.\" notice, this list of conditions and the following disclaimer in the
16*6b6d114aSBen Gras.\" documentation and/or other materials provided with the distribution.
17*6b6d114aSBen Gras.\"
18*6b6d114aSBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19*6b6d114aSBen Gras.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20*6b6d114aSBen Gras.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21*6b6d114aSBen Gras.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22*6b6d114aSBen Gras.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*6b6d114aSBen Gras.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*6b6d114aSBen Gras.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*6b6d114aSBen Gras.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*6b6d114aSBen Gras.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*6b6d114aSBen Gras.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*6b6d114aSBen Gras.\" POSSIBILITY OF SUCH DAMAGE.
29*6b6d114aSBen Gras.\"
30*6b6d114aSBen Gras.Dd October 10, 2009
31*6b6d114aSBen Gras.Dt PROP_ARRAY 3
32*6b6d114aSBen Gras.Os
33*6b6d114aSBen Gras.Sh NAME
34*6b6d114aSBen Gras.Nm prop_array ,
35*6b6d114aSBen Gras.Nm prop_array_create ,
36*6b6d114aSBen Gras.Nm prop_array_create_with_capacity ,
37*6b6d114aSBen Gras.Nm prop_array_copy ,
38*6b6d114aSBen Gras.Nm prop_array_copy_mutable ,
39*6b6d114aSBen Gras.Nm prop_array_capacity ,
40*6b6d114aSBen Gras.Nm prop_array_count ,
41*6b6d114aSBen Gras.Nm prop_array_ensure_capacity ,
42*6b6d114aSBen Gras.Nm prop_array_iterator ,
43*6b6d114aSBen Gras.Nm prop_array_make_immutable ,
44*6b6d114aSBen Gras.Nm prop_array_mutable ,
45*6b6d114aSBen Gras.Nm prop_array_get ,
46*6b6d114aSBen Gras.Nm prop_array_set ,
47*6b6d114aSBen Gras.Nm prop_array_add ,
48*6b6d114aSBen Gras.Nm prop_array_remove ,
49*6b6d114aSBen Gras.Nm prop_array_externalize ,
50*6b6d114aSBen Gras.Nm prop_array_internalize ,
51*6b6d114aSBen Gras.Nm prop_array_externalize_to_file ,
52*6b6d114aSBen Gras.Nm prop_array_internalize_from_file ,
53*6b6d114aSBen Gras.Nm prop_array_externalize_to_pref ,
54*6b6d114aSBen Gras.Nm prop_array_internalize_from_pref ,
55*6b6d114aSBen Gras.Nm prop_array_equals
56*6b6d114aSBen Gras.Nd array property collection object
57*6b6d114aSBen Gras.Sh LIBRARY
58*6b6d114aSBen Gras.Lb libprop
59*6b6d114aSBen Gras.Sh SYNOPSIS
60*6b6d114aSBen Gras.In prop/proplib.h
61*6b6d114aSBen Gras.\"
62*6b6d114aSBen Gras.Ft prop_array_t
63*6b6d114aSBen Gras.Fn prop_array_create "void"
64*6b6d114aSBen Gras.Ft prop_array_t
65*6b6d114aSBen Gras.Fn prop_array_create_with_capacity "unsigned int capacity"
66*6b6d114aSBen Gras.\"
67*6b6d114aSBen Gras.Ft prop_array_t
68*6b6d114aSBen Gras.Fn prop_array_copy "prop_array_t array"
69*6b6d114aSBen Gras.Ft prop_array_t
70*6b6d114aSBen Gras.Fn prop_array_copy_mutable "prop_array_t array"
71*6b6d114aSBen Gras.\"
72*6b6d114aSBen Gras.Ft unsigned int
73*6b6d114aSBen Gras.Fn prop_array_capacity "prop_array_t array"
74*6b6d114aSBen Gras.Ft unsigned int
75*6b6d114aSBen Gras.Fn prop_array_count "prop_array_t array"
76*6b6d114aSBen Gras.Ft bool
77*6b6d114aSBen Gras.Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
78*6b6d114aSBen Gras.\"
79*6b6d114aSBen Gras.Ft prop_object_iterator_t
80*6b6d114aSBen Gras.Fn prop_array_iterator "prop_array_t array"
81*6b6d114aSBen Gras.\"
82*6b6d114aSBen Gras.Ft void
83*6b6d114aSBen Gras.Fn prop_array_make_immutable "prop_array_t array"
84*6b6d114aSBen Gras.Ft bool
85*6b6d114aSBen Gras.Fn prop_array_mutable "prop_array_t array"
86*6b6d114aSBen Gras.\"
87*6b6d114aSBen Gras.Ft prop_object_t
88*6b6d114aSBen Gras.Fn prop_array_get "prop_array_t array" "unsigned int index"
89*6b6d114aSBen Gras.Ft bool
90*6b6d114aSBen Gras.Fn prop_array_set "prop_array_t array" "unsigned int index" "prop_object_t obj"
91*6b6d114aSBen Gras.Ft bool
92*6b6d114aSBen Gras.Fn prop_array_add "prop_array_t array" "prop_object_t obj"
93*6b6d114aSBen Gras.Ft void
94*6b6d114aSBen Gras.Fn prop_array_remove "prop_array_t array" "unsigned int index"
95*6b6d114aSBen Gras.\"
96*6b6d114aSBen Gras.Ft char *
97*6b6d114aSBen Gras.Fn prop_array_externalize "prop_array_t array"
98*6b6d114aSBen Gras.Ft prop_array_t
99*6b6d114aSBen Gras.Fn prop_array_internalize "const char *xml"
100*6b6d114aSBen Gras.\"
101*6b6d114aSBen Gras.Ft bool
102*6b6d114aSBen Gras.Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
103*6b6d114aSBen Gras.Ft prop_array_t
104*6b6d114aSBen Gras.Fn prop_array_internalize_from_file "const char *path"
105*6b6d114aSBen Gras.\"
106*6b6d114aSBen Gras.Ft bool
107*6b6d114aSBen Gras.Fn prop_array_externalize_to_pref "prop_array_t array" "struct plistref *pref"
108*6b6d114aSBen Gras.Ft bool
109*6b6d114aSBen Gras.Fn prop_array_internalize_from_pref "const struct plistref *pref" \
110*6b6d114aSBen Gras    "prop_array_t *arrayp"
111*6b6d114aSBen Gras.\"
112*6b6d114aSBen Gras.Ft bool
113*6b6d114aSBen Gras.Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
114*6b6d114aSBen Gras.Sh DESCRIPTION
115*6b6d114aSBen GrasThe
116*6b6d114aSBen Gras.Nm prop_array
117*6b6d114aSBen Grasfamily of functions operate on the array property collection object type.
118*6b6d114aSBen GrasAn array is an ordered set; an iterated array will return objects in the
119*6b6d114aSBen Grassame order with which they were stored.
120*6b6d114aSBen Gras.Bl -tag -width "xxxxx"
121*6b6d114aSBen Gras.It Fn prop_array_create "void"
122*6b6d114aSBen GrasCreate an empty array.
123*6b6d114aSBen GrasThe array initially has no capacity.
124*6b6d114aSBen GrasReturns
125*6b6d114aSBen Gras.Dv NULL
126*6b6d114aSBen Grason failure.
127*6b6d114aSBen Gras.It Fn prop_array_create_with_capacity "unsigned int capacity"
128*6b6d114aSBen GrasCreate an array with the capacity to store
129*6b6d114aSBen Gras.Fa capacity
130*6b6d114aSBen Grasobjects.
131*6b6d114aSBen GrasReturns
132*6b6d114aSBen Gras.Dv NULL
133*6b6d114aSBen Grason failure.
134*6b6d114aSBen Gras.It Fn prop_array_copy "prop_array_t array"
135*6b6d114aSBen GrasCopy an array.
136*6b6d114aSBen GrasThe new array has an initial capacity equal to the number of objects stored
137*6b6d114aSBen Grasin the array being copied.
138*6b6d114aSBen GrasThe new array contains references to the original array's objects, not
139*6b6d114aSBen Grascopies of those objects
140*6b6d114aSBen Gras.Pq i.e. a shallow copy is made .
141*6b6d114aSBen GrasIf the original array is immutable, the resulting array is also immutable.
142*6b6d114aSBen GrasReturns
143*6b6d114aSBen Gras.Dv NULL
144*6b6d114aSBen Grason failure.
145*6b6d114aSBen Gras.It Fn prop_array_copy_mutable "prop_array_t array"
146*6b6d114aSBen GrasLike
147*6b6d114aSBen Gras.Fn prop_array_copy ,
148*6b6d114aSBen Grasexcept the resulting array is always mutable.
149*6b6d114aSBen Gras.It Fn prop_array_capacity "prop_array_t array"
150*6b6d114aSBen GrasReturns the total capacity of the array, including objects already stored
151*6b6d114aSBen Grasin the array.
152*6b6d114aSBen GrasIf the supplied object isn't an array, zero is returned.
153*6b6d114aSBen Gras.It Fn prop_array_count "prop_array_t array"
154*6b6d114aSBen GrasReturns the number of objects stored in the array.
155*6b6d114aSBen GrasIf the supplied object isn't an array, zero is returned.
156*6b6d114aSBen Gras.It Fn prop_array_ensure_capacity "prop_array_t array" "unsigned int capacity"
157*6b6d114aSBen GrasEnsure that the array has a total capacity of
158*6b6d114aSBen Gras.Fa capacity ,
159*6b6d114aSBen Grasincluding objects already stored in the array.
160*6b6d114aSBen GrasReturns
161*6b6d114aSBen Gras.Dv true
162*6b6d114aSBen Grasif the capacity of the array is greater or equal to
163*6b6d114aSBen Gras.Fa capacity
164*6b6d114aSBen Grasor if expansion of the array's capacity was successful
165*6b6d114aSBen Grasand
166*6b6d114aSBen Gras.Dv false
167*6b6d114aSBen Grasotherwise.
168*6b6d114aSBen Gras.It Fn prop_array_iterator "prop_array_t array"
169*6b6d114aSBen GrasCreate an iterator for the array.
170*6b6d114aSBen GrasThe array is retained by the iterator.
171*6b6d114aSBen GrasAn array iterator returns the object references stored in the array.
172*6b6d114aSBen GrasStoring to or removing from the array invalidates any active iterators for
173*6b6d114aSBen Grasthe array.
174*6b6d114aSBen GrasReturns
175*6b6d114aSBen Gras.Dv NULL
176*6b6d114aSBen Grason failure.
177*6b6d114aSBen Gras.It Fn prop_array_make_immutable "prop_array_t array"
178*6b6d114aSBen GrasMake
179*6b6d114aSBen Gras.Fa array
180*6b6d114aSBen Grasimmutable.
181*6b6d114aSBen Gras.It Fn prop_array_mutable "prop_array_t array"
182*6b6d114aSBen GrasReturns
183*6b6d114aSBen Gras.Dv true
184*6b6d114aSBen Grasif the array is mutable.
185*6b6d114aSBen Gras.It Fn prop_array_get "prop_array_t array" "unsigned int index"
186*6b6d114aSBen GrasReturn the object stored at the array index
187*6b6d114aSBen Gras.Fa index .
188*6b6d114aSBen GrasReturns
189*6b6d114aSBen Gras.Dv NULL
190*6b6d114aSBen Grason failure.
191*6b6d114aSBen Gras.It Fn prop_array_set "prop_array_t array" "unsigned int index" \
192*6b6d114aSBen Gras       "prop_object_t obj"
193*6b6d114aSBen GrasStore a reference to the object
194*6b6d114aSBen Gras.Fa obj
195*6b6d114aSBen Grasat the array index
196*6b6d114aSBen Gras.Fa index .
197*6b6d114aSBen GrasThis function is not allowed to create holes in the array;
198*6b6d114aSBen Grasthe caller must either be setting the object just beyond the existing
199*6b6d114aSBen Grascount or replacing an already existing object reference.
200*6b6d114aSBen GrasThe object will be retained by the array.
201*6b6d114aSBen GrasIf an existing object reference is being replaced, that object will be
202*6b6d114aSBen Grasreleased.
203*6b6d114aSBen GrasReturns
204*6b6d114aSBen Gras.Dv true
205*6b6d114aSBen Grasif storing the object was successful and
206*6b6d114aSBen Gras.Dv false
207*6b6d114aSBen Grasotherwise.
208*6b6d114aSBen Gras.It Fn prop_array_add "prop_array_t array" "prop_object_t obj"
209*6b6d114aSBen GrasAdd a reference to the object
210*6b6d114aSBen Gras.Fa obj
211*6b6d114aSBen Grasto the array, appending to the end and growing the array's capacity if
212*6b6d114aSBen Grasnecessary.
213*6b6d114aSBen GrasThe object will be retained by the array.
214*6b6d114aSBen GrasReturns
215*6b6d114aSBen Gras.Dv true
216*6b6d114aSBen Grasif storing the object was successful and
217*6b6d114aSBen Gras.Dv false
218*6b6d114aSBen Grasotherwise.
219*6b6d114aSBen Gras.Pp
220*6b6d114aSBen GrasDuring expansion, array's capacity is augmented by the
221*6b6d114aSBen Gras.Dv EXPAND_STEP
222*6b6d114aSBen Grasconstant, as defined in
223*6b6d114aSBen Gras.Pa libprop/prop_array.c
224*6b6d114aSBen Grasfile, e.g.
225*6b6d114aSBen Gras.Pp
226*6b6d114aSBen Gras.Dl #define	EXPAND_STEP		16
227*6b6d114aSBen Gras.It Fn prop_array_remove "prop_array_t array" "unsigned int index"
228*6b6d114aSBen GrasRemove the reference to the object stored at array index
229*6b6d114aSBen Gras.Fa index .
230*6b6d114aSBen GrasThe object will be released and the array compacted following
231*6b6d114aSBen Grasthe removal.
232*6b6d114aSBen Gras.It Fn prop_array_externalize "prop_array_t array"
233*6b6d114aSBen GrasExternalizes an array, returning a NUL-terminated buffer containing
234*6b6d114aSBen Grasthe XML representation of the array.
235*6b6d114aSBen GrasThe caller is responsible for freeing the returned buffer.
236*6b6d114aSBen GrasIf converting to the external representation fails for any reason,
237*6b6d114aSBen Gras.Dv NULL
238*6b6d114aSBen Grasis returned.
239*6b6d114aSBen Gras.Pp
240*6b6d114aSBen GrasIn user space, the buffer is allocated using
241*6b6d114aSBen Gras.Xr malloc 3 .
242*6b6d114aSBen GrasIn the kernel, the buffer is allocated using
243*6b6d114aSBen Gras.Xr malloc 9
244*6b6d114aSBen Grasusing the malloc type
245*6b6d114aSBen Gras.Dv M_TEMP .
246*6b6d114aSBen Gras.It Fn prop_array_internalize "const char *xml"
247*6b6d114aSBen GrasParse the XML representation of a property list in the NUL-terminated
248*6b6d114aSBen Grasbuffer
249*6b6d114aSBen Gras.Fa xml
250*6b6d114aSBen Grasand return the corresponding array.
251*6b6d114aSBen GrasReturns
252*6b6d114aSBen Gras.Dv NULL
253*6b6d114aSBen Grasif parsing fails for any reason.
254*6b6d114aSBen Gras.It Fn prop_array_externalize_to_file "prop_array_t array" "const char *path"
255*6b6d114aSBen GrasExternalizes an array and writes it to the file specified by
256*6b6d114aSBen Gras.Fa path .
257*6b6d114aSBen GrasThe file is saved with the mode
258*6b6d114aSBen Gras.Dv 0666
259*6b6d114aSBen Grasas modified by the process's file creation mask
260*6b6d114aSBen Gras.Pq see Xr umask 2
261*6b6d114aSBen Grasand is written atomically.
262*6b6d114aSBen GrasReturns
263*6b6d114aSBen Gras.Dv false
264*6b6d114aSBen Grasif externalizing or writing the array fails for any reason.
265*6b6d114aSBen Gras.It Fn prop_array_internalize_from_file "const char *path"
266*6b6d114aSBen GrasReads the XML property list contained in the file specified by
267*6b6d114aSBen Gras.Fa path ,
268*6b6d114aSBen Grasinternalizes it, and returns the corresponding array.
269*6b6d114aSBen GrasReturns
270*6b6d114aSBen Gras.Dv NULL
271*6b6d114aSBen Grason failure.
272*6b6d114aSBen Gras.It Fn prop_array_externalize_to_pref "prop_array_t array" \
273*6b6d114aSBen Gras    "struct plistref *pref"
274*6b6d114aSBen GrasExternalizes an array and packs it into the plistref specified by
275*6b6d114aSBen Gras.Fa pref .
276*6b6d114aSBen GrasReturns
277*6b6d114aSBen Gras.Dv false
278*6b6d114aSBen Grasif externalizing the array fails for any reason.
279*6b6d114aSBen Gras.It Fn prop_array_internalize_from_pref "const struct plistref *pref" \
280*6b6d114aSBen Gras    "prop_array_t *arrayp"
281*6b6d114aSBen GrasReads the plistref specified by
282*6b6d114aSBen Gras.Fa pref ,
283*6b6d114aSBen Grasinternalizes it, and returns the corresponding array.
284*6b6d114aSBen GrasReturns
285*6b6d114aSBen Gras.Dv false
286*6b6d114aSBen Grasif internalizing or writing the array fails for any reason.
287*6b6d114aSBen Gras.It Fn prop_array_equals "prop_array_t array1" "prop_array_t array2"
288*6b6d114aSBen GrasReturns
289*6b6d114aSBen Gras.Dv true
290*6b6d114aSBen Grasif the two arrays are equivalent.
291*6b6d114aSBen GrasIf at least one of the supplied objects isn't an array,
292*6b6d114aSBen Gras.Dv false
293*6b6d114aSBen Grasis returned.
294*6b6d114aSBen GrasNote: Objects contained in the array are compared by value, not by reference.
295*6b6d114aSBen Gras.El
296*6b6d114aSBen Gras.Sh SEE ALSO
297*6b6d114aSBen Gras.Xr prop_bool 3 ,
298*6b6d114aSBen Gras.Xr prop_data 3 ,
299*6b6d114aSBen Gras.Xr prop_dictionary 3 ,
300*6b6d114aSBen Gras.Xr prop_number 3 ,
301*6b6d114aSBen Gras.Xr prop_object 3 ,
302*6b6d114aSBen Gras.Xr prop_string 3 ,
303*6b6d114aSBen Gras.Xr proplib 3
304*6b6d114aSBen Gras.Sh HISTORY
305*6b6d114aSBen GrasThe
306*6b6d114aSBen Gras.Nm proplib
307*6b6d114aSBen Grasproperty container object library first appeared in
308*6b6d114aSBen Gras.Nx 4.0 .
309