2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 Copyright (c) 1999-2007, Apple Inc. All rights reserved.
28 CFStorage stores an array of arbitrary-sized values. There are no callbacks;
29 all that is provided about the values is the size, and the appropriate number
30 of bytes are copied in and out of the CFStorage.
32 CFStorage uses a balanced tree to store the values, and is most appropriate
33 for situations where potentially a large number values (more than a hundred
34 bytes' worth) will be stored and there will be a lot of editing (insertions and deletions).
36 Getting to an item is O(log n), although caching the last result often reduces this
39 The overhead of CFStorage is 48 bytes. There is no per item overhead; the
40 non-leaf nodes in the tree cost 20 bytes each, and the worst case extra
41 capacity (unused space in the leaves) is 12%, typically much less.
43 Because CFStorage does not necessarily use a single block of memory to store the values,
44 when you ask for a value, you get back the pointer to the value and optionally
45 the range of other values that are consecutive and thus reachable as if the
46 storage was a single block.
49 #if !defined(__COREFOUNDATION_CFSTORAGE__)
50 #define __COREFOUNDATION_CFSTORAGE__ 1
52 #include <CoreFoundation/CFBase.h>
58 This is the type of a reference to a CFStorage instance.
60 typedef struct __CFStorage
*CFStorageRef
;
63 @typedef CFStorageApplierFunction
64 Type of the callback function used by the apply functions of
66 @param value The current value from the storage.
67 @param context The user-defined context parameter given to the apply
70 typedef void (*CFStorageApplierFunction
)(const void *val
, void *context
);
73 @function CFStorageGetTypeID
74 Returns the type identifier of all CFStorage instances.
76 CF_EXPORT CFTypeID
CFStorageGetTypeID(void);
79 @function CFStorageCreate
80 Creates a new mutable storage with elements of the given size.
81 @param alloc The CFAllocator which should be used to allocate
82 memory for the set and its storage for values. This
83 parameter may be NULL in which case the current default
84 CFAllocator is used. If this reference is not a valid
85 CFAllocator, the behavior is undefined.
86 @param valueSizeInBytes The size in bytes of each of the elements
87 to be stored in the storage. If this value is zero or
88 negative, the result is undefined.
89 @result A reference to the new CFStorage instance.
91 CF_EXPORT CFStorageRef
CFStorageCreate(CFAllocatorRef alloc
, CFIndex valueSizeInBytes
);
94 @function CFStorageInsertValues
95 Allocates space for range.length values at location range.location. Use
96 CFStorageReplaceValues() to set those values.
97 @param storage The storage to which the values are to be inserted.
98 If this parameter is not a valid CFStorage, the behavior is undefined.
99 @param range The range of values within the storage to delete. If the
100 range location or end point (defined by the location plus
101 length minus 1) are outside the index space of the storage (0
102 to N inclusive, where N is the count of the storage), the
103 behavior is undefined. If the range length is negative, the
104 behavior is undefined. The range may be empty (length 0),
105 in which case the no values are inserted.
107 CF_EXPORT
void CFStorageInsertValues(CFStorageRef storage
, CFRange range
);
110 @function CFStorageDeleteValues
111 Deletes the values of the storage in the specified range.
112 @param storage The storage from which the values are to be deleted.
113 If this parameter is not a valid CFStorage, the behavior is undefined.
114 @param range The range of values within the storage to delete. If the
115 range location or end point (defined by the location plus
116 length minus 1) are outside the index space of the storage (0
117 to N inclusive, where N is the count of the storage), the
118 behavior is undefined. If the range length is negative, the
119 behavior is undefined. The range may be empty (length 0),
120 in which case the no values are deleted.
122 CF_EXPORT
void CFStorageDeleteValues(CFStorageRef storage
, CFRange range
);
125 @function CFStorageGetCount
126 Returns the number of values currently in the storage.
127 @param storage The storage to be queried. If this parameter is not a valid
128 CFStorage, the behavior is undefined.
129 @result The number of values in the storage.
131 CF_EXPORT CFIndex
CFStorageGetCount(CFStorageRef storage
);
134 @function CFStorageGetValueAtIndex
135 Returns a pointer to the specified value. The pointer is mutable and may be used to
136 get or set the value.
137 @param storage The storage to be queried. If this parameter is not a
138 valid CFStorage, the behavior is undefined.
139 @param idx The index of the value to retrieve. If the index is
140 outside the index space of the storage (0 to N-1 inclusive,
141 where N is the count of the storage), the behavior is
143 @param validConsecutiveValueRange This parameter is a C pointer to a CFRange.
144 If NULL is specified, this argument is ignored; otherwise, the range
145 is set to the range of values that may be accessed via an offset from the result pointer.
146 The range location is set to the index of the lowest consecutive
147 value and the range length is set to the count of consecutive values.
148 @result The value with the given index in the storage.
150 CF_EXPORT
void *CFStorageGetValueAtIndex(CFStorageRef storage
, CFIndex idx
, CFRange
*validConsecutiveValueRange
);
153 @function CFStorageGetValues
154 Fills the buffer with values from the storage.
155 @param storage The storage to be queried. If this parameter is not a
156 valid CFStorage, the behavior is undefined.
157 @param range The range of values within the storage to retrieve. If
158 the range location or end point (defined by the location
159 plus length minus 1) are outside the index space of the
160 storage (0 to N-1 inclusive, where N is the count of the
161 storage), the behavior is undefined. If the range length is
162 negative, the behavior is undefined. The range may be empty
163 (length 0), in which case no values are put into the buffer.
164 @param values A C array of to be filled with values from the storage.
165 The values in the C array are ordered
166 in the same order in which they appear in the storage. If this
167 parameter is not a valid pointer to a C array of at least
168 range.length pointers, the behavior is undefined.
170 CF_EXPORT
void CFStorageGetValues(CFStorageRef storage
, CFRange range
, void *values
);
173 @function CFStorageApplyFunction
174 Calls a function once for each value in the set.
175 @param storage The storage to be operated upon. If this parameter is not
176 a valid CFStorage, the behavior is undefined.
177 @param range The range of values within the storage to operate on. If the
178 range location or end point (defined by the location plus
179 length minus 1) are outside the index space of the storage (0
180 to N inclusive, where N is the count of the storage), the
181 behavior is undefined. If the range length is negative, the
182 behavior is undefined. The range may be empty (length 0),
183 in which case the no values are operated on.
184 @param applier The callback function to call once for each value in
185 the given storage. If this parameter is not a
186 pointer to a function of the correct prototype, the behavior
187 is undefined. If there are values in the storage which the
188 applier function does not expect or cannot properly apply
189 to, the behavior is undefined.
190 @param context A pointer-sized user-defined value, which is passed
191 as the second parameter to the applier function, but is
192 otherwise unused by this function. If the context is not
193 what is expected by the applier function, the behavior is
196 CF_EXPORT
void CFStorageApplyFunction(CFStorageRef storage
, CFRange range
, CFStorageApplierFunction applier
, void *context
);
199 @function CFStorageReplaceValues
200 Replaces a range of values in the storage.
201 @param storage The storage from which the specified values are to be
202 removed. If this parameter is not a valid CFStorage,
203 the behavior is undefined.
204 @param range The range of values within the storage to replace. If the
205 range location or end point (defined by the location plus
206 length minus 1) are outside the index space of the storage (0
207 to N inclusive, where N is the count of the storage), the
208 behavior is undefined. If the range length is negative, the
209 behavior is undefined. The range may be empty (length 0),
210 in which case the new values are merely inserted at the
212 @param values A C array of the values to be copied into the storage.
213 The new values in the storage are ordered in the same order
214 in which they appear in this C array. This parameter may be NULL
215 if the range length is 0. This C array is not changed or freed by
216 this function. If this parameter is not a valid pointer to a C array of at least
217 range length pointers, the behavior is undefined.
219 CF_EXPORT
void CFStorageReplaceValues(CFStorageRef storage
, CFRange range
, const void *values
);
223 CF_EXPORT CFIndex
__CFStorageGetCapacity(CFStorageRef storage
);
224 CF_EXPORT CFIndex
__CFStorageGetValueSize(CFStorageRef storage
);
229 #endif /* ! __COREFOUNDATION_CFSTORAGE__ */