]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSCollection.h
ea0acb64845a3e880ef1146a1bc6b85133cecccf
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
;
106 /* Reserved for future use. (Internal use only) */
107 // ExpansionData * reserved;
108 unsigned int fOptions
;
111 // Member functions used by the OSCollectionIterator class.
115 * @function iteratorSize
118 * Returns the size in bytes of a subclass's iteration context.
121 * The size in bytes of the iteration context
122 * needed by the subclass of OSCollection.
125 * This pure virtual member function, which subclasses must implement,
127 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
128 * object so that it can allocate the storage needed
129 * for the iteration context.
130 * An iteration context contains the data necessary
131 * to iterate through the collection.
133 virtual unsigned int iteratorSize() const = 0;
137 * @function initIterator
140 * Initializes the iteration context for a collection subclass.
142 * @param iterationContext The iteration context to initialize.
145 * <code>true</code> if initialization was successful,
146 * <code>false</code> otherwise.
149 * This pure virtual member function, which subclasses must implement,
151 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
152 * object to initialize an iteration context for a collection.
153 * The collection object should interpret <code>iterationContext</code> appropriately
154 * and initialize its contents to begin an iteration.
156 * This function can be called repeatedly for a given context,
157 * whenever the iterator is reset via the
158 * @link //apple_ref/cpp/instm/OSCollectionIterator/reset/virtualvoid/()
159 * OSCollectionIterator::reset@/link
162 virtual bool initIterator(void * iterationContext
) const = 0;
166 * @function getNextObjectForIterator
169 * Returns the next member of a collection.
171 * @param iterationContext The iteration context.
172 * @param nextObject The object returned by reference to the caller.
175 * <code>true</code> if an object was found, <code>false</code> otherwise.
178 * This pure virtual member function, which subclasses must implement,
180 * @link //apple_ref/doc/class/OSCollectionIterator OSCollectionIterator@/link
181 * to get the next object for a given iteration context.
182 * The collection object should interpret
183 * <code>iterationContext</code> appropriately,
184 * advance the context from its current object
185 * to the next object (if it exists),
186 * return that object by reference in <code>nextObject</code>,
187 * and return <code>true</code> for the function call.
188 * If there is no next object, the collection object must return <code>false</code>.
190 * For associative collections, the object returned should be the key
191 * used to access its associated value, and not the value itself.
193 virtual bool getNextObjectForIterator(
194 void * iterationContext
,
195 OSObject
** nextObject
) const = 0;
202 * Initializes the OSCollection object.
205 * <code>true</code> on success, <code>false</code> otherwise.
208 * This function is used to initialize state
209 * within a newly created OSCollection object.
216 * @typedef _OSCollectionFlags
220 * Used with <code>@link setOptions setOptions@/link</code>
221 * to indicate the collection's contents should
222 * or should not change.
224 * An @link //apple_ref/doc/class/IORegistryEntry IORegistryEntry@/link
225 * object marks collections immutable when set
226 * as properties of a registry entry that's attached to a plane.
227 * This is generally an advisory flag, used for debugging;
228 * setting it does not mean a collection will in fact
229 * disallow modifications.
232 kImmutable
= 0x00000001,
233 kMASK
= (unsigned) -1
234 } _OSCollectionFlags
;
236 // xx-review: should be protected, not public
239 * @function haveUpdated
242 * Tracks updates to the collection.
245 * Subclasses call this function <i>before</i>
246 * making any change to their contents (not after, as the name implies).
247 * Update tracking is used for collection iterators,
248 * and to enforce certain protections in the IORegistry.
257 * Returns the number of objects in the collection.
260 * The number of objects in the collection.
263 * Subclasses must implement this pure virtual member function.
265 virtual unsigned int getCount() const = 0;
269 * @function getCapacity
272 * Returns the number of objects the collection
273 * can store without reallocating.
276 * The number objects the collection
277 * can store without reallocating.
280 * Subclasses must implement this pure virtual member function.
282 virtual unsigned int getCapacity() const = 0;
286 * @function getCapacityIncrement
289 * Returns the storage increment of the collection.
292 * The storage increment of the collection.
295 * Subclasses must implement this pure virtual member function.
296 * Most collection subclasses allocate their storage
297 * in multiples of the capacity increment.
301 * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint)
302 * ensureCapacity@/link</code>
303 * for how the capacity increment is used.
305 virtual unsigned int getCapacityIncrement() const = 0;
309 * @function setCapacityIncrement
312 * Sets the storage increment of the collection.
315 * The new storage increment of the collection,
316 * which may be different from the number requested.
319 * Subclasses must implement this pure virtual member function.
320 * Most collection subclasses allocate their storage
321 * in multiples of the capacity increment.
323 * Collection subclasses should gracefully handle
324 * an <code>increment</code> of zero
325 * by applying (and returning) a positive minimum capacity.
327 * Setting the capacity increment does not trigger an immediate adjustment
328 * of a collection's storage.
332 * //apple_ref/cpp/instm/OSCollection/ensureCapacity/virtualunsignedint/(unsignedint)
333 * ensureCapacity@/link
334 * for how the capacity increment is used.
336 virtual unsigned int setCapacityIncrement(unsigned increment
) = 0;
340 * @function ensureCapacity
343 * Ensures the collection has enough space to store
344 * the requested number of objects.
346 * @param newCapacity The total number of objects the collection
347 * should be able to store.
350 * The new capacity of the collection,
351 * which may be different from the number requested
352 * (if smaller, reallocation of storage failed).
355 * Subclasses implement this pure virtual member function
356 * to adjust their storage so that they can hold
357 * at least <code>newCapacity</code> objects.
358 * Libkern collections generally allocate storage
359 * in multiples of their capacity increment.
361 * Subclass methods that add objects to the collection
362 * should call this function before adding any object,
363 * and should check the return value for success.
365 * Collection subclasses may reduce their storage
366 * when the number of contained objects falls below some threshold,
367 * but no Libkern collections currently do.
369 virtual unsigned int ensureCapacity(unsigned int newCapacity
) = 0;
373 * @function flushCollection
376 * Empties the collection, releasing any objects retained.
379 * Subclasses implement this pure virtual member function
380 * to remove their entire contents.
381 * This must not release the collection itself.
383 virtual void flushCollection() = 0;
387 * @function setOptions
390 * Recursively sets option bits in this collection
391 * and all child collections.
393 * @param options A bitfield whose values turn the options on (1) or off (0).
394 * @param mask A mask indicating which bits
395 * in <code>options</code> to change.
396 * Pass 0 to get the whole current options bitfield
397 * without changing any settings.
398 * @param context Unused.
401 * The options bitfield as it was before the set operation.
404 * Kernel extensions should not call this function.
406 * The only option currently in use is
407 * <code>@link //apple_ref/doc/title:econst/OSCollectionFlags/kImmutable
408 * kImmutable@/link</code>.
410 * Subclasses should override this function to recursively apply
411 * the options to their contents if the options actually change.
413 virtual unsigned setOptions(
417 OSMetaClassDeclareReservedUsed(OSCollection
, 0);
420 * @function copyCollection
423 * Creates a deep copy of a collection.
425 * @param cycleDict A dictionary of all of the collections
426 * that have been copied so far,
427 * to start the copy at the top level
428 * pass <code>NULL</code> for <code>cycleDict</code>.
431 * The newly copied collecton,
432 * <code>NULL</code> on failure.
435 * This function copies the collection
436 * and all of the contained collections recursively.
437 * Objects that are not derived from OSCollection are retained
438 * rather than copied.
440 * Subclasses of OSCollection must override this function
441 * to properly support deep copies.
443 virtual OSCollection
*copyCollection(OSDictionary
* cycleDict
= 0);
444 OSMetaClassDeclareReservedUsed(OSCollection
, 1);
447 OSMetaClassDeclareReservedUnused(OSCollection
, 2);
448 OSMetaClassDeclareReservedUnused(OSCollection
, 3);
449 OSMetaClassDeclareReservedUnused(OSCollection
, 4);
450 OSMetaClassDeclareReservedUnused(OSCollection
, 5);
451 OSMetaClassDeclareReservedUnused(OSCollection
, 6);
452 OSMetaClassDeclareReservedUnused(OSCollection
, 7);
455 #endif /* !_OS_OSCOLLECTION_H */