TreeNode Class Reference

#include <tree-node.h>

Inheritance diagram for TreeNode:

PointTreeNode List of all members.

Detailed Description

An indexed node, used by Tree.

A TreeNode has an integer identifier. It also contains the IDs of its parent and children, but makes no effort to maintain them.

To augment a TreeNode with your own data, there are three functions you need to provide: (1) reading the data from a stream, (2) writing the data to a stream, and (3) how to combine two nodes. The definition of "combine" will vary depending on what you're doing, but the general idea is that sometimes you will have two TreeNodes with the same ID that you want to insert into a tree. It is advisable that you make the output of Combine() symmetric, since there are no guarantees on what Tree does with duplicate-ID bins other than calling Combine().

Remember that if you implement a copy constructor for your TreeNode, you should have your copy constructor call the base class's copy constructor:
MyNode::MyNode(const MyNode& other) : TreeNode(other) {
// your copy code
}


Public Member Functions

 TreeNode ()
 TreeNode (int node_id)
 TreeNode (const TreeNode &other)
 A copy constructor, which copies the ID and parent/child info.
virtual ~TreeNode ()
int id () const
int parent () const
int child (int child_index) const
int child_size () const
bool has_parent () const
bool has_child () const
void set_id (int id)
void set_parent (int id)
void add_child (int id)
 Adds a child to the end of the child list.
void remove_child (int child_index)
 Removes the <child_index>th child.
void ReadFromStream (istream &input_stream)
 Read the data, including the index, from a stream.
void WriteToStream (ostream &output_stream) const
 Write the data, including the index, to a stream.
virtual void Combine (const TreeNode &other)=0
 Add the data from <other> to self.

Static Public Attributes

static const int kInvalidNodeID = -1

Protected Member Functions

virtual void ReadData (istream &input_stream)=0
 Read the data, excluding the index, from a stream.
virtual void WriteData (ostream &output_stream) const=0
 Write the data, excluding the index, to a stream.


Constructor & Destructor Documentation

TreeNode (  ) 

TreeNode ( int  node_id  ) 

TreeNode ( const TreeNode other  ) 

A copy constructor, which copies the ID and parent/child info.

virtual ~TreeNode (  )  [inline, virtual]


Member Function Documentation

int id (  )  const [inline]

int parent (  )  const [inline]

int child ( int  child_index  )  const [inline]

int child_size (  )  const [inline]

bool has_parent (  )  const [inline]

bool has_child (  )  const [inline]

void set_id ( int  id  )  [inline]

void set_parent ( int  id  )  [inline]

void add_child ( int  id  )  [inline]

Adds a child to the end of the child list.

This does not check for dupes, i.e., it is possible for a node to have two children with the same ID using this, so be careful!

void remove_child ( int  child_index  ) 

Removes the <child_index>th child.

void ReadFromStream ( istream &  input_stream  ) 

Read the data, including the index, from a stream.

Calling this will override the node's current index. The format is:

It will then call ReadData().
See also:
ReadData()

void WriteToStream ( ostream &  output_stream  )  const

Write the data, including the index, to a stream.

This will simply write the index to the stream, followed by WriteData().

See also:
WriteData().

virtual void Combine ( const TreeNode other  )  [pure virtual]

Add the data from <other> to self.

Implemented in PointTreeNode.

virtual void ReadData ( istream &  input_stream  )  [protected, pure virtual]

Read the data, excluding the index, from a stream.

Implemented in PointTreeNode.

virtual void WriteData ( ostream &  output_stream  )  const [protected, pure virtual]

Write the data, excluding the index, to a stream.

Implemented in PointTreeNode.


Member Data Documentation

const int kInvalidNodeID = -1 [static]


The documentation for this class was generated from the following files:
Generated on Fri Sep 21 11:39:06 2007 for libpmk2 by  doxygen 1.5.1