]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/c++/OSCollectionIterator.h
72e8e97929dfe2186085e2e809ce5f5ecea95493
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 /* IOCollectionIterator.h created by gvdl on Fri 1998-10-30 */
30 #ifndef _OS_OSCOLLECTIONITERATOR_H
31 #define _OS_OSCOLLECTIONITERATOR_H
33 #include <libkern/c++/OSIterator.h>
41 * This header declares the OSCollectionIterator collection class.
46 * @class OSCollectionIterator
49 * OSCollectionIterator defines a consistent mechanism to iterate
50 * through the objects of an OSCollection.
51 * It expands on the basic interface of
52 * @link //apple_ref/cpp/class/OSIterator OSIterator@/link
53 * to allow association of an iterator with a specific collection.
55 * To use an OSCollectionIterator, you create it with the collection
56 * to be iterated, then call
57 * @link //apple_ref/cpp/class/OSIterator OSIterator@/link
58 * as long as it returns an object:
62 * OSCollectionIterator * iterator =
63 * OSCollectionIterator::withCollection(myCollection);
65 * while (object = iterator->getNextObject()) {
66 * // do something with object
69 * if (!iterator->isValid()) {
70 * // report that collection changed during iteration
72 * iterator->release();
76 * Note that when iterating associative collections,
77 * the objects returned by <code>getNextObject</code> are keys;
78 * if you want to work with the associated values,
79 * simply look them up in the collection with the keys.
81 * <b>Use Restrictions</b>
83 * With very few exceptions in the I/O Kit, all Libkern-based C++
84 * classes, functions, and macros are <b>unsafe</b>
85 * to use in a primary interrupt context.
86 * Consult the I/O Kit documentation related to primary interrupts
87 * for more information.
89 * OSCollectionIterator provides no concurrency protection.
91 class OSCollectionIterator
: public OSIterator
93 OSDeclareDefaultStructors(OSCollectionIterator
)
96 // xx-review: Do we want to document these?
97 const OSCollection
* collection
;
99 unsigned int initialUpdateStamp
;
104 * @function withCollection
107 * Creates and initializes an OSCollectionIterator
108 * for the provided collection object.
110 * @param inColl The OSCollection-derived collection object to be iteratated.
113 * A new instance of OSCollectionIterator, or <code>NULL</code> on failure.
115 static OSCollectionIterator
* withCollection(const OSCollection
* inColl
);
119 * @function initWithCollection
122 * Initializes an OSCollectionIterator
123 * for the provided collection object.
125 * @param inColl The OSCollection-derived collection object to be iteratated.
127 * <code>true</code> if the initialization was successful,
128 * or <code>false</code> on failure.
131 * Not for general use. Use the static instance creation method
132 * <code>@link withCollection withCollection@/link</code> instead.
134 virtual bool initWithCollection(const OSCollection
* inColl
);
141 * Releases or deallocates any resources used
142 * by the OSCollectionIterator object.
145 * This function should not be called directly;
148 * //apple_ref/cpp/instm/OSObject/release/virtualvoid/()
149 * release@/link</code>
159 * Resets the iterator to the beginning of the collection,
160 * as if it had just been created.
162 virtual void reset();
169 * Checks that the collection hasn't been modified during iteration.
172 * <code>true</code> if the iterator is valid for continued use,
173 * <code>false</code> otherwise
174 * (typically because the iteration context has been modified).
176 virtual bool isValid();
180 * @function getNextObject
183 * Advances to and returns the next object in the iteration.
186 * The next object in the iteration context,
187 * <code>NULL</code> if there is no next object
188 * or if the iterator is no longer valid.
191 * This function first calls
192 * <code>@link //apple_ref/cpp/instm/OSCollectionIterator/isValid/virtualbool/()
193 * isValid@/link</code>
194 * and returns <code>NULL</code> if that function
195 * returns <code>false</code>.
197 * Subclasses must implement this pure virtual function
198 * to check for validity with
200 * //apple_ref/cpp/instm/OSCollectionIterator/isValid/virtualbool/()
201 * isValid@/link</code>,
202 * and then to advance the iteration context to the next object (if any)
203 * and return that next object, or <code>NULL</code> if there is none.
205 virtual OSObject
* getNextObject();
208 #endif /* !_OS_OSCOLLECTIONITERATOR_H */