2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 Copyright (c) 1998-2003, Apple, Inc. All rights reserved.
31 CFDictionary implements a container which pairs pointer-sized keys
32 with pointer-sized values. Values are accessed via arbitrary
33 user-defined keys. A CFDictionary differs from a CFArray in that
34 the key used to access a particular value in the dictionary remains
35 the same as values are added to or removed from the dictionary,
36 unless a value associated with its particular key is replaced or
37 removed. In a CFArray, the key (or index) used to retrieve a
38 particular value can change over time as values are added to or
39 deleted from the array. Also unlike an array, there is no ordering
40 among values in a dictionary. To enable later retrieval of a value,
41 the key of the key-value pair should be constant (or treated as
42 constant); if the key changes after being used to put a value in
43 the dictionary, the value may not be retrievable. The keys of a
44 dictionary form a set; that is, no two keys which are equal to
45 one another are present in the dictionary at any time.
47 Dictionaries come in two flavors, immutable, which cannot have
48 values added to them or removed from them after the dictionary is
49 created, and mutable, to which you can add values or from which
50 remove values. Mutable dictionaries have two subflavors,
51 fixed-capacity, for which there is a maximum number set at creation
52 time of values which can be put into the dictionary, and variable
53 capacity, which can have an unlimited number of values (or rather,
54 limited only by constraints external to CFDictionary, like the
55 amount of available memory). Fixed-capacity dictionaries can be
56 somewhat higher performing, if you can put a definate upper limit
57 on the number of values that might be put into the dictionary.
59 As with all CoreFoundation collection types, dictionaries maintain
60 hard references on the values you put in them, but the retaining and
61 releasing functions are user-defined callbacks that can actually do
62 whatever the user wants (for example, nothing).
64 Although a particular implementation of CFDictionary may not use
65 hashing and a hash table for storage of the values, the keys have
66 a hash-code generating function defined for them, and a function
67 to test for equality of two keys. These two functions together
68 must maintain the invariant that if equal(X, Y), then hash(X) ==
69 hash(Y). Note that the converse will not generally be true (but
70 the contrapositive, if hash(X) != hash(Y), then !equal(X, Y),
71 will be as required by Boolean logic). If the hash() and equal()
72 key callbacks are NULL, the key is used as a pointer-sized integer,
73 and pointer equality is used. Care should be taken to provide a
74 hash() callback which will compute sufficiently dispersed hash
75 codes for the key set for best performance.
77 Computational Complexity
78 The access time for a value in the dictionary is guaranteed to be at
79 worst O(lg N) for any implementation, current and future, but will
80 often be O(1) (constant time). Insertion or deletion operations
81 will typically be constant time as well, but are O(N*lg N) in the
82 worst case in some implementations. Access of values through a key
83 is faster than accessing values directly (if there are any such
84 operations). Dictionaries will tend to use significantly more memory
85 than a array with the same number of values.
88 #if !defined(__COREFOUNDATION_CFDICTIONARY__)
89 #define __COREFOUNDATION_CFDICTIONARY__ 1
91 #include <CoreFoundation/CFBase.h>
93 #if defined(__cplusplus)
98 @typedef CFDictionaryKeyCallBacks
99 Structure containing the callbacks for keys of a CFDictionary.
100 @field version The version number of the structure type being passed
101 in as a parameter to the CFDictionary creation functions.
102 This structure is version 0.
103 @field retain The callback used to add a retain for the dictionary
104 on keys as they are used to put values into the dictionary.
105 This callback returns the value to use as the key in the
106 dictionary, which is usually the value parameter passed to
107 this callback, but may be a different value if a different
108 value should be used as the key. The dictionary's allocator
109 is passed as the first argument.
110 @field release The callback used to remove a retain previously added
111 for the dictionary from keys as their values are removed from
112 the dictionary. The dictionary's allocator is passed as the
114 @field copyDescription The callback used to create a descriptive
115 string representation of each key in the dictionary. This
116 is used by the CFCopyDescription() function.
117 @field equal The callback used to compare keys in the dictionary for
119 @field hash The callback used to compute a hash code for keys as they
120 are used to access, add, or remove values in the dictionary.
122 typedef const void * (*CFDictionaryRetainCallBack
)(CFAllocatorRef allocator
, const void *value
);
123 typedef void (*CFDictionaryReleaseCallBack
)(CFAllocatorRef allocator
, const void *value
);
124 typedef CFStringRef (*CFDictionaryCopyDescriptionCallBack
)(const void *value
);
125 typedef Boolean (*CFDictionaryEqualCallBack
)(const void *value1
, const void *value2
);
126 typedef CFHashCode (*CFDictionaryHashCallBack
)(const void *value
);
129 CFDictionaryRetainCallBack retain
;
130 CFDictionaryReleaseCallBack release
;
131 CFDictionaryCopyDescriptionCallBack copyDescription
;
132 CFDictionaryEqualCallBack equal
;
133 CFDictionaryHashCallBack hash
;
134 } CFDictionaryKeyCallBacks
;
137 @constant kCFTypeDictionaryKeyCallBacks
138 Predefined CFDictionaryKeyCallBacks structure containing a
139 set of callbacks appropriate for use when the keys of a
140 CFDictionary are all CFTypes.
143 const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks
;
146 @constant kCFCopyStringDictionaryKeyCallBacks
147 Predefined CFDictionaryKeyCallBacks structure containing a
148 set of callbacks appropriate for use when the keys of a
149 CFDictionary are all CFStrings, which may be mutable and
150 need to be copied in order to serve as constant keys for
151 the values in the dictionary.
154 const CFDictionaryKeyCallBacks kCFCopyStringDictionaryKeyCallBacks
;
157 @typedef CFDictionaryValueCallBacks
158 Structure containing the callbacks for values of a CFDictionary.
159 @field version The version number of the structure type being passed
160 in as a parameter to the CFDictionary creation functions.
161 This structure is version 0.
162 @field retain The callback used to add a retain for the dictionary
163 on values as they are put into the dictionary.
164 This callback returns the value to use as the value in the
165 dictionary, which is usually the value parameter passed to
166 this callback, but may be a different value if a different
167 value should be added to the dictionary. The dictionary's
168 allocator is passed as the first argument.
169 @field release The callback used to remove a retain previously added
170 for the dictionary from values as they are removed from
171 the dictionary. The dictionary's allocator is passed as the
173 @field copyDescription The callback used to create a descriptive
174 string representation of each value in the dictionary. This
175 is used by the CFCopyDescription() function.
176 @field equal The callback used to compare values in the dictionary for
177 equality in some operations.
181 CFDictionaryRetainCallBack retain
;
182 CFDictionaryReleaseCallBack release
;
183 CFDictionaryCopyDescriptionCallBack copyDescription
;
184 CFDictionaryEqualCallBack equal
;
185 } CFDictionaryValueCallBacks
;
188 @constant kCFTypeDictionaryValueCallBacks
189 Predefined CFDictionaryValueCallBacks structure containing a set
190 of callbacks appropriate for use when the values in a CFDictionary
194 const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks
;
197 @typedef CFDictionaryApplierFunction
198 Type of the callback function used by the apply functions of
200 @param key The current key for the value.
201 @param value The current value from the dictionary.
202 @param context The user-defined context parameter given to the apply
205 typedef void (*CFDictionaryApplierFunction
)(const void *key
, const void *value
, void *context
);
208 @typedef CFDictionaryRef
209 This is the type of a reference to immutable CFDictionarys.
211 typedef const struct __CFDictionary
* CFDictionaryRef
;
214 @typedef CFMutableDictionaryRef
215 This is the type of a reference to mutable CFDictionarys.
217 typedef struct __CFDictionary
* CFMutableDictionaryRef
;
220 @function CFDictionaryGetTypeID
221 Returns the type identifier of all CFDictionary instances.
224 CFTypeID
CFDictionaryGetTypeID(void);
227 @function CFDictionaryCreate
228 Creates a new immutable dictionary with the given values.
229 @param allocator The CFAllocator which should be used to allocate
230 memory for the dictionary and its storage for values. This
231 parameter may be NULL in which case the current default
232 CFAllocator is used. If this reference is not a valid
233 CFAllocator, the behavior is undefined.
234 @param keys A C array of the pointer-sized keys to be used for
235 the parallel C array of values to be put into the dictionary.
236 This parameter may be NULL if the numValues parameter is 0.
237 This C array is not changed or freed by this function. If
238 this parameter is not a valid pointer to a C array of at
239 least numValues pointers, the behavior is undefined.
240 @param values A C array of the pointer-sized values to be in the
241 dictionary. This parameter may be NULL if the numValues
242 parameter is 0. This C array is not changed or freed by
243 this function. If this parameter is not a valid pointer to
244 a C array of at least numValues pointers, the behavior is
246 @param numValues The number of values to copy from the keys and
247 values C arrays into the CFDictionary. This number will be
248 the count of the dictionary. If this parameter is
249 negative, or greater than the number of values actually
250 in the keys or values C arrays, the behavior is undefined.
251 @param keyCallBacks A pointer to a CFDictionaryKeyCallBacks structure
252 initialized with the callbacks for the dictionary to use on
253 each key in the dictionary. The retain callback will be used
254 within this function, for example, to retain all of the new
255 keys from the keys C array. A copy of the contents of the
256 callbacks structure is made, so that a pointer to a structure
257 on the stack can be passed in, or can be reused for multiple
258 dictionary creations. If the version field of this
259 callbacks structure is not one of the defined ones for
260 CFDictionary, the behavior is undefined. The retain field may
261 be NULL, in which case the CFDictionary will do nothing to add
262 a retain to the keys of the contained values. The release field
263 may be NULL, in which case the CFDictionary will do nothing
264 to remove the dictionary's retain (if any) on the keys when the
265 dictionary is destroyed or a key-value pair is removed. If the
266 copyDescription field is NULL, the dictionary will create a
267 simple description for a key. If the equal field is NULL, the
268 dictionary will use pointer equality to test for equality of
269 keys. If the hash field is NULL, a key will be converted from
270 a pointer to an integer to compute the hash code. This callbacks
271 parameter itself may be NULL, which is treated as if a valid
272 structure of version 0 with all fields NULL had been passed in.
273 Otherwise, if any of the fields are not valid pointers to
274 functions of the correct type, or this parameter is not a
275 valid pointer to a CFDictionaryKeyCallBacks callbacks structure,
276 the behavior is undefined. If any of the keys put into the
277 dictionary is not one understood by one of the callback functions
278 the behavior when that callback function is used is undefined.
279 @param valueCallBacks A pointer to a CFDictionaryValueCallBacks structure
280 initialized with the callbacks for the dictionary to use on
281 each value in the dictionary. The retain callback will be used
282 within this function, for example, to retain all of the new
283 values from the values C array. A copy of the contents of the
284 callbacks structure is made, so that a pointer to a structure
285 on the stack can be passed in, or can be reused for multiple
286 dictionary creations. If the version field of this callbacks
287 structure is not one of the defined ones for CFDictionary, the
288 behavior is undefined. The retain field may be NULL, in which
289 case the CFDictionary will do nothing to add a retain to values
290 as they are put into the dictionary. The release field may be
291 NULL, in which case the CFDictionary will do nothing to remove
292 the dictionary's retain (if any) on the values when the
293 dictionary is destroyed or a key-value pair is removed. If the
294 copyDescription field is NULL, the dictionary will create a
295 simple description for a value. If the equal field is NULL, the
296 dictionary will use pointer equality to test for equality of
297 values. This callbacks parameter itself may be NULL, which is
298 treated as if a valid structure of version 0 with all fields
299 NULL had been passed in. Otherwise,
300 if any of the fields are not valid pointers to functions
301 of the correct type, or this parameter is not a valid
302 pointer to a CFDictionaryValueCallBacks callbacks structure,
303 the behavior is undefined. If any of the values put into the
304 dictionary is not one understood by one of the callback functions
305 the behavior when that callback function is used is undefined.
306 @result A reference to the new immutable CFDictionary.
309 CFDictionaryRef
CFDictionaryCreate(CFAllocatorRef allocator
, const void **keys
, const void **values
, CFIndex numValues
, const CFDictionaryKeyCallBacks
*keyCallBacks
, const CFDictionaryValueCallBacks
*valueCallBacks
);
312 @function CFDictionaryCreateCopy
313 Creates a new immutable dictionary with the key-value pairs from
314 the given dictionary.
315 @param allocator The CFAllocator which should be used to allocate
316 memory for the dictionary and its storage for values. This
317 parameter may be NULL in which case the current default
318 CFAllocator is used. If this reference is not a valid
319 CFAllocator, the behavior is undefined.
320 @param theDict The dictionary which is to be copied. The keys and values
321 from the dictionary are copied as pointers into the new
322 dictionary (that is, the values themselves are copied, not
323 that which the values point to, if anything). However, the
324 keys and values are also retained by the new dictionary using
325 the retain function of the original dictionary.
326 The count of the new dictionary will be the same as the
327 given dictionary. The new dictionary uses the same callbacks
328 as the dictionary to be copied. If this parameter is
329 not a valid CFDictionary, the behavior is undefined.
330 @result A reference to the new immutable CFDictionary.
333 CFDictionaryRef
CFDictionaryCreateCopy(CFAllocatorRef allocator
, CFDictionaryRef theDict
);
336 @function CFDictionaryCreateMutable
337 Creates a new mutable dictionary.
338 @param allocator The CFAllocator which should be used to allocate
339 memory for the dictionary and its storage for values. This
340 parameter may be NULL in which case the current default
341 CFAllocator is used. If this reference is not a valid
342 CFAllocator, the behavior is undefined.
343 @param capacity The maximum number of values that can be contained by
344 the CFDictionary. The dictionary starts empty, and can grow
345 to this number of values (and it can have less). If this
346 parameter is 0, the dictionary's maximum capacity is unlimited
347 (or rather, only limited by address space and available memory
348 constraints). If this parameter is negative, the behavior is
350 @param keyCallBacks A pointer to a CFDictionaryKeyCallBacks structure
351 initialized with the callbacks for the dictionary to use on
352 each key in the dictionary. A copy of the contents of the
353 callbacks structure is made, so that a pointer to a structure
354 on the stack can be passed in, or can be reused for multiple
355 dictionary creations. If the version field of this
356 callbacks structure is not one of the defined ones for
357 CFDictionary, the behavior is undefined. The retain field may
358 be NULL, in which case the CFDictionary will do nothing to add
359 a retain to the keys of the contained values. The release field
360 may be NULL, in which case the CFDictionary will do nothing
361 to remove the dictionary's retain (if any) on the keys when the
362 dictionary is destroyed or a key-value pair is removed. If the
363 copyDescription field is NULL, the dictionary will create a
364 simple description for a key. If the equal field is NULL, the
365 dictionary will use pointer equality to test for equality of
366 keys. If the hash field is NULL, a key will be converted from
367 a pointer to an integer to compute the hash code. This callbacks
368 parameter itself may be NULL, which is treated as if a valid
369 structure of version 0 with all fields NULL had been passed in.
370 Otherwise, if any of the fields are not valid pointers to
371 functions of the correct type, or this parameter is not a
372 valid pointer to a CFDictionaryKeyCallBacks callbacks structure,
373 the behavior is undefined. If any of the keys put into the
374 dictionary is not one understood by one of the callback functions
375 the behavior when that callback function is used is undefined.
376 @param valueCallBacks A pointer to a CFDictionaryValueCallBacks structure
377 initialized with the callbacks for the dictionary to use on
378 each value in the dictionary. The retain callback will be used
379 within this function, for example, to retain all of the new
380 values from the values C array. A copy of the contents of the
381 callbacks structure is made, so that a pointer to a structure
382 on the stack can be passed in, or can be reused for multiple
383 dictionary creations. If the version field of this callbacks
384 structure is not one of the defined ones for CFDictionary, the
385 behavior is undefined. The retain field may be NULL, in which
386 case the CFDictionary will do nothing to add a retain to values
387 as they are put into the dictionary. The release field may be
388 NULL, in which case the CFDictionary will do nothing to remove
389 the dictionary's retain (if any) on the values when the
390 dictionary is destroyed or a key-value pair is removed. If the
391 copyDescription field is NULL, the dictionary will create a
392 simple description for a value. If the equal field is NULL, the
393 dictionary will use pointer equality to test for equality of
394 values. This callbacks parameter itself may be NULL, which is
395 treated as if a valid structure of version 0 with all fields
396 NULL had been passed in. Otherwise,
397 if any of the fields are not valid pointers to functions
398 of the correct type, or this parameter is not a valid
399 pointer to a CFDictionaryValueCallBacks callbacks structure,
400 the behavior is undefined. If any of the values put into the
401 dictionary is not one understood by one of the callback functions
402 the behavior when that callback function is used is undefined.
403 @result A reference to the new mutable CFDictionary.
406 CFMutableDictionaryRef
CFDictionaryCreateMutable(CFAllocatorRef allocator
, CFIndex capacity
, const CFDictionaryKeyCallBacks
*keyCallBacks
, const CFDictionaryValueCallBacks
*valueCallBacks
);
409 @function CFDictionaryCreateMutableCopy
410 Creates a new mutable dictionary with the key-value pairs from
411 the given dictionary.
412 @param allocator The CFAllocator which should be used to allocate
413 memory for the dictionary and its storage for values. This
414 parameter may be NULL in which case the current default
415 CFAllocator is used. If this reference is not a valid
416 CFAllocator, the behavior is undefined.
417 @param capacity The maximum number of values that can be contained
418 by the CFDictionary. The dictionary starts empty, and can grow
419 to this number of values (and it can have less). If this
420 parameter is 0, the dictionary's maximum capacity is unlimited
421 (or rather, only limited by address space and available memory
422 constraints). This parameter must be greater than or equal
423 to the count of the dictionary which is to be copied, or the
424 behavior is undefined. If this parameter is negative, the
425 behavior is undefined.
426 @param theDict The dictionary which is to be copied. The keys and values
427 from the dictionary are copied as pointers into the new
428 dictionary (that is, the values themselves are copied, not
429 that which the values point to, if anything). However, the
430 keys and values are also retained by the new dictionary using
431 the retain function of the original dictionary.
432 The count of the new dictionary will be the same as the
433 given dictionary. The new dictionary uses the same callbacks
434 as the dictionary to be copied. If this parameter is
435 not a valid CFDictionary, the behavior is undefined.
436 @result A reference to the new mutable CFDictionary.
439 CFMutableDictionaryRef
CFDictionaryCreateMutableCopy(CFAllocatorRef allocator
, CFIndex capacity
, CFDictionaryRef theDict
);
442 @function CFDictionaryGetCount
443 Returns the number of values currently in the dictionary.
444 @param theDict The dictionary to be queried. If this parameter is
445 not a valid CFDictionary, the behavior is undefined.
446 @result The number of values in the dictionary.
449 CFIndex
CFDictionaryGetCount(CFDictionaryRef theDict
);
452 @function CFDictionaryGetCountOfKey
453 Counts the number of times the given key occurs in the dictionary.
454 @param theDict The dictionary to be searched. If this parameter is
455 not a valid CFDictionary, the behavior is undefined.
456 @param key The key for which to find matches in the dictionary. The
457 hash() and equal() key callbacks provided when the dictionary
458 was created are used to compare. If the hash() key callback
459 was NULL, the key is treated as a pointer and converted to
460 an integer. If the equal() key callback was NULL, pointer
461 equality (in C, ==) is used. If key, or any of the keys in
462 the dictionary, are not understood by the equal() callback,
463 the behavior is undefined.
464 @result Returns 1 if a matching key is used by the dictionary,
468 CFIndex
CFDictionaryGetCountOfKey(CFDictionaryRef theDict
, const void *key
);
471 @function CFDictionaryGetCountOfValue
472 Counts the number of times the given value occurs in the dictionary.
473 @param theDict The dictionary to be searched. If this parameter is
474 not a valid CFDictionary, the behavior is undefined.
475 @param value The value for which to find matches in the dictionary. The
476 equal() callback provided when the dictionary was created is
477 used to compare. If the equal() value callback was NULL, pointer
478 equality (in C, ==) is used. If value, or any of the values in
479 the dictionary, are not understood by the equal() callback,
480 the behavior is undefined.
481 @result The number of times the given value occurs in the dictionary.
484 CFIndex
CFDictionaryGetCountOfValue(CFDictionaryRef theDict
, const void *value
);
487 @function CFDictionaryContainsKey
488 Reports whether or not the key is in the dictionary.
489 @param theDict The dictionary to be searched. If this parameter is
490 not a valid CFDictionary, the behavior is undefined.
491 @param key The key for which to find matches in the dictionary. The
492 hash() and equal() key callbacks provided when the dictionary
493 was created are used to compare. If the hash() key callback
494 was NULL, the key is treated as a pointer and converted to
495 an integer. If the equal() key callback was NULL, pointer
496 equality (in C, ==) is used. If key, or any of the keys in
497 the dictionary, are not understood by the equal() callback,
498 the behavior is undefined.
499 @result true, if the key is in the dictionary, otherwise false.
502 Boolean
CFDictionaryContainsKey(CFDictionaryRef theDict
, const void *key
);
505 @function CFDictionaryContainsValue
506 Reports whether or not the value is in the dictionary.
507 @param theDict The dictionary to be searched. If this parameter is
508 not a valid CFDictionary, the behavior is undefined.
509 @param value The value for which to find matches in the dictionary. The
510 equal() callback provided when the dictionary was created is
511 used to compare. If the equal() callback was NULL, pointer
512 equality (in C, ==) is used. If value, or any of the values
513 in the dictionary, are not understood by the equal() callback,
514 the behavior is undefined.
515 @result true, if the value is in the dictionary, otherwise false.
518 Boolean
CFDictionaryContainsValue(CFDictionaryRef theDict
, const void *value
);
521 @function CFDictionaryGetValue
522 Retrieves the value associated with the given key.
523 @param theDict The dictionary to be queried. If this parameter is
524 not a valid CFDictionary, the behavior is undefined.
525 @param key The key for which to find a match in the dictionary. The
526 hash() and equal() key callbacks provided when the dictionary
527 was created are used to compare. If the hash() key callback
528 was NULL, the key is treated as a pointer and converted to
529 an integer. If the equal() key callback was NULL, pointer
530 equality (in C, ==) is used. If key, or any of the keys in
531 the dictionary, are not understood by the equal() callback,
532 the behavior is undefined.
533 @result The value with the given key in the dictionary, or NULL if
534 no key-value pair with a matching key exists. Since NULL
535 can be a valid value in some dictionaries, the function
536 CFDictionaryGetValueIfPresent() must be used to distinguish
537 NULL-no-found from NULL-is-the-value.
540 const void *CFDictionaryGetValue(CFDictionaryRef theDict
, const void *key
);
543 @function CFDictionaryGetValueIfPresent
544 Retrieves the value associated with the given key.
545 @param theDict The dictionary to be queried. If this parameter is
546 not a valid CFDictionary, the behavior is undefined.
547 @param key The key for which to find a match in the dictionary. The
548 hash() and equal() key callbacks provided when the dictionary
549 was created are used to compare. If the hash() key callback
550 was NULL, the key is treated as a pointer and converted to
551 an integer. If the equal() key callback was NULL, pointer
552 equality (in C, ==) is used. If key, or any of the keys in
553 the dictionary, are not understood by the equal() callback,
554 the behavior is undefined.
555 @param value A pointer to memory which should be filled with the
556 pointer-sized value if a matching key is found. If no key
557 match is found, the contents of the storage pointed to by
558 this parameter are undefined. This parameter may be NULL,
559 in which case the value from the dictionary is not returned
560 (but the return value of this function still indicates
561 whether or not the key-value pair was present).
562 @result true, if a matching key was found, false otherwise.
565 Boolean
CFDictionaryGetValueIfPresent(CFDictionaryRef theDict
, const void *key
, const void **value
);
568 @function CFDictionaryGetKeysAndValues
569 Fills the two buffers with the keys and values from the dictionary.
570 @param theDict The dictionary to be queried. If this parameter is
571 not a valid CFDictionary, the behavior is undefined.
572 @param keys A C array of pointer-sized values to be filled with keys
573 from the dictionary. The keys and values C arrays are parallel
574 to each other (that is, the items at the same indices form a
575 key-value pair from the dictionary). This parameter may be NULL
576 if the keys are not desired. If this parameter is not a valid
577 pointer to a C array of at least CFDictionaryGetCount() pointers,
578 or NULL, the behavior is undefined.
579 @param values A C array of pointer-sized values to be filled with values
580 from the dictionary. The keys and values C arrays are parallel
581 to each other (that is, the items at the same indices form a
582 key-value pair from the dictionary). This parameter may be NULL
583 if the values are not desired. If this parameter is not a valid
584 pointer to a C array of at least CFDictionaryGetCount() pointers,
585 or NULL, the behavior is undefined.
588 void CFDictionaryGetKeysAndValues(CFDictionaryRef theDict
, const void **keys
, const void **values
);
591 @function CFDictionaryApplyFunction
592 Calls a function once for each value in the dictionary.
593 @param theDict The dictionary to be queried. If this parameter is
594 not a valid CFDictionary, the behavior is undefined.
595 @param applier The callback function to call once for each value in
596 the dictionary. If this parameter is not a
597 pointer to a function of the correct prototype, the behavior
598 is undefined. If there are keys or values which the
599 applier function does not expect or cannot properly apply
600 to, the behavior is undefined.
601 @param context A pointer-sized user-defined value, which is passed
602 as the third parameter to the applier function, but is
603 otherwise unused by this function. If the context is not
604 what is expected by the applier function, the behavior is
608 void CFDictionaryApplyFunction(CFDictionaryRef theDict
, CFDictionaryApplierFunction applier
, void *context
);
611 @function CFDictionaryAddValue
612 Adds the key-value pair to the dictionary if no such key already exists.
613 @param theDict The dictionary to which the value is to be added. If this
614 parameter is not a valid mutable CFDictionary, the behavior is
615 undefined. If the dictionary is a fixed-capacity dictionary and
616 it is full before this operation, the behavior is undefined.
617 @param key The key of the value to add to the dictionary. The key is
618 retained by the dictionary using the retain callback provided
619 when the dictionary was created. If the key is not of the sort
620 expected by the retain callback, the behavior is undefined. If
621 a key which matches this key is already present in the dictionary,
622 this function does nothing ("add if absent").
623 @param value The value to add to the dictionary. The value is retained
624 by the dictionary using the retain callback provided when the
625 dictionary was created. If the value is not of the sort expected
626 by the retain callback, the behavior is undefined.
629 void CFDictionaryAddValue(CFMutableDictionaryRef theDict
, const void *key
, const void *value
);
632 @function CFDictionarySetValue
633 Sets the value of the key in the dictionary.
634 @param theDict The dictionary to which the value is to be set. If this
635 parameter is not a valid mutable CFDictionary, the behavior is
636 undefined. If the dictionary is a fixed-capacity dictionary and
637 it is full before this operation, and the key does not exist in
638 the dictionary, the behavior is undefined.
639 @param key The key of the value to set into the dictionary. If a key
640 which matches this key is already present in the dictionary, only
641 the value is changed ("add if absent, replace if present"). If
642 no key matches the given key, the key-value pair is added to the
643 dictionary. If added, the key is retained by the dictionary,
644 using the retain callback provided
645 when the dictionary was created. If the key is not of the sort
646 expected by the key retain callback, the behavior is undefined.
647 @param value The value to add to or replace into the dictionary. The value
648 is retained by the dictionary using the retain callback provided
649 when the dictionary was created, and the previous value if any is
650 released. If the value is not of the sort expected by the
651 retain or release callbacks, the behavior is undefined.
654 void CFDictionarySetValue(CFMutableDictionaryRef theDict
, const void *key
, const void *value
);
657 @function CFDictionaryReplaceValue
658 Replaces the value of the key in the dictionary.
659 @param theDict The dictionary to which the value is to be replaced. If this
660 parameter is not a valid mutable CFDictionary, the behavior is
662 @param key The key of the value to replace in the dictionary. If a key
663 which matches this key is present in the dictionary, the value
664 is changed to the given value, otherwise this function does
665 nothing ("replace if present").
666 @param value The value to replace into the dictionary. The value
667 is retained by the dictionary using the retain callback provided
668 when the dictionary was created, and the previous value is
669 released. If the value is not of the sort expected by the
670 retain or release callbacks, the behavior is undefined.
673 void CFDictionaryReplaceValue(CFMutableDictionaryRef theDict
, const void *key
, const void *value
);
676 @function CFDictionaryRemoveValue
677 Removes the value of the key from the dictionary.
678 @param theDict The dictionary from which the value is to be removed. If this
679 parameter is not a valid mutable CFDictionary, the behavior is
681 @param key The key of the value to remove from the dictionary. If a key
682 which matches this key is present in the dictionary, the key-value
683 pair is removed from the dictionary, otherwise this function does
684 nothing ("remove if present").
687 void CFDictionaryRemoveValue(CFMutableDictionaryRef theDict
, const void *key
);
690 @function CFDictionaryRemoveAllValues
691 Removes all the values from the dictionary, making it empty.
692 @param theDict The dictionary from which all of the values are to be
693 removed. If this parameter is not a valid mutable
694 CFDictionary, the behavior is undefined.
697 void CFDictionaryRemoveAllValues(CFMutableDictionaryRef theDict
);
699 #if defined(__cplusplus)
703 #endif /* ! __COREFOUNDATION_CFDICTIONARY__ */