OSCollectionIterator
Declaration
class OSCollectionIterator : OSIteratorOverview
OSCollectionIterator defines a consistent mechanism to iterate through the objects of an OSCollection. It expands on the basic interface of OSIterator to allow association of an iterator with a specific collection.
To use an OSCollectionIterator, you create it with the collection to be iterated, then call OSIterator as long as it returns an object:
<pre> OSCollectionIterator * iterator = OSCollectionIterator::withCollection(myCollection); OSObject * object; while (object = iterator->getNextObject()) { // do something with object } // optional if (!iterator->isValid()) { // report that collection changed during iteration } iterator->release(); </pre>
Note that when iterating associative collections, the objects returned by getNextObject are keys; if you want to work with the associated values, simply look them up in the collection with the keys.
Use Restrictions
With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information.
OSCollectionIterator provides no concurrency protection.