Version 5 (modified by landauf, 16 years ago) (diff) |
---|
Iterator
TracNav(TracNav/TOC_Development)?
The Iterator allows you to iteratate through any ObjectList you like. It's possible to iterate through all objects of class B with an Iterator of class A, under condition that B is a child of A. Iterator does a dynamic_cast to the requested class. Because this is not really performant, you should always use ObjectListIterator instead in case that A == B.
Important: Always use ObjectListIterator if you know at compiletime through which class you want to iterate.
Iterator is made to iterate through a list of objects which gets determined at runtime. For this reason you can create an Iterator not only by calling ObjectList<T>::begin() but also through anyidentifier→getObjects()→begin(). Of course end(), rbegin() and rend() work too.
Illustration
Example
Identifier* identifier = someFunctionReturningAnIdentifier(); for (Iterator<BaseObject> it = identifier->getObjects()->begin(); it != identifier->getObjects()->end(); ++it) { it->callSomeFunction(...); BaseObject* storeTheObject = (*it); }
for (Iterator<BaseClass> it = ObjectList<ChildClass>::begin(); it != ObjectList<ChildClass>::end(); ++it) { it->callSomeFunction(...); BaseObject* storeTheObject = (*it); } // Note: // In this case you should better use ObjectListIterator<ChildClass> // to avoid a dynamic_cast
Attachments (1)
- Iterator.png (8.8 KB) - added by landauf 16 years ago.
Download all attachments as: .zip