tree-node.h

Go to the documentation of this file.
00001 // Copyright 2007, Massachusetts Institute of Technology.
00002 // The use of this code is permitted for research only. There is
00003 // absolutely no warranty for this software.
00004 //
00005 // Author: John Lee (jjl@mit.edu)
00006 //
00007 
00008 #ifndef TREE_TREE_NODE_H
00009 #define TREE_TREE_NODE_H
00010 
00011 #include <iostream>
00012 #include <vector>
00013 
00014 using namespace std;
00015 
00016 namespace libpmk {
00017 
00019 
00042 class TreeNode {
00043 public:
00044   static const int kInvalidNodeID = -1;
00045 
00046   TreeNode();
00047   TreeNode(int node_id);
00048 
00050   TreeNode(const TreeNode& other);
00051 
00052   virtual ~TreeNode() { }
00053 
00054   int id() const { return id_; }
00055   int parent() const { return parent_; }
00056   int child(int child_index) const { return children_.at(child_index); }
00057 
00058   int child_size() const { return (int)children_.size(); }
00059   bool has_parent() const { return parent_ != kInvalidNodeID; }
00060   bool has_child() const { return child_size() > 0; }
00061 
00062   void set_id(int id) { id_ = id; }
00063   void set_parent(int id) { parent_ = id; }
00064 
00066 
00070   void add_child(int id) { children_.push_back(id); }
00071 
00073   void remove_child(int child_index);
00074 
00075 
00077 
00089   void ReadFromStream(istream& input_stream);
00090 
00092 
00097   void WriteToStream(ostream& output_stream) const;
00098 
00100   virtual void Combine(const TreeNode& other) = 0;
00101 
00102 protected:
00104   virtual void ReadData(istream& input_stream) = 0;
00105 
00107   virtual void WriteData(ostream& output_stream) const = 0;
00108 
00109 private:
00110   int id_;
00111   int parent_;
00112   vector<int> children_;
00113 };
00114 }  // namespace libpmk
00115 
00116 #endif  // TREE_TREE_NODE_H

Generated on Fri Sep 21 11:39:04 2007 for libpmk2 by  doxygen 1.5.1