OMNeT++ Simulation Library  6.0.3
cVisitor Class Referenceabstract

#include <cvisitor.h>

Description

Enables traversing the tree of (cObject-rooted) simulation objects.

Subclasses should redefine the visit() method and add the desired functionality.

An example: the cRecursiveObjectFinderVisitor class (internal) has been created to find an object of the given name. The constructor accepts the name of the object to search for, and visit() has been redefined to perform recursive traversal, and to throw EndTraversalException if it finds the given object. The class can be used like this:

cRecursiveObjectFinderVisitor v(objectName);
v.process(root);
cObject *result = v.getResult();

The above code will find the root object as well, if its name matches. The second version (below) starts the traversal at the children, so the root object is ignored.

cRecursiveObjectFinderVisitor v(objectName);
v.processChildrenOf(root);
cObject *result = v.getResult();

Public Member Functions

virtual ~cVisitor ()
 
virtual void process (cObject *obj)
 
virtual void processChildrenOf (cObject *obj)
 
virtual bool visit (cObject *obj)=0
 

Constructor & Destructor Documentation

◆ ~cVisitor()

virtual ~cVisitor ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ process()

virtual void process ( cObject obj)
virtual

Starts the visiting process. This version simply calls visit(obj).

◆ processChildrenOf()

virtual void processChildrenOf ( cObject obj)
virtual

Similar to process(), except that it skips the object itself, i.e. it begins with processing the children. Calls obj->forEachChild(this).

◆ visit()

virtual bool visit ( cObject obj)
pure virtual

Method called from the forEachChild() methods of every class derived from cObject, for each contained object. visit() should be redefined by user to encapsulate the operation to be performed on the object. If you want recursively traversal, call obj->forEachChild(this) from here. A return value of false indicates to the caller i.e. the forEachChild() method that the rest of the children may be skipped.

This method should NOT be called to to initiate the traversal – use process() or processChildrenOf() for that.


The documentation for this class was generated from the following file: