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 UTIL_TREE_NODE_H 00009 #define UTIL_TREE_NODE_H 00010 00011 #include <iostream> 00012 #include "util/sparse-vector.h" 00013 00014 using namespace std; 00015 00016 namespace libpmk { 00017 00019 00046 class TreeNode { 00047 public: 00049 TreeNode(); 00050 00052 TreeNode(const LargeIndex& index); 00053 00055 00058 TreeNode(const TreeNode& other); 00059 00060 virtual ~TreeNode(); 00061 00062 const LargeIndex& GetIndex() const; 00063 TreeNode* GetParent(); 00064 TreeNode* GetPreviousSibling(); 00065 TreeNode* GetNextSibling(); 00066 TreeNode* GetFirstChild(); 00067 TreeNode* GetLastChild(); 00068 00069 void SetParent(TreeNode* parent); 00070 void SetPreviousSibling(TreeNode* sibling); 00071 void SetNextSibling(TreeNode* sibling); 00072 void SetFirstChild(TreeNode* child); 00073 void SetLastChild(TreeNode* child); 00074 void SetIndex(const LargeIndex& index); 00075 00076 bool HasParent() const; 00077 bool HasPreviousSibling() const; 00078 bool HasNextSibling() const; 00079 bool HasChild() const; 00080 00082 00092 void ReadFromStream(istream& input_stream); 00093 00095 00100 void WriteToStream(ostream& output_stream) const; 00101 00103 virtual void Combine(const TreeNode& other) = 0; 00104 00106 bool operator<(const TreeNode& other) const; 00107 00109 static bool CompareNodes(const TreeNode* one, const TreeNode* two); 00110 00111 protected: 00113 virtual void ReadData(istream& input_stream) = 0; 00114 00116 virtual void WriteData(ostream& output_stream) const = 0; 00117 private: 00118 LargeIndex index_; 00119 TreeNode* parent_; 00120 TreeNode* next_sibling_; 00121 TreeNode* previous_sibling_; 00122 TreeNode* first_child_; 00123 TreeNode* last_child_; 00124 }; 00125 } // namespace libpmk 00126 #endif // UTIL_TREE_NODE_H