AlIterator
 
 
 

Pure virtual base classes used to derive iterators for doing tasks on elements of a list.

Synopsis

#include <AlIterator.h>
class AlIterator
virtual int	func( AlObject* ) = 0;
class AlIteratorWithParent
virtual int	func( AlObject* , AlDagNode* ) = 0;

Description

Many classes return the first element of a list, which is then traversed with some operation done on each element of the list. This class encapsulates this functionality making it very easy to write code that does operations on members of a list.

To use this class the method "func" should be overloaded. On success, func() should return zero which will cause the iteration to continue with the next element in the list. A non-zero return value will cause the iteration to stop. The returned value will be returned through the second reference argument in the applyIterator() method. In general the applyIterator() methods return sSuccess even when func() returns non-zero. A return other than sSuccess indicates that the applyIterator() method failed to function properly.

Two types of iterators are defined. The first passes in an AlObject* to the func(). The second iterator AlIteratorWithParent passes in the AlObject* and the AlDagNode* parent of the object. Note that if an AlIteratorWithParent is used and the AlObject is a shader then the AlDagNode pointer will be null.

Iterators should be used to examine or set data in the visited objects, but should not be used to delete the objects.

For example: class countIterator : public AlIterator { public: countIterator() : count( 0 ); ~countIterator() {}; virtual int func( AlObject* ) { count++; }; int result() { return count; }; private: int count; };