]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSCollection.h
adb7cbf8bdedef4181a122d6fd7dcbbe2794b6b6
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* IOCollection.h created by gvdl on Thu 1998-10-22 */
30 #ifndef _OS_OSCOLLECTION_H
31 #define _OS_OSCOLLECTION_H
33 #include <libkern/c++/OSObject.h>
42 * This header declares the OSDictionary collection class.
50 * The abstract superclass for Libkern collections.
53 * OSCollection is the abstract superclass
54 * for all Libkern C++ object collections.
55 * It defines the necessary interfaces for managing storage space
56 * and iterating through an arbitrary collection
58 * @link //apple_ref/cpp/class/OSIterator OSIterator@/link
60 * @link //apple_ref/cpp/class/OSCollectionIterator OSCollectionIterator@/link
62 * It is up to concrete subclasses
63 * to define their specific content management functions.
65 * <b>Use Restrictions</b>
67 * With very few exceptions in the I/O Kit, all Libkern-based C++
68 * classes, functions, and macros are <b>unsafe</b>
69 * to use in a primary interrupt context.
70 * Consult the I/O Kit documentation related to primary interrupts
71 * for more information.
73 * OSCollection provides no concurrency protection;
74 * it's up to the usage context to provide any protection necessary.
75 * Some portions of the I/O Kit, such as
76 * @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link,
77 * handle synchronization via defined member functions for setting
80 class OSCollection
: public OSObject
82 friend class OSCollectionIterator
;
84 OSDeclareAbstractStructors(OSCollection
);
86 struct ExpansionData
{ };
89 /* Not to be included in headerdoc.
94 * A counter for changes to the collection object.
97 * The update stamp is used primarily to track validity
98 * of iteration contexts.
99 * See @link //apple_ref/cpp/class/OSIterator OSIterator@/link and
100 * @link //apple_ref/cpp/class/OSCollectionIterator OSCollectionIterator@/link
101 * for more information.
103 unsigned int updateStamp
;
105 #ifdef XNU_KERNEL_PRIVATE
109 #endif /* XNU_KERNEL_PRIVATE */
110 /* Reserved for future use. (Internal use only) */
111 // ExpansionData * reserved;
112 unsigned int fOptions
;
115 // Member functions used by the OSCollectionIterator class.
119 * @function iteratorSize
122 * Returns the size in bytes of a subclass's iteration context.
125 * The size in bytes of the iteration context
126 * needed by the subclass of OSCollection.
129 * This pure virtual member function, which subclasses must implement,
131 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
132 * object so that it can allocate the storage needed
133 * for the iteration context.
134 * An iteration context contains the data necessary
135 * to iterate through the collection.
137 virtual unsigned int iteratorSize() const = 0;
141 * @function initIterator
144 * Initializes the iteration context for a collection subclass.
146 * @param iterationContext The iteration context to initialize.
149 * <code>true</code> if initialization was successful,
150 * <code>false</code> otherwise.
153 * This pure virtual member function, which subclasses must implement,
155 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
156 * object to initialize an iteration context for a collection.
157 * The collection object should interpret <code>iterationContext</code> appropriately
158 * and initialize its contents to begin an iteration.
160 * This function can be called repeatedly for a given context,
161 * whenever the iterator is reset via the
162 * @link //apple_ref/cpp/instm/OSCollectionIterator/reset/virtualvoid/()
163 * OSCollectionIterator::reset@/link
166 virtual bool initIterator(void * iterationContext
) const = 0;
170 * @function getNextObjectForIterator
173 * Returns the next member of a collection.
175 * @param iterationContext The iteration context.
176 * @param nextObject The object returned by reference to the caller.
179 * <code>true</code> if an object was found, <code>false</code> otherwise.
182 * This pure virtual member function, which subclasses must implement,
184 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
185 * to get the next object for a given iteration context.
186 * The collection object should interpret
187 * <code>iterationContext</code> appropriately,
188 * advance the context from its current object
189 * to the next object (if it exists),
190 * return that object by reference in <code>nextObject</code>,
191 * and return <code>true</code> for the function call.
192 * If there is no next object, the collection object must return <code>false</code>.
194 * For associative collections, the object returned should be the key
195 * used to access its associated value, and not the value itself.
197 virtual bool getNextObjectForIterator(
198 void * iterationContext
,
199 OSObject
** nextObject
) const = 0;
206 * Initializes the OSCollection object.
209 * <code>true</code> on success, <code>false</code> otherwise.
212 * This function is used to initialize state
213 * within a newly created OSCollection object.
220 * @typedef _OSCollectionFlags
224 * Used with <code>@link setOptions setOptions@/link</code>
225 * to indicate the collection's contents should
226 * or should not change.
228 * An @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link
229 * object marks collections immutable when set
230 * as properties of a registry entry that's attached to a plane.
231 * This is generally an advisory flag, used for debugging;
232 * setting it does not mean a collection will in fact
233 * disallow modifications.
236 kImmutable
= 0x00000001,
238 kMASK
= (unsigned) -1
239 } _OSCollectionFlags
;
241 // xx-review: should be protected, not public
244 * @function haveUpdated
247 * Tracks updates to the collection.
250 * Subclasses call this function <i>before</i>
251 * making any change to their contents (not after, as the name implies).
252 * Update tracking is used for collection iterators,
253 * and to enforce certain protections in the IORegistry.
262 * Returns the number of objects in the collection.
265 * The number of objects in the collection.
268 * Subclasses must implement this pure virtual member function.
270 virtual unsigned int getCount() const = 0;
274 * @function getCapacity
277 * Returns the number of objects the collection
278 * can store without reallocating.
281 * The number objects the collection
282 * can store without reallocating.
285 * Subclasses must implement this pure virtual member function.
287 virtual unsigned int getCapacity() const = 0;
291 * @function getCapacityIncrement
294 * Returns the storage increment of the collection.
297 * The storage increment of the collection.
300 * Subclasses must implement this pure virtual member function.
301 * Most collection subclasses allocate their storage
302 * in multiples of the capacity increment.
306 * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint)
307 * ensureCapacity@/link</code>
308 * for how the capacity increment is used.
310 virtual unsigned int getCapacityIncrement() const = 0;
314 * @function setCapacityIncrement
317 * Sets the storage increment of the collection.
320 * The new storage increment of the collection,
321 * which may be different from the number requested.
324 * Subclasses must implement this pure virtual member function.
325 * Most collection subclasses allocate their storage
326 * in multiples of the capacity increment.
328 * Collection subclasses should gracefully handle
329 * an <code>increment</code> of zero
330 * by applying (and returning) a positive minimum capacity.
332 * Setting the capacity increment does not trigger an immediate adjustment
333 * of a collection's storage.
337 * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint)
338 * ensureCapacity@/link
339 * for how the capacity increment is used.
341 virtual unsigned int setCapacityIncrement(unsigned increment
) = 0;
345 * @function ensureCapacity
348 * Ensures the collection has enough space to store
349 * the requested number of objects.
351 * @param newCapacity The total number of objects the collection
352 * should be able to store.
355 * The new capacity of the collection,
356 * which may be different from the number requested
357 * (if smaller, reallocation of storage failed).
360 * Subclasses implement this pure virtual member function
361 * to adjust their storage so that they can hold
362 * at least <code>newCapacity</code> objects.
363 * Libkern collections generally allocate storage
364 * in multiples of their capacity increment.
366 * Subclass methods that add objects to the collection
367 * should call this function before adding any object,
368 * and should check the return value for success.
370 * Collection subclasses may reduce their storage
371 * when the number of contained objects falls below some threshold,
372 * but no Libkern collections currently do.
374 virtual unsigned int ensureCapacity(unsigned int newCapacity
) = 0;
378 * @function flushCollection
381 * Empties the collection, releasing any objects retained.
384 * Subclasses implement this pure virtual member function
385 * to remove their entire contents.
386 * This must not release the collection itself.
388 virtual void flushCollection() = 0;
392 * @function setOptions
395 * Recursively sets option bits in this collection
396 * and all child collections.
398 * @param options A bitfield whose values turn the options on (1) or off (0).
399 * @param mask A mask indicating which bits
400 * in <code>options</code> to change.
401 * Pass 0 to get the whole current options bitfield
402 * without changing any settings.
403 * @param context Unused.
406 * The options bitfield as it was before the set operation.
409 * Kernel extensions should not call this function.
411 * The only option currently in use is
412 * <code>@link //apple_ref/doc/title:econst/OSCollectionFlags/kImmutable
413 * kImmutable@/link</code>.
415 * Subclasses should override this function to recursively apply
416 * the options to their contents if the options actually change.
418 virtual unsigned setOptions(
422 OSMetaClassDeclareReservedUsed(OSCollection
, 0);
425 * @function copyCollection
428 * Creates a deep copy of a collection.
430 * @param cycleDict A dictionary of all of the collections
431 * that have been copied so far,
432 * to start the copy at the top level
433 * pass <code>NULL</code> for <code>cycleDict</code>.
436 * The newly copied collecton,
437 * <code>NULL</code> on failure.
440 * This function copies the collection
441 * and all of the contained collections recursively.
442 * Objects that are not derived from OSCollection are retained
443 * rather than copied.
445 * Subclasses of OSCollection must override this function
446 * to properly support deep copies.
448 virtual OSCollection
*copyCollection(OSDictionary
* cycleDict
= 0);
449 OSMetaClassDeclareReservedUsed(OSCollection
, 1);
452 OSMetaClassDeclareReservedUnused(OSCollection
, 2);
453 OSMetaClassDeclareReservedUnused(OSCollection
, 3);
454 OSMetaClassDeclareReservedUnused(OSCollection
, 4);
455 OSMetaClassDeclareReservedUnused(OSCollection
, 5);
456 OSMetaClassDeclareReservedUnused(OSCollection
, 6);
457 OSMetaClassDeclareReservedUnused(OSCollection
, 7);
460 #endif /* !_OS_OSCOLLECTION_H */