MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Friends | List of all members
Mezzanine::XML::TreeWalker Class Referenceabstract

Used to call a function OnEachNode member of the subtree of nodes descended from a specific node. More...

#include <treewalker.h>

Public Member Functions

 TreeWalker ()
 Default constructor, initializes depth, and can do little else without a fully implemented treewalker.
 
virtual ~TreeWalker ()
 Virtual deconstructor. Tears down a TreeWalker.
 
virtual bool OnEachNode (Node &node)=0
 A Pure Virtual function that is expected to be implemented to create the desired behavior. More...
 
virtual bool OnTraversalBegin (Node &node)
 Called by the root Node of the xml subtree when traversal begins. More...
 
virtual bool OnTraversalEnd (Node &node)
 Called on the root Node of the xml subtree when traversal ends. More...
 

Protected Member Functions

int Depth () const
 How many descendants deep are we during traversal. More...
 

Friends

class Node
 

Detailed Description

Used to call a function OnEachNode member of the subtree of nodes descended from a specific node.

If you want to do a deep tree traversal, you'll either have to do it via a recursive function or some equivalent method or use a TreeWalker. This provides a helper for depth-first traversal of a subtree. In order to use it, you have to implement XML::TreeWalker interface and call XML::Node::Traverse() function.

Definition at line 83 of file treewalker.h.

Member Function Documentation

int Mezzanine::XML::TreeWalker::Depth ( ) const
protected

How many descendants deep are we during traversal.

Returns
This returns -1 if called from TreeWalker::OnTraversalBegin() or TreeWalker::OnTraversalEnd(), and returns 0-based depth if called from OnEachNode - depth is 0 for all children of the traversal root, 1 for all grandchildren, 2 for great-grandchildren and so on.
virtual bool Mezzanine::XML::TreeWalker::OnEachNode ( Node node)
pure virtual

A Pure Virtual function that is expected to be implemented to create the desired behavior.

Parameters
nodeThe curren node being trraversed.

This is called on every Node that is traversed except the root node of the traversed subtree. Can be used to perform sophisticated searches of a portion of the xml document, alter the document on a large scale, gather statistics, or just about any other behavior that requires touching many nodes.

Returns
if true Traversal is expected to continue, if false, then traversal ends and the Node::Traverse() that was called is expected to return false.
virtual bool Mezzanine::XML::TreeWalker::OnTraversalBegin ( Node node)
virtual

Called by the root Node of the xml subtree when traversal begins.

Parameters
nodeThe first node the Tree to traverse

By default this simply returns true, but is expected to be overridden with any desired behavior

Returns
True by default. If it returns false, then traversal ends and the Node::Traverse() that was called is expected to return false.
virtual bool Mezzanine::XML::TreeWalker::OnTraversalEnd ( Node node)
virtual

Called on the root Node of the xml subtree when traversal ends.

Parameters
nodeThe last node the Tree to traverse

By default this simply returns true, but is expected to be overridden with any desired behavior

Returns
True by default. If it returns false, then traversal ends and the Node::Traverse() that was called is expected to return false.

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