1 .\" $NetBSD: prop_dictionary.3,v 1.14 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_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_externalize_to_pref ,
56 .Nm prop_dictionary_equals ,
57 .Nm prop_dictionary_keysym_cstring_nocopy ,
58 .Nm prop_dictionary_keysym_equals
59 .Nd dictionary property collection object
66 .Fn prop_dictionary_create "void"
68 .Fn prop_dictionary_create_with_capacity "unsigned int capacity"
71 .Fn prop_dictionary_copy "prop_dictionary_t dict"
73 .Fn prop_dictionary_copy_mutable "prop_dictionary_t dict"
76 .Fn prop_dictionary_count "prop_dictionary_t dict"
78 .Fn prop_dictionary_ensure_capacity "prop_dictionary_t dict" \
79 "unsigned int capacity"
81 .Ft prop_object_iterator_t
82 .Fn prop_dictionary_iterator "prop_dictionary_t dict"
84 .Fn prop_dictionary_all_keys "prop_dictionary_t dict"
87 .Fn prop_dictionary_make_immutable "prop_dictionary_t dict"
89 .Fn prop_dictionary_mutable "prop_dictionary_t dict"
92 .Fn prop_dictionary_get "prop_dictionary_t dict" "const char *key"
94 .Fn prop_dictionary_set "prop_dictionary_t dict" "const char *key" \
97 .Fn prop_dictionary_remove "prop_dictionary_t dict" "const char *key"
100 .Fn prop_dictionary_get_keysym "prop_dictionary_t dict" \
101 "prop_dictionary_keysym_t keysym"
103 .Fn prop_dictionary_set_keysym "prop_dictionary_t dict" \
104 "prop_dictionary_keysym_t keysym" "prop_object_t obj"
106 .Fn prop_dictionary_remove_keysym "prop_dictionary_t dict" \
107 "prop_dictionary_keysym_t keysym"
110 .Fn prop_dictionary_equals "prop_dictionary_t dict1" "prop_dictionary_t dict2"
113 .Fn prop_dictionary_keysym_cstring_nocopy "prop_dictionary_keysym_t sym"
116 .Fn prop_dictionary_keysym_equals "prop_dictionary_keysym_t keysym1" \
117 "prop_dictionary_keysym_t keysym2"
120 .Fn prop_dictionary_externalize "prop_dictionary_t dict"
121 .Ft prop_dictionary_t
122 .Fn prop_dictionary_internalize "const char *xml"
125 .Fn prop_dictionary_externalize_to_file "prop_dictionary_t dict" \
127 .Ft prop_dictionary_t
128 .Fn prop_dictionary_internalize_from_file "const char *path"
131 .Fn prop_dictionary_externalize_to_pref "prop_dictionary_t dict" \
132 "struct plistref *pref"
137 family of functions operate on the dictionary property collection object type.
138 A dictionary is an unordered set of objects stored as key-value pairs.
139 .Bl -tag -width "xxxxx"
140 .It Fn prop_dictionary_create "void"
141 Create an empty dictionary.
142 The dictionary initially has no capacity.
146 .It Fn prop_dictionary_create_with_capacity "unsigned int capacity"
147 Create a dictionary with the capacity to store
153 .It Fn prop_dictionary_copy "prop_dictionary_t dict"
155 The new dictionary has an initial capacity equal to the number of objects
156 stored in the dictionary being copied.
157 The new dictionary contains references to the original dictionary's objects,
158 not copies of those objects
159 .Pq i.e. a shallow copy is made .
160 If the original dictionary is immutable, the resulting dictionary is also
162 .It Fn prop_dictionary_copy_mutable "prop_dictionary_t dict"
164 .Fn prop_dictionary_copy ,
165 except the resulting dictionary is always mutable.
166 .It Fn prop_dictionary_count "prop_dictionary_t dict"
167 Returns the number of objects stored in the dictionary.
168 .It Fn prop_dictionary_ensure_capacity "prop_dictionary_t dict" \
169 "unsigned int capacity"
170 Ensure that the dictionary has a total capacity of
172 including objects already stored in the dictionary.
175 if the capacity of the dictionary is greater or equal to
177 or if the expansion of the dictionary's capacity was successful
181 If the supplied object isn't a dictionary,
184 .It Fn prop_dictionary_iterator "prop_dictionary_t dict"
185 Create an iterator for the dictionary.
186 The dictionary is retained by the iterator.
187 A dictionary iterator returns the key symbols used to look up objects stored
188 in the dictionary; to get the object itself, a dictionary lookup using this
189 key symbol must be performed.
190 Storing to or removing from the dictionary invalidates any active iterators for
195 .It Fn prop_dictionary_all_keys "prop_dictionary_t dict"
196 Return an array of all of the dictionary key symbols
197 .Pq prop_dictionary_keysym_t
199 This provides a way to iterate over the items in the dictionary while
200 retaining the ability to mutate the dictionary; instead of iterating
201 over the dictionary itself, iterate over the array of keys.
202 The caller is responsible for releasing the array.
206 .It Fn prop_dictionary_make_immutable "prop_dictionary_t dict"
210 .It Fn prop_dictionary_mutable "prop_dictionary_t dict"
213 if the dictionary is mutable.
214 .It Fn prop_dictionary_get "prop_dictionary_t dict" "const char *key"
215 Return the object stored in the dictionary with the key
217 If no object is stored with the specified key,
220 .It Fn prop_dictionary_set "prop_dictionary_t dict" "const char *key" \
222 Store a reference to the object
226 The object will be retained by the dictionary.
227 If the key already exists in the dictionary, the object associated with
228 that key will be released and replaced with the new object.
231 if storing the object was successful and
234 .It Fn prop_dictionary_remove "prop_dictionary_t dict" "const char *key"
235 Remove the reference to the object stored in the dictionary with the key
237 The object will be released.
238 .It Fn prop_dictionary_get_keysym "prop_dictionary_t dict" \
239 "prop_dictionary_keysym_t sym"
241 .Fn prop_dictionary_get ,
242 but the lookup is performed using a key symbol returned by a dictionary
244 The results are undefined if the iterator used to obtain the key symbol
245 is not associated with
247 .It Fn prop_dictionary_set_keysym "prop_dictionary_t dict" \
248 "prop_dictionary_keysym_t sym" "prop_object_t obj"
250 .Fn prop_dictionary_set ,
251 but the lookup of the object to replace is performed using a key symbol
252 returned by a dictionary iterator.
253 The results are undefined if the iterator used to obtain the key symbol
254 is not associated with
256 .It Fn prop_dictionary_remove_keysym "prop_dictionary_t dict" \
257 "prop_dictionary_keysym_t sym"
259 .Fn prop_dictionary_remove ,
260 but the lookup of the object to remove is performed using a key symbol
261 returned by a dictionary iterator.
262 The results are undefined if the iterator used to obtain the key symbol
263 is not associated with
265 .It Fn prop_dictionary_equals "prop_dictionary_t dict1" \
266 "prop_dictionary_t dict2"
269 if the two dictionaries are equivalent.
270 Note: Objects contained in the dictionary are compared by value, not by
272 .It Fn prop_dictionary_keysym_cstring_nocopy "prop_dictionary_keysym_t keysym"
273 Returns an immutable reference to the dictionary key symbol's string value.
274 .It Fn prop_dictionary_keysym_equals "prop_dictionary_keysym_t keysym1" \
275 "prop_dictionary_keysym_t keysym2"
278 if the two dictionary key symbols are equivalent.
279 .It Fn prop_dictionary_externalize "prop_dictionary_t dict"
280 Externalizes a dictionary, returning a NUL-terminated buffer containing
281 the XML representation of the dictionary.
282 The caller is responsible for freeing the returned buffer.
283 If converting to the external representation fails for any reason,
287 In user space, the buffer is allocated using
289 In the kernel, the buffer is allocated using
291 using the malloc type
293 .It Fn prop_dictionary_internalize "const char *xml"
294 Parse the XML representation of a property list in the NUL-terminated
297 and return the corresponding dictionary.
300 if parsing fails for any reason.
301 .It Fn prop_dictionary_externalize_to_file "prop_dictionary_t dict" \
303 Externalizes a dictionary and writes it to the file specified by
305 The file is saved with the mode
307 as modified by the process's file creation mask
309 and is written atomically.
312 if externalizing or writing the dictionary fails for any reason.
313 .It Fn prop_dictionary_internalize_from_file "const char *path"
314 Reads the XML property list contained in the file specified by
316 internalizes it, and returns the corresponding array.
320 .It Fn prop_dictionary_externalize_to_pref "prop_dictionary_t dict" \
321 "struct plistref *pref"
322 Externalizes a dictionary and packs it into the plistref specified by
326 if externalizing the dictionary fails for any reason.
332 .Xr prop_dictionary_util 3 ,
340 property container object library first appeared in