#include <Composite.h>
Inheritance diagram for Composite< V >:

Public Types | |
| typedef Composite | Node |
| typedef Ref< Node > | NodeRef |
| typedef Ref< V > | VisitorRef |
| typedef std::vector< NodeRef > | ChildList |
| A list of child node references. | |
| typedef std::vector< Node * > | ParentList |
| A list of parent node pointers (which avoids circular references). | |
Public Methods | |
| virtual VisitorRef | accept (VisitorRef v)=0 |
| Accept a visitor. | |
| virtual bool | addChild (Node *node) |
| Add a child to this node. | |
| virtual bool | removeChild (Node *node) |
| Remove a child from this node. | |
| virtual bool | removeChild (unsigned int pos, unsigned int count=1) |
| Remove one or more children. | |
| unsigned int | getNumChildren () const |
| Get the number of immediate children of this node. | |
| virtual bool | setChild (unsigned int i, Node *node) |
| Replace an existing child node with a new one. | |
| Node * | getChild (unsigned int i) |
| Get a child by index number. | |
| const Node * | getChild (unsigned int i) const |
| Get a child by index number. | |
| ChildList const & | getChildren () const |
| Get a list of immediate children of this node. | |
| bool | containsNode (Node const *node) const |
| Test if this node contains a given node. | |
| unsigned int | getChildIndex (Node const *node) const |
| Get the index of a child node. | |
| const ParentList & | getParents () const |
| Get a list of immediate parents of this node. | |
| Node * | getParent (unsigned int i) |
| Get a parent by index number. | |
| const Node * | getParent (unsigned int i) const |
| Get a parent by index number. | |
| unsigned int | getNumParents () const |
| Get the number of immediate parents of this node. | |
| virtual bool | isContainer () const |
| virtual bool | canBeAdded () const |
| virtual Ref< V > | accept (Ref< V > v)=0 |
Protected Methods | |
| ParentList | getParents () |
| Get a copy of this node's parent list. | |
| void | descend (VisitorBase *visitor) |
| Propagate a visitor through all immediate children. | |
| void | ascend (VisitorBase *visitor) |
| Propagate a visitor through all immediate parents. | |
Composite should be used as a base class for nodes in a Composite/Visitor design pattern. First declare a context specific visitor class (see Visitor), then create use Composite<> as a base class for the primary node type. Starting from a context specific visitor (see Visitor for details) named MyNodeVisitor, one would declare MyNode as:
class MyNode: public Composite<MyNodeVisitor> { public: SIMDATA_VISITABLE(MyNodeVisitor); // the rest of MyNode's declaration... };
MyNode and each of its subclasses must define an accept() method, which is just a couple lines of boilerplate code handled by the SIMDATA_VISITABLE macro (feel free to write it out by hand if you despise macros). Defining accept() in each subclass allows the overloaded apply() method in MyNodeVisitor to be correctly selected based on the type of each node.
Notes:
Although Composite supports multiple parents, this capability can easily be disabled within a given context by overriding the addChild() method of the primary node class and testing that getNumOfParents() equals zero for each child to be added.
The current implementation does not support non- composite leaf nodes. Any node can contain other nodes, although again this feature can be disabled for specific node classes simply by overriding addChild().
| V | is a context specific visitor class. |
|
|||||
|
A list of child node references.
|
|
|||||
|
|
|
|||||
|
|
|
|||||
|
A list of parent node pointers (which avoids circular references).
|
|
|||||
|
|
|
||||||||||
|
|
|
||||||||||
|
Accept a visitor. This method must be implemented in each subclasses to ensure proper dispatch of the visitor's apply methods. See the Composite class documentation for details. |
|
||||||||||
|
Add a child to this node. Extend this method to inforce constraints on the graph structure, such as preventing nodes from having multiple parents.
|
|
||||||||||
|
Propagate a visitor through all immediate parents.
Implements CompositeBase< Visitable< V > >. |
|
|||||||||
|
|
|
||||||||||
|
Test if this node contains a given node.
|
|
||||||||||
|
Propagate a visitor through all immediate children.
Implements CompositeBase< Visitable< V > >. |
|
||||||||||
|
Get a child by index number.
|
|
||||||||||
|
Get a child by index number.
|
|
||||||||||
|
Get the index of a child node.
|
|
|||||||||
|
Get a list of immediate children of this node.
|
|
|||||||||
|
Get the number of immediate children of this node.
|
|
|||||||||
|
Get the number of immediate parents of this node.
|
|
||||||||||
|
Get a parent by index number.
|
|
||||||||||
|
Get a parent by index number.
|
|
|||||||||
|
Get a copy of this node's parent list.
|
|
|||||||||
|
Get a list of immediate parents of this node.
|
|
|||||||||
|
|
|
||||||||||||||||
|
Remove one or more children.
|
|
||||||||||
|
Remove a child from this node.
|
|
||||||||||||||||
|
Replace an existing child node with a new one. The original node will be destroyed if it is not already referenced elsewhere.
|
|
SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage. Generated on Tue Oct 14 12:06:40 2003, using Doxygen 1.2.18. |