#include <OTC/collctn/worker.hh> template<class T> class OTC_Worker {
public:
inline OTC_Worker();
virtual void start() = 0;
virtual void finish() = 0;
virtual OTC_Progress action(T& theItem) = 0;
};
OTC_Worker
class provides an alternative to using the
OTC_Modifier
class to act on items in a collection. Support for
the OTC_Worker
class can also be provided on collection type
objects which do not support an iterator.
To use this concept, a derived version of this class must be
created. The derived class must redefine the action()
function
to perform whatever is to be done for each item in the collection.
An instance of the derived class is then applied to the
collection. The collection will do the work of calling the
action()
function on each item in the collection. If necessary,
the action()
function, through is return value, can prematurely
stop or restart the process.
Through the OTC_Worker
class, it is possible to modify the
item to which the action()
function is being applied.
virtual void start() = 0;
action()
function is applied to any
items in the collection. This function
must be defined in a derived class,
even if the implementation will be
empty.
virtual void finish() = 0;
action()
function has
been applied to all items in a collection,
or if the return value of the action()
function requested that traversal of items
in the collection be stopped. This
function must be defined in a derived
class, even if the implementation will be
empty.
virtual OTC_Progress action(T& theItem) = 0;
theItem
. The function must
return either OTCLIB_RESTART
,
OTCLIB_CONTINUE
or OTCLIB_FINISH
. The
value OTCLIB_RESTART
should be
returned if it is desired to start back at
the beginning and go through each item
again. The value OTCLIB_FINISH
should be
returned if it is desired to prematurely
stop going through the items. The value
OTCLIB_CONTINUE
should be returned if it
is desired to move to the next item.
start()
and finish()
functions are defined as being
pure virtual functions and must be defined in a derived class.
This requirement is again to avoid a separate template expansion
of this class being required.
OTC_Visitor