]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
d8925383 | 2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. |
9ce05555 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
9ce05555 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* CFArray.h | |
d8925383 | 24 | Copyright (c) 1998-2005, Apple, Inc. All rights reserved. |
9ce05555 A |
25 | */ |
26 | ||
27 | /*! | |
28 | @header CFArray | |
29 | CFArray implements an ordered, compact container of pointer-sized | |
30 | values. Values are accessed via integer keys (indices), from the | |
31 | range 0 to N-1, where N is the number of values in the array when | |
32 | an operation is performed. The array is said to be "compact" because | |
33 | deleted or inserted values do not leave a gap in the key space -- | |
34 | the values with higher-numbered indices have their indices | |
35 | renumbered lower (or higher, in the case of insertion) so that the | |
36 | set of valid indices is always in the integer range [0, N-1]. Thus, | |
37 | the index to access a particular value in the array may change over | |
38 | time as other values are inserted into or deleted from the array. | |
39 | ||
40 | Arrays come in two flavors, immutable, which cannot have values | |
41 | added to them or removed from them after the array is created, and | |
42 | mutable, to which you can add values or from which remove values. | |
43 | Mutable arrays have two subflavors, fixed-capacity, for which there | |
44 | is a maximum number set at creation time of values which can be put | |
45 | into the array, and variable capacity, which can have an unlimited | |
46 | number of values (or rather, limited only by constraints external | |
47 | to CFArray, like the amount of available memory). Fixed-capacity | |
48 | arrays can be somewhat higher performing, if you can put a definite | |
49 | upper limit on the number of values that might be put into the | |
50 | array. | |
51 | ||
52 | As with all CoreFoundation collection types, arrays maintain hard | |
53 | references on the values you put in them, but the retaining and | |
54 | releasing functions are user-defined callbacks that can actually do | |
55 | whatever the user wants (for example, nothing). | |
56 | ||
57 | Computational Complexity | |
58 | The access time for a value in the array is guaranteed to be at | |
59 | worst O(lg N) for any implementation, current and future, but will | |
60 | often be O(1) (constant time). Linear search operations similarly | |
61 | have a worst case complexity of O(N*lg N), though typically the | |
62 | bounds will be tighter, and so on. Insertion or deletion operations | |
63 | will typically be linear in the number of values in the array, but | |
64 | may be O(N*lg N) clearly in the worst case in some implementations. | |
65 | There are no favored positions within the array for performance; | |
66 | that is, it is not necessarily faster to access values with low | |
67 | indices, or to insert or delete values with high indices, or | |
68 | whatever. | |
69 | */ | |
70 | ||
71 | #if !defined(__COREFOUNDATION_CFARRAY__) | |
72 | #define __COREFOUNDATION_CFARRAY__ 1 | |
73 | ||
74 | #include <CoreFoundation/CFBase.h> | |
75 | ||
76 | #if defined(__cplusplus) | |
77 | extern "C" { | |
78 | #endif | |
79 | ||
80 | /*! | |
81 | @typedef CFArrayCallBacks | |
82 | Structure containing the callbacks of a CFArray. | |
83 | @field version The version number of the structure type being passed | |
84 | in as a parameter to the CFArray creation functions. This | |
85 | structure is version 0. | |
86 | @field retain The callback used to add a retain for the array on | |
87 | values as they are put into the array. This callback returns | |
88 | the value to store in the array, which is usually the value | |
89 | parameter passed to this callback, but may be a different | |
90 | value if a different value should be stored in the array. | |
91 | The array's allocator is passed as the first argument. | |
92 | @field release The callback used to remove a retain previously added | |
93 | for the array from values as they are removed from the | |
94 | array. The array's allocator is passed as the first | |
95 | argument. | |
96 | @field copyDescription The callback used to create a descriptive | |
97 | string representation of each value in the array. This is | |
98 | used by the CFCopyDescription() function. | |
99 | @field equal The callback used to compare values in the array for | |
100 | equality for some operations. | |
101 | */ | |
102 | typedef const void * (*CFArrayRetainCallBack)(CFAllocatorRef allocator, const void *value); | |
103 | typedef void (*CFArrayReleaseCallBack)(CFAllocatorRef allocator, const void *value); | |
104 | typedef CFStringRef (*CFArrayCopyDescriptionCallBack)(const void *value); | |
105 | typedef Boolean (*CFArrayEqualCallBack)(const void *value1, const void *value2); | |
106 | typedef struct { | |
107 | CFIndex version; | |
108 | CFArrayRetainCallBack retain; | |
109 | CFArrayReleaseCallBack release; | |
110 | CFArrayCopyDescriptionCallBack copyDescription; | |
111 | CFArrayEqualCallBack equal; | |
112 | } CFArrayCallBacks; | |
113 | ||
114 | /*! | |
115 | @constant kCFTypeArrayCallBacks | |
116 | Predefined CFArrayCallBacks structure containing a set of callbacks | |
117 | appropriate for use when the values in a CFArray are all CFTypes. | |
118 | */ | |
119 | CF_EXPORT | |
120 | const CFArrayCallBacks kCFTypeArrayCallBacks; | |
121 | ||
122 | /*! | |
123 | @typedef CFArrayApplierFunction | |
124 | Type of the callback function used by the apply functions of | |
125 | CFArrays. | |
126 | @param value The current value from the array. | |
127 | @param context The user-defined context parameter given to the apply | |
128 | function. | |
129 | */ | |
130 | typedef void (*CFArrayApplierFunction)(const void *value, void *context); | |
131 | ||
132 | /*! | |
133 | @typedef CFArrayRef | |
134 | This is the type of a reference to immutable CFArrays. | |
135 | */ | |
136 | typedef const struct __CFArray * CFArrayRef; | |
137 | ||
138 | /*! | |
139 | @typedef CFMutableArrayRef | |
140 | This is the type of a reference to mutable CFArrays. | |
141 | */ | |
142 | typedef struct __CFArray * CFMutableArrayRef; | |
143 | ||
144 | /*! | |
145 | @function CFArrayGetTypeID | |
146 | Returns the type identifier of all CFArray instances. | |
147 | */ | |
148 | CF_EXPORT | |
149 | CFTypeID CFArrayGetTypeID(void); | |
150 | ||
151 | /*! | |
152 | @function CFArrayCreate | |
153 | Creates a new immutable array with the given values. | |
154 | @param allocator The CFAllocator which should be used to allocate | |
155 | memory for the array and its storage for values. This | |
156 | parameter may be NULL in which case the current default | |
157 | CFAllocator is used. If this reference is not a valid | |
158 | CFAllocator, the behavior is undefined. | |
159 | @param values A C array of the pointer-sized values to be in the | |
160 | array. The values in the array are ordered in the same order | |
161 | in which they appear in this C array. This parameter may be | |
162 | NULL if the numValues parameter is 0. This C array is not | |
163 | changed or freed by this function. If this parameter is not | |
164 | a valid pointer to a C array of at least numValues pointers, | |
165 | the behavior is undefined. | |
166 | @param numValues The number of values to copy from the values C | |
167 | array into the CFArray. This number will be the count of the | |
168 | array. | |
169 | If this parameter is negative, or greater than the number of | |
170 | values actually in the value's C array, the behavior is | |
171 | undefined. | |
172 | @param callBacks A pointer to a CFArrayCallBacks structure | |
173 | initialized with the callbacks for the array to use on each | |
174 | value in the array. The retain callback will be used within | |
175 | this function, for example, to retain all of the new values | |
176 | from the values C array. A copy of the contents of the | |
177 | callbacks structure is made, so that a pointer to a | |
178 | structure on the stack can be passed in, or can be reused | |
179 | for multiple array creations. If the version field of this | |
180 | callbacks structure is not one of the defined ones for | |
181 | CFArray, the behavior is undefined. The retain field may be | |
182 | NULL, in which case the CFArray will do nothing to add a | |
183 | retain to the contained values for the array. The release | |
184 | field may be NULL, in which case the CFArray will do nothing | |
185 | to remove the array's retain (if any) on the values when the | |
186 | array is destroyed. If the copyDescription field is NULL, | |
187 | the array will create a simple description for the value. If | |
188 | the equal field is NULL, the array will use pointer equality | |
189 | to test for equality of values. This callbacks parameter | |
190 | itself may be NULL, which is treated as if a valid structure | |
191 | of version 0 with all fields NULL had been passed in. | |
192 | Otherwise, if any of the fields are not valid pointers to | |
193 | functions of the correct type, or this parameter is not a | |
194 | valid pointer to a CFArrayCallBacks callbacks structure, | |
195 | the behavior is undefined. If any of the values put into the | |
196 | array is not one understood by one of the callback functions | |
197 | the behavior when that callback function is used is | |
198 | undefined. | |
199 | @result A reference to the new immutable CFArray. | |
200 | */ | |
201 | CF_EXPORT | |
202 | CFArrayRef CFArrayCreate(CFAllocatorRef allocator, const void **values, CFIndex numValues, const CFArrayCallBacks *callBacks); | |
203 | ||
204 | /*! | |
205 | @function CFArrayCreateCopy | |
206 | Creates a new immutable array with the values from the given array. | |
207 | @param allocator The CFAllocator which should be used to allocate | |
208 | memory for the array and its storage for values. This | |
209 | parameter may be NULL in which case the current default | |
210 | CFAllocator is used. If this reference is not a valid | |
211 | CFAllocator, the behavior is undefined. | |
212 | @param theArray The array which is to be copied. The values from the | |
213 | array are copied as pointers into the new array (that is, | |
214 | the values themselves are copied, not that which the values | |
215 | point to, if anything). However, the values are also | |
216 | retained by the new array. The count of the new array will | |
217 | be the same as the given array. The new array uses the same | |
218 | callbacks as the array to be copied. If this parameter is | |
219 | not a valid CFArray, the behavior is undefined. | |
220 | @result A reference to the new immutable CFArray. | |
221 | */ | |
222 | CF_EXPORT | |
223 | CFArrayRef CFArrayCreateCopy(CFAllocatorRef allocator, CFArrayRef theArray); | |
224 | ||
225 | /*! | |
226 | @function CFArrayCreateMutable | |
227 | Creates a new empty mutable array. | |
228 | @param allocator The CFAllocator which should be used to allocate | |
229 | memory for the array and its storage for values. This | |
230 | parameter may be NULL in which case the current default | |
231 | CFAllocator is used. If this reference is not a valid | |
232 | CFAllocator, the behavior is undefined. | |
233 | @param capacity The maximum number of values that can be contained | |
234 | by the CFArray. The array starts empty, and can grow to this | |
235 | number of values (and it can have less). If this parameter | |
236 | is 0, the array's maximum capacity is unlimited (or rather, | |
237 | only limited by address space and available memory | |
238 | constraints). If this parameter is negative, the behavior is | |
239 | undefined. | |
240 | @param callBacks A pointer to a CFArrayCallBacks structure | |
241 | initialized with the callbacks for the array to use on each | |
242 | value in the array. A copy of the contents of the | |
243 | callbacks structure is made, so that a pointer to a | |
244 | structure on the stack can be passed in, or can be reused | |
245 | for multiple array creations. If the version field of this | |
246 | callbacks structure is not one of the defined ones for | |
247 | CFArray, the behavior is undefined. The retain field may be | |
248 | NULL, in which case the CFArray will do nothing to add a | |
249 | retain to the contained values for the array. The release | |
250 | field may be NULL, in which case the CFArray will do nothing | |
251 | to remove the arrays retain (if any) on the values when the | |
252 | array is destroyed. If the copyDescription field is NULL, | |
253 | the array will create a simple description for the value. If | |
254 | the equal field is NULL, the array will use pointer equality | |
255 | to test for equality of values. This callbacks parameter | |
256 | itself may be NULL, which is treated as if a valid structure | |
257 | of version 0 with all fields NULL had been passed in. | |
258 | Otherwise, if any of the fields are not valid pointers to | |
259 | functions of the correct type, or this parameter is not a | |
260 | valid pointer to a CFArrayCallBacks callbacks structure, | |
261 | the behavior is undefined. If any of the values put into the | |
262 | array is not one understood by one of the callback functions | |
263 | the behavior when that callback function is used is | |
264 | undefined. | |
265 | @result A reference to the new mutable CFArray. | |
266 | */ | |
267 | CF_EXPORT | |
268 | CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks); | |
269 | ||
270 | /*! | |
271 | @function CFArrayCreateMutableCopy | |
272 | Creates a new mutable array with the values from the given array. | |
273 | @param allocator The CFAllocator which should be used to allocate | |
274 | memory for the array and its storage for values. This | |
275 | parameter may be NULL in which case the current default | |
276 | CFAllocator is used. If this reference is not a valid | |
277 | CFAllocator, the behavior is undefined. | |
278 | @param capacity The maximum number of values that can be contained | |
279 | by the CFArray. The array starts empty, and can grow to this | |
280 | number of values (and it can have less). If this parameter | |
281 | is 0, the array's maximum capacity is unlimited (or rather, | |
282 | only limited by address space and available memory | |
283 | constraints). This parameter must be greater than or equal | |
284 | to the count of the array which is to be copied, or the | |
285 | behavior is undefined. If this parameter is negative, the | |
286 | behavior is undefined. | |
287 | @param theArray The array which is to be copied. The values from the | |
288 | array are copied as pointers into the new array (that is, | |
289 | the values themselves are copied, not that which the values | |
290 | point to, if anything). However, the values are also | |
291 | retained by the new array. The count of the new array will | |
292 | be the same as the given array. The new array uses the same | |
293 | callbacks as the array to be copied. If this parameter is | |
294 | not a valid CFArray, the behavior is undefined. | |
295 | @result A reference to the new mutable CFArray. | |
296 | */ | |
297 | CF_EXPORT | |
298 | CFMutableArrayRef CFArrayCreateMutableCopy(CFAllocatorRef allocator, CFIndex capacity, CFArrayRef theArray); | |
299 | ||
300 | /*! | |
301 | @function CFArrayGetCount | |
302 | Returns the number of values currently in the array. | |
303 | @param theArray The array to be queried. If this parameter is not a valid | |
304 | CFArray, the behavior is undefined. | |
305 | @result The number of values in the array. | |
306 | */ | |
307 | CF_EXPORT | |
308 | CFIndex CFArrayGetCount(CFArrayRef theArray); | |
309 | ||
310 | /*! | |
311 | @function CFArrayGetCountOfValue | |
312 | Counts the number of times the given value occurs in the array. | |
313 | @param theArray The array to be searched. If this parameter is not a | |
314 | valid CFArray, the behavior is undefined. | |
315 | @param range The range within the array to search. If the range | |
316 | location or end point (defined by the location plus length | |
317 | minus 1) is outside the index space of the array (0 to | |
318 | N-1 inclusive, where N is the count of the array), the | |
319 | behavior is undefined. If the range length is negative, the | |
320 | behavior is undefined. The range may be empty (length 0). | |
321 | @param value The value for which to find matches in the array. The | |
322 | equal() callback provided when the array was created is | |
323 | used to compare. If the equal() callback was NULL, pointer | |
324 | equality (in C, ==) is used. If value, or any of the values | |
325 | in the array, are not understood by the equal() callback, | |
326 | the behavior is undefined. | |
327 | @result The number of times the given value occurs in the array, | |
328 | within the specified range. | |
329 | */ | |
330 | CF_EXPORT | |
331 | CFIndex CFArrayGetCountOfValue(CFArrayRef theArray, CFRange range, const void *value); | |
332 | ||
333 | /*! | |
334 | @function CFArrayContainsValue | |
335 | Reports whether or not the value is in the array. | |
336 | @param theArray The array to be searched. If this parameter is not a | |
337 | valid CFArray, the behavior is undefined. | |
338 | @param range The range within the array to search. If the range | |
339 | location or end point (defined by the location plus length | |
340 | minus 1) is outside the index space of the array (0 to | |
341 | N-1 inclusive, where N is the count of the array), the | |
342 | behavior is undefined. If the range length is negative, the | |
343 | behavior is undefined. The range may be empty (length 0). | |
344 | @param value The value for which to find matches in the array. The | |
345 | equal() callback provided when the array was created is | |
346 | used to compare. If the equal() callback was NULL, pointer | |
347 | equality (in C, ==) is used. If value, or any of the values | |
348 | in the array, are not understood by the equal() callback, | |
349 | the behavior is undefined. | |
350 | @result true, if the value is in the specified range of the array, | |
351 | otherwise false. | |
352 | */ | |
353 | CF_EXPORT | |
354 | Boolean CFArrayContainsValue(CFArrayRef theArray, CFRange range, const void *value); | |
355 | ||
356 | /*! | |
357 | @function CFArrayGetValueAtIndex | |
358 | Retrieves the value at the given index. | |
359 | @param theArray The array to be queried. If this parameter is not a | |
360 | valid CFArray, the behavior is undefined. | |
361 | @param idx The index of the value to retrieve. If the index is | |
362 | outside the index space of the array (0 to N-1 inclusive, | |
363 | where N is the count of the array), the behavior is | |
364 | undefined. | |
365 | @result The value with the given index in the array. | |
366 | */ | |
367 | CF_EXPORT | |
368 | const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); | |
369 | ||
370 | /*! | |
371 | @function CFArrayGetValues | |
372 | Fills the buffer with values from the array. | |
373 | @param theArray The array to be queried. If this parameter is not a | |
374 | valid CFArray, the behavior is undefined. | |
375 | @param range The range of values within the array to retrieve. If | |
376 | the range location or end point (defined by the location | |
377 | plus length minus 1) is outside the index space of the | |
378 | array (0 to N-1 inclusive, where N is the count of the | |
379 | array), the behavior is undefined. If the range length is | |
380 | negative, the behavior is undefined. The range may be empty | |
381 | (length 0), in which case no values are put into the buffer. | |
382 | @param values A C array of pointer-sized values to be filled with | |
383 | values from the array. The values in the C array are ordered | |
384 | in the same order in which they appear in the array. If this | |
385 | parameter is not a valid pointer to a C array of at least | |
386 | range.length pointers, the behavior is undefined. | |
387 | */ | |
388 | CF_EXPORT | |
389 | void CFArrayGetValues(CFArrayRef theArray, CFRange range, const void **values); | |
390 | ||
391 | /*! | |
392 | @function CFArrayApplyFunction | |
393 | Calls a function once for each value in the array. | |
394 | @param theArray The array to be operated upon. If this parameter is not | |
395 | a valid CFArray, the behavior is undefined. | |
396 | @param range The range of values within the array to which to apply | |
397 | the function. If the range location or end point (defined by | |
398 | the location plus length minus 1) is outside the index | |
399 | space of the array (0 to N-1 inclusive, where N is the count | |
400 | of the array), the behavior is undefined. If the range | |
401 | length is negative, the behavior is undefined. The range may | |
402 | be empty (length 0). | |
403 | @param applier The callback function to call once for each value in | |
404 | the given range in the array. If this parameter is not a | |
405 | pointer to a function of the correct prototype, the behavior | |
406 | is undefined. If there are values in the range which the | |
407 | applier function does not expect or cannot properly apply | |
408 | to, the behavior is undefined. | |
409 | @param context A pointer-sized user-defined value, which is passed | |
410 | as the second parameter to the applier function, but is | |
411 | otherwise unused by this function. If the context is not | |
412 | what is expected by the applier function, the behavior is | |
413 | undefined. | |
414 | */ | |
415 | CF_EXPORT | |
416 | void CFArrayApplyFunction(CFArrayRef theArray, CFRange range, CFArrayApplierFunction applier, void *context); | |
417 | ||
418 | /*! | |
419 | @function CFArrayGetFirstIndexOfValue | |
420 | Searches the array for the value. | |
421 | @param theArray The array to be searched. If this parameter is not a | |
422 | valid CFArray, the behavior is undefined. | |
423 | @param range The range within the array to search. If the range | |
424 | location or end point (defined by the location plus length | |
425 | minus 1) is outside the index space of the array (0 to | |
426 | N-1 inclusive, where N is the count of the array), the | |
427 | behavior is undefined. If the range length is negative, the | |
428 | behavior is undefined. The range may be empty (length 0). | |
429 | The search progresses from the smallest index defined by | |
430 | the range to the largest. | |
431 | @param value The value for which to find a match in the array. The | |
432 | equal() callback provided when the array was created is | |
433 | used to compare. If the equal() callback was NULL, pointer | |
434 | equality (in C, ==) is used. If value, or any of the values | |
435 | in the array, are not understood by the equal() callback, | |
436 | the behavior is undefined. | |
437 | @result The lowest index of the matching values in the range, or | |
438 | kCFNotFound if no value in the range matched. | |
439 | */ | |
440 | CF_EXPORT | |
441 | CFIndex CFArrayGetFirstIndexOfValue(CFArrayRef theArray, CFRange range, const void *value); | |
442 | ||
443 | /*! | |
444 | @function CFArrayGetLastIndexOfValue | |
445 | Searches the array for the value. | |
446 | @param theArray The array to be searched. If this parameter is not a | |
447 | valid CFArray, the behavior is undefined. | |
448 | @param range The range within the array to search. If the range | |
449 | location or end point (defined by the location plus length | |
450 | minus 1) is outside the index space of the array (0 to | |
451 | N-1 inclusive, where N is the count of the array), the | |
452 | behavior is undefined. If the range length is negative, the | |
453 | behavior is undefined. The range may be empty (length 0). | |
454 | The search progresses from the largest index defined by the | |
455 | range to the smallest. | |
456 | @param value The value for which to find a match in the array. The | |
457 | equal() callback provided when the array was created is | |
458 | used to compare. If the equal() callback was NULL, pointer | |
459 | equality (in C, ==) is used. If value, or any of the values | |
460 | in the array, are not understood by the equal() callback, | |
461 | the behavior is undefined. | |
462 | @result The highest index of the matching values in the range, or | |
463 | kCFNotFound if no value in the range matched. | |
464 | */ | |
465 | CF_EXPORT | |
466 | CFIndex CFArrayGetLastIndexOfValue(CFArrayRef theArray, CFRange range, const void *value); | |
467 | ||
468 | /*! | |
469 | @function CFArrayBSearchValues | |
470 | Searches the array for the value using a binary search algorithm. | |
471 | @param theArray The array to be searched. If this parameter is not a | |
472 | valid CFArray, the behavior is undefined. If the array is | |
473 | not sorted from least to greatest according to the | |
474 | comparator function, the behavior is undefined. | |
475 | @param range The range within the array to search. If the range | |
476 | location or end point (defined by the location plus length | |
477 | minus 1) is outside the index space of the array (0 to | |
478 | N-1 inclusive, where N is the count of the array), the | |
479 | behavior is undefined. If the range length is negative, the | |
480 | behavior is undefined. The range may be empty (length 0). | |
481 | @param value The value for which to find a match in the array. If | |
482 | value, or any of the values in the array, are not understood | |
483 | by the comparator callback, the behavior is undefined. | |
484 | @param comparator The function with the comparator function type | |
485 | signature which is used in the binary search operation to | |
486 | compare values in the array with the given value. If this | |
487 | parameter is not a pointer to a function of the correct | |
488 | prototype, the behavior is undefined. If there are values | |
489 | in the range which the comparator function does not expect | |
490 | or cannot properly compare, the behavior is undefined. | |
491 | @param context A pointer-sized user-defined value, which is passed | |
492 | as the third parameter to the comparator function, but is | |
493 | otherwise unused by this function. If the context is not | |
494 | what is expected by the comparator function, the behavior is | |
495 | undefined. | |
496 | @result The return value is either 1) the index of a value that | |
497 | matched, if the target value matches one or more in the | |
498 | range, 2) greater than or equal to the end point of the | |
499 | range, if the value is greater than all the values in the | |
500 | range, or 3) the index of the value greater than the target | |
501 | value, if the value lies between two of (or less than all | |
502 | of) the values in the range. | |
503 | */ | |
504 | CF_EXPORT | |
505 | CFIndex CFArrayBSearchValues(CFArrayRef theArray, CFRange range, const void *value, CFComparatorFunction comparator, void *context); | |
506 | ||
507 | /*! | |
508 | @function CFArrayAppendValue | |
509 | Adds the value to the array giving it a new largest index. | |
510 | @param theArray The array to which the value is to be added. If this | |
511 | parameter is not a valid mutable CFArray, the behavior is | |
512 | undefined. If the array is a fixed-capacity array and it | |
513 | is full before this operation, the behavior is undefined. | |
514 | @param value The value to add to the array. The value is retained by | |
515 | the array using the retain callback provided when the array | |
516 | was created. If the value is not of the sort expected by the | |
517 | retain callback, the behavior is undefined. The value is | |
518 | assigned to the index one larger than the previous largest | |
519 | index, and the count of the array is increased by one. | |
520 | */ | |
521 | CF_EXPORT | |
522 | void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value); | |
523 | ||
524 | /*! | |
525 | @function CFArrayInsertValueAtIndex | |
526 | Adds the value to the array, giving it the given index. | |
527 | @param theArray The array to which the value is to be added. If this | |
528 | parameter is not a valid mutable CFArray, the behavior is | |
529 | undefined. If the array is a fixed-capacity array and it | |
530 | is full before this operation, the behavior is undefined. | |
531 | @param idx The index to which to add the new value. If the index is | |
532 | outside the index space of the array (0 to N inclusive, | |
533 | where N is the count of the array before the operation), the | |
534 | behavior is undefined. If the index is the same as N, this | |
535 | function has the same effect as CFArrayAppendValue(). | |
536 | @param value The value to add to the array. The value is retained by | |
537 | the array using the retain callback provided when the array | |
538 | was created. If the value is not of the sort expected by the | |
539 | retain callback, the behavior is undefined. The value is | |
540 | assigned to the given index, and all values with equal and | |
541 | larger indices have their indexes increased by one. | |
542 | */ | |
543 | CF_EXPORT | |
544 | void CFArrayInsertValueAtIndex(CFMutableArrayRef theArray, CFIndex idx, const void *value); | |
545 | ||
546 | /*! | |
547 | @function CFArraySetValueAtIndex | |
548 | Changes the value with the given index in the array. | |
549 | @param theArray The array in which the value is to be changed. If this | |
550 | parameter is not a valid mutable CFArray, the behavior is | |
551 | undefined. If the array is a fixed-capacity array and it | |
552 | is full before this operation and the index is the same as | |
553 | N, the behavior is undefined. | |
554 | @param idx The index to which to set the new value. If the index is | |
555 | outside the index space of the array (0 to N inclusive, | |
556 | where N is the count of the array before the operation), the | |
557 | behavior is undefined. If the index is the same as N, this | |
558 | function has the same effect as CFArrayAppendValue(). | |
559 | @param value The value to set in the array. The value is retained by | |
560 | the array using the retain callback provided when the array | |
561 | was created, and the previous value with that index is | |
562 | released. If the value is not of the sort expected by the | |
563 | retain callback, the behavior is undefined. The indices of | |
564 | other values is not affected. | |
565 | */ | |
566 | CF_EXPORT | |
567 | void CFArraySetValueAtIndex(CFMutableArrayRef theArray, CFIndex idx, const void *value); | |
568 | ||
569 | /*! | |
570 | @function CFArrayRemoveValueAtIndex | |
571 | Removes the value with the given index from the array. | |
572 | @param theArray The array from which the value is to be removed. If | |
573 | this parameter is not a valid mutable CFArray, the behavior | |
574 | is undefined. | |
575 | @param idx The index from which to remove the value. If the index is | |
576 | outside the index space of the array (0 to N-1 inclusive, | |
577 | where N is the count of the array before the operation), the | |
578 | behavior is undefined. | |
579 | */ | |
580 | CF_EXPORT | |
581 | void CFArrayRemoveValueAtIndex(CFMutableArrayRef theArray, CFIndex idx); | |
582 | ||
583 | /*! | |
584 | @function CFArrayRemoveAllValues | |
585 | Removes all the values from the array, making it empty. | |
586 | @param theArray The array from which all of the values are to be | |
587 | removed. If this parameter is not a valid mutable CFArray, | |
588 | the behavior is undefined. | |
589 | */ | |
590 | CF_EXPORT | |
591 | void CFArrayRemoveAllValues(CFMutableArrayRef theArray); | |
592 | ||
593 | /*! | |
594 | @function CFArrayReplaceValues | |
595 | Replaces a range of values in the array. | |
596 | @param theArray The array from which all of the values are to be | |
597 | removed. If this parameter is not a valid mutable CFArray, | |
598 | the behavior is undefined. | |
599 | @param range The range of values within the array to replace. If the | |
600 | range location or end point (defined by the location plus | |
601 | length minus 1) is outside the index space of the array (0 | |
602 | to N inclusive, where N is the count of the array), the | |
603 | behavior is undefined. If the range length is negative, the | |
604 | behavior is undefined. The range may be empty (length 0), | |
605 | in which case the new values are merely inserted at the | |
606 | range location. | |
607 | @param newValues A C array of the pointer-sized values to be placed | |
608 | into the array. The new values in the array are ordered in | |
609 | the same order in which they appear in this C array. This | |
610 | parameter may be NULL if the newCount parameter is 0. This | |
611 | C array is not changed or freed by this function. If this | |
612 | parameter is not a valid pointer to a C array of at least | |
613 | newCount pointers, the behavior is undefined. | |
614 | @param newCount The number of values to copy from the values C | |
615 | array into the CFArray. If this parameter is different than | |
616 | the range length, the excess newCount values will be | |
617 | inserted after the range, or the excess range values will be | |
618 | deleted. This parameter may be 0, in which case no new | |
619 | values are replaced into the array and the values in the | |
620 | range are simply removed. If this parameter is negative, or | |
621 | greater than the number of values actually in the newValues | |
622 | C array, the behavior is undefined. | |
623 | */ | |
624 | CF_EXPORT | |
625 | void CFArrayReplaceValues(CFMutableArrayRef theArray, CFRange range, const void **newValues, CFIndex newCount); | |
626 | ||
627 | /*! | |
628 | @function CFArrayExchangeValuesAtIndices | |
629 | Exchanges the values at two indices of the array. | |
630 | @param theArray The array of which the values are to be swapped. If | |
631 | this parameter is not a valid mutable CFArray, the behavior | |
632 | is undefined. | |
633 | @param idx1 The first index whose values should be swapped. If the | |
634 | index is outside the index space of the array (0 to N-1 | |
635 | inclusive, where N is the count of the array before the | |
636 | operation), the behavior is undefined. | |
637 | @param idx2 The second index whose values should be swapped. If the | |
638 | index is outside the index space of the array (0 to N-1 | |
639 | inclusive, where N is the count of the array before the | |
640 | operation), the behavior is undefined. | |
641 | */ | |
642 | CF_EXPORT | |
643 | void CFArrayExchangeValuesAtIndices(CFMutableArrayRef theArray, CFIndex idx1, CFIndex idx2); | |
644 | ||
645 | /*! | |
646 | @function CFArraySortValues | |
647 | Sorts the values in the array using the given comparison function. | |
648 | @param theArray The array whose values are to be sorted. If this | |
649 | parameter is not a valid mutable CFArray, the behavior is | |
650 | undefined. | |
651 | @param range The range of values within the array to sort. If the | |
652 | range location or end point (defined by the location plus | |
653 | length minus 1) is outside the index space of the array (0 | |
654 | to N-1 inclusive, where N is the count of the array), the | |
655 | behavior is undefined. If the range length is negative, the | |
656 | behavior is undefined. The range may be empty (length 0). | |
657 | @param comparator The function with the comparator function type | |
658 | signature which is used in the sort operation to compare | |
659 | values in the array with the given value. If this parameter | |
660 | is not a pointer to a function of the correct prototype, the | |
661 | the behavior is undefined. If there are values in the array | |
662 | which the comparator function does not expect or cannot | |
663 | properly compare, the behavior is undefined. The values in | |
664 | the range are sorted from least to greatest according to | |
665 | this function. | |
666 | @param context A pointer-sized user-defined value, which is passed | |
667 | as the third parameter to the comparator function, but is | |
668 | otherwise unused by this function. If the context is not | |
669 | what is expected by the comparator function, the behavior is | |
670 | undefined. | |
671 | */ | |
672 | CF_EXPORT | |
673 | void CFArraySortValues(CFMutableArrayRef theArray, CFRange range, CFComparatorFunction comparator, void *context); | |
674 | ||
675 | /*! | |
676 | @function CFArrayAppendArray | |
677 | Adds the values from an array to another array. | |
678 | @param theArray The array to which values from the otherArray are to | |
679 | be added. If this parameter is not a valid mutable CFArray, | |
680 | the behavior is undefined. If the array is a fixed-capacity | |
681 | array and adding range.length values from the otherArray | |
682 | exceeds the capacity of the array, the behavior is | |
683 | undefined. | |
684 | @param otherArray The array providing the values to be added to the | |
685 | array. If this parameter is not a valid CFArray, the | |
686 | behavior is undefined. | |
687 | @param otherRange The range within the otherArray from which to add | |
688 | the values to the array. If the range location or end point | |
689 | (defined by the location plus length minus 1) is outside | |
690 | the index space of the otherArray (0 to N-1 inclusive, where | |
691 | N is the count of the otherArray), the behavior is | |
692 | undefined. The new values are retained by the array using | |
693 | the retain callback provided when the array was created. If | |
694 | the values are not of the sort expected by the retain | |
695 | callback, the behavior is undefined. The values are assigned | |
696 | to the indices one larger than the previous largest index | |
697 | in the array, and beyond, and the count of the array is | |
698 | increased by range.length. The values are assigned new | |
699 | indices in the array from smallest to largest index in the | |
700 | order in which they appear in the otherArray. | |
701 | */ | |
702 | CF_EXPORT | |
703 | void CFArrayAppendArray(CFMutableArrayRef theArray, CFArrayRef otherArray, CFRange otherRange); | |
704 | ||
705 | #if defined(__cplusplus) | |
706 | } | |
707 | #endif | |
708 | ||
709 | #endif /* ! __COREFOUNDATION_CFARRAY__ */ | |
710 |