Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Iterator

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
Last modified 8 years ago Last modified on Apr 12, 2017, 11:15:10 PM

Attachments (1)

Download all attachments as: .zip