SundanceRivaraTreeNode.hpp
Go to the documentation of this file.
00001 #ifndef SUNDANCERIVARATREENODE_H
00002 #define SUNDANCERIVARATREENODE_H
00003 
00004 #include "SundanceDefs.hpp"
00005 
00006 namespace Sundance
00007 {
00008   namespace Rivara
00009     {
00010       /**
00011        * Class TreeNode represents a node in a Rivara mesh refinement tree.
00012        * Each node has either zero or two children depending on whether
00013        * it has been refined. All non-root nodes have a pointer back to their
00014        * parent.
00015        *
00016        * Only maximal elements will be responsible for deleting their children.
00017        * Therefore, the TreeNode dtor does not delete children; subtypes
00018        * that need to delete children should call the deleteChildren()
00019        * method.
00020        */
00021       class TreeNode 
00022         {
00023         public:
00024           /** Empty ctor */
00025           TreeNode();
00026 
00027           virtual ~TreeNode(){;}
00028 
00029           /** Delete the node's children */
00030           void deleteChildren();
00031 
00032 
00033           /** set the parent of this node */
00034           void setParent(TreeNode* parent) {parent_ = parent;}
00035 
00036           /** Set the two children of this node */
00037           void setChildren(TreeNode* left, TreeNode* right)
00038             {left_ = left; right_ = right;}
00039 
00040           /** return the leftmost leaf beneath this node */
00041           const TreeNode* first() const ;
00042 
00043           /** return the rightmost leaf beneath this node */
00044           const TreeNode* last() const ;
00045 
00046           /** Indicate whether this is the leftward child of another node */
00047           bool isLeftChild() const ;
00048 
00049           /** Indicate whether this is the rightward child of another node */
00050           bool isRightChild() const ;
00051 
00052           /** Return the next leaf in a left-to-right walk of the tree. If this
00053            * is the last leaf, return 0. */
00054           const TreeNode* next() const ;
00055 
00056           /** Indicate whether this node has children */
00057           bool hasChildren() const {return left_ != 0;}
00058 
00059           /** Return a count of the number of leaves */
00060           int numLeaves() const ;
00061 
00062 
00063         protected:
00064           TreeNode* left() {return left_;}
00065 
00066           TreeNode* right() {return right_;}
00067         private:
00068 
00069           TreeNode* parent_;
00070 
00071           TreeNode* left_;
00072 
00073           TreeNode* right_;
00074         };
00075     }
00076 }
00077 
00078 #endif

Site Contact