1 .\" $NetBSD: prop_dictionary.3,v 1.13 2008/05/06 17:23:38 xtraeme 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_dictionary_create ,
36 .Nm prop_dictionary_create_with_capacity ,
37 .Nm prop_dictionary_copy ,
38 .Nm prop_dictionary_copy_mutable ,
39 .Nm prop_dictionary_count ,
40 .Nm prop_dictionary_ensure_capacity ,
41 .Nm prop_dictionary_iterator ,
42 .Nm prop_dictionary_all_keys ,
43 .Nm prop_dictionary_make_immutable ,
44 .Nm prop_dictionary_mutable ,
45 .Nm prop_dictionary_get ,
46 .Nm prop_dictionary_set ,
47 .Nm prop_dictionary_remove ,
48 .Nm prop_dictionary_get_keysym ,
49 .Nm prop_dictionary_set_keysym ,
50 .Nm prop_dictionary_remove_keysym ,
51 .Nm prop_dictionary_externalize ,
52 .Nm prop_dictionary_internalize ,
53 .Nm prop_dictionary_externalize_to_file ,
54 .Nm prop_dictionary_internalize_from_file ,
55 .Nm prop_dictionary_equals ,
56 .Nm prop_dictionary_keysym_cstring_nocopy ,
57 .Nm prop_dictionary_keysym_equals
58 .Nd dictionary property collection object
65 .Fn prop_dictionary_create "void"
67 .Fn prop_dictionary_create_with_capacity "unsigned int capacity"
70 .Fn prop_dictionary_copy "prop_dictionary_t dict"
72 .Fn prop_dictionary_copy_mutable "prop_dictionary_t dict"
75 .Fn prop_dictionary_count "prop_dictionary_t dict"
77 .Fn prop_dictionary_ensure_capacity "prop_dictionary_t dict" \
78 "unsigned int capacity"
80 .Ft prop_object_iterator_t
81 .Fn prop_dictionary_iterator "prop_dictionary_t dict"
83 .Fn prop_dictionary_all_keys "prop_dictionary_t dict"
86 .Fn prop_dictionary_make_immutable "prop_dictionary_t dict"
88 .Fn prop_dictionary_mutable "prop_dictionary_t dict"
91 .Fn prop_dictionary_get "prop_dictionary_t dict" "const char *key"
93 .Fn prop_dictionary_set "prop_dictionary_t dict" "const char *key" \
96 .Fn prop_dictionary_remove "prop_dictionary_t dict" "const char *key"
99 .Fn prop_dictionary_get_keysym "prop_dictionary_t dict" \
100 "prop_dictionary_keysym_t keysym"
102 .Fn prop_dictionary_set_keysym "prop_dictionary_t dict" \
103 "prop_dictionary_keysym_t keysym" "prop_object_t obj"
105 .Fn prop_dictionary_remove_keysym "prop_dictionary_t dict" \
106 "prop_dictionary_keysym_t keysym"
109 .Fn prop_dictionary_equals "prop_dictionary_t dict1" "prop_dictionary_t dict2"
112 .Fn prop_dictionary_keysym_cstring_nocopy "prop_dictionary_keysym_t sym"
115 .Fn prop_dictionary_keysym_equals "prop_dictionary_keysym_t keysym1" \
116 "prop_dictionary_keysym_t keysym2"
119 .Fn prop_dictionary_externalize "prop_dictionary_t dict"
120 .Ft prop_dictionary_t
121 .Fn prop_dictionary_internalize "const char *xml"
124 .Fn prop_dictionary_externalize_to_file "prop_dictionary_t dict" \
126 .Ft prop_dictionary_t
127 .Fn prop_dictionary_internalize_from_file "const char *path"
132 family of functions operate on the dictionary property collection object type.
133 A dictionary is an unordered set of objects stored as key-value pairs.
134 .Bl -tag -width "xxxxx"
135 .It Fn prop_dictionary_create "void"
136 Create an empty dictionary.
137 The dictionary initially has no capacity.
141 .It Fn prop_dictionary_create_with_capacity "unsigned int capacity"
142 Create a dictionary with the capacity to store
148 .It Fn prop_dictionary_copy "prop_dictionary_t dict"
150 The new dictionary has an initial capacity equal to the number of objects
151 stored in the dictionary being copied.
152 The new dictionary contains references to the original dictionary's objects,
153 not copies of those objects
154 .Pq i.e. a shallow copy is made .
155 If the original dictionary is immutable, the resulting dictionary is also
157 .It Fn prop_dictionary_copy_mutable "prop_dictionary_t dict"
159 .Fn prop_dictionary_copy ,
160 except the resulting dictionary is always mutable.
161 .It Fn prop_dictionary_count "prop_dictionary_t dict"
162 Returns the number of objects stored in the dictionary.
163 .It Fn prop_dictionary_ensure_capacity "prop_dictionary_t dict"
164 Ensure that the dictionary has a total capacity of
166 including objects already stored in the dictionary.
169 if the capacity of the dictionary is greater or equal to
171 or if the expansion of the dictionary's capacity was successful
175 If the supplied object isn't a dictionary,
178 .It Fn prop_dictionary_iterator "prop_dictionary_t dict"
179 Create an iterator for the dictionary.
180 The dictionary is retained by the iterator.
181 A dictionary iterator returns the key symbols used to look up objects stored
182 in the dictionary; to get the object itself, a dictionary lookup using this
183 key symbol must be performed.
184 Storing to or removing from the dictionary invalidates any active iterators for
189 .It Fn prop_dictionary_all_keys "prop_dictionary_t dict"
190 Return an array of all of the dictionary key symbols
191 .Pq prop_dictionary_keysym_t
193 This provides a way to iterate over the items in the dictionary while
194 retaining the ability to mutate the dictionary; instead of iterating
195 over the dictionary itself, iterate over the array of keys.
196 The caller is responsible for releasing the array.
200 .It Fn prop_dictionary_make_immutable "prop_dictionary_t dict"
204 .It Fn prop_dictionary_mutable "prop_dictionary_t dict"
207 if the dictionary is mutable.
208 .It Fn prop_dictionary_get "prop_dictionary_t dict" "const char *key"
209 Return the object stored in the dictionary with the key
211 If no object is stored with the specified key,
214 .It Fn prop_dictionary_set "prop_dictionary_t dict" "const char *key" \
216 Store a reference to the object
220 The object will be retained by the dictionary.
221 If the key already exists in the dictionary, the object associated with
222 that key will be released and replaced with the new object.
225 if storing the object was successful and
228 .It Fn prop_dictionary_remove "prop_dictionary_t dict" "const char *key"
229 Remove the reference to the object stored in the dictionary with the key
231 The object will be released.
232 .It Fn prop_dictionary_get_keysym "prop_dictionary_t dict" \
233 "prop_dictionary_keysym_t sym"
235 .Fn prop_dictionary_get ,
236 but the lookup is performed using a key symbol returned by a dictionary
238 The results are undefined if the iterator used to obtain the key symbol
239 is not associated with
241 .It Fn prop_dictionary_set_keysym "prop_dictionary_t dict" \
242 "prop_dictionary_keysym_t sym" "prop_object_t obj"
244 .Fn prop_dictionary_set ,
245 but the lookup of the object to replace is performed using a key symbol
246 returned by a dictionary iterator.
247 The results are undefined if the iterator used to obtain the key symbol
248 is not associated with
250 .It Fn prop_dictionary_remove_keysym "prop_dictionary_t dict" \
251 "prop_dictionary_keysym_t sym"
253 .Fn prop_dictionary_remove ,
254 but the lookup of the object to remove is performed using a key symbol
255 returned by a dictionary iterator.
256 The results are undefined if the iterator used to obtain the key symbol
257 is not associated with
259 .It Fn prop_dictionary_equals "prop_dictionary_t dict1" \
260 "prop_dictionary_t dict2"
263 if the two dictionaries are equivalent.
264 Note: Objects contained in the dictionary are compared by value, not by
266 .It Fn prop_dictionary_keysym_cstring_nocopy "prop_dictionary_keysym_t keysym"
267 Returns an immutable reference to the dictionary key symbol's string value.
268 .It Fn prop_dictionary_keysym_equals "prop_dictionary_keysym_t keysym1" \
269 "prop_dictionary_keysym_t keysym2"
272 if the two dictionary key symbols are equivalent.
273 .It Fn prop_dictionary_externalize "prop_dictionary_t dict"
274 Externalizes a dictionary, returning a NUL-terminated buffer containing
275 the XML representation of the dictionary.
276 The caller is responsible for freeing the returned buffer.
277 If converting to the external representation fails for any reason,
281 In user space, the buffer is allocated using
283 In the kernel, the buffer is allocated using
285 using the malloc type
287 .It Fn prop_dictionary_internalize "const char *xml"
288 Parse the XML representation of a property list in the NUL-terminated
291 and return the corresponding dictionary.
294 if parsing fails for any reason.
295 .It Fn prop_dictionary_externalize_to_file "prop_dictionary_t dict" \
297 Externalizes a dictionary and writes it to the file specified by
299 The file is saved with the mode
301 as modified by the process's file creation mask
303 and is written atomically.
306 if externalizing or writing the dictionary fails for any reason.
307 .It Fn prop_dictionary_internalize_from_file "const char *path"
308 Reads the XML property list contained in the file specified by
310 internalizes it, and returns the corresponding array.
319 .Xr prop_dictionary_util 3 ,
327 property container object library first appeared in