navi homePPSaboutscreenshotsdownloaddevelopmentforum

HowTo: ObjectLists and Iterators


Every instance of a class which is in the class hierarchy is stored in a list. Additionally it's stored in the lists of all classes it is derived. So in the list of "BaseClass" you'll find instances of "BaseClass" and "DerivedClass" (if DerivedClass is derived from BaseClass as the names suggest).

Of course it's possible to iterate through all instances of a class. This is achieved by using iterators. There are two types: doc/ObjectListIterator and doc/Iterator. This page explains the difference and how to use them.


An ObjectListIterator is used if you know at compiletime through which class you want to iterate.

for (ObjectList<MyClass>::iterator it = ObjectList<MyClass>::begin();
                                 it != ObjectList<MyClass>::end(); ++it)
    MyClass* storeTheObject = (*it);

See doc/ObjectListIterator for detailed information.


An Iterator is used if the class through which you want do iterate is determined at runtime. This is slower than ObjectListIterator.

Identifier* identifier = someFunctionReturningAnIdentifier();

for (Iterator<BaseObject> it = identifier->getObjects()->begin();
                          it != identifier->getObjects()->end(); ++it)
    BaseObject* storeTheObject = (*it);

See doc/Iterator for detailed information.

Last modified 3 years ago Last modified on Apr 12, 2017, 11:47:30 PM