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