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