SDSL: Succinct Data Structure Library
A C++ template library for succinct data structures
|
00001 00005 #ifndef INCLUDED_SDSL_STRUCTURE_TREE 00006 #define INCLUDED_SDSL_STRUCTURE_TREE 00007 00008 #include <vector> 00009 #include <map> 00010 #include <string> 00011 #include <iostream> 00012 00013 using std::vector; 00014 using std::map; 00015 using std::string; 00016 00018 namespace sdsl 00019 { 00020 00021 class structure_tree; // forward declaration 00022 00023 namespace util 00024 { 00025 00026 template<typename T> 00027 std::string to_string(const T&); // forward declaration 00028 00029 } 00030 00032 class structure_tree_node 00033 { 00034 public: 00035 typedef map<string, string> tKeyValue; 00036 friend class structure_tree; 00037 private: 00038 structure_tree_node* m_parent; 00039 vector<structure_tree_node*> m_children; 00040 map<string, string> m_key_values; 00041 void copy(const structure_tree_node& v); 00042 public: 00043 00044 structure_tree_node*& parent; 00045 vector<structure_tree_node*>& children; 00046 map<string, string>& key_values; 00048 structure_tree_node(); 00050 00053 explicit structure_tree_node(structure_tree_node* v); 00055 00060 structure_tree_node(structure_tree_node* v, const string& name, const string& class_name); 00062 structure_tree_node(const structure_tree_node& v); 00064 ~structure_tree_node(); 00065 structure_tree_node& operator=(const structure_tree_node& v); 00067 void swap(structure_tree_node& v); 00069 void add_key_value(const string& key, const string& value); 00070 template<class IntType> 00071 void add_size(IntType value); 00072 }; 00073 00074 class structure_tree 00075 { 00076 public: 00077 static structure_tree_node* add_child(structure_tree_node* v, const string& name, const string& class_name); 00078 template<class IntType> 00079 static void add_size(structure_tree_node* v, IntType value); 00080 static structure_tree_node* parent(const structure_tree_node* v); 00081 }; 00082 00083 00084 enum format_type {JSON_FORMAT, R_FORMAT}; 00085 00086 template<format_type F> 00087 void write_structure_tree(const structure_tree_node* v, std::ostream& out); 00088 00089 00090 template<class IntType> 00091 void structure_tree_node::add_size(IntType value) 00092 { 00093 m_key_values["size"] = util::to_string(value); 00094 } 00095 00096 template<class IntType> 00097 void structure_tree::add_size(structure_tree_node* v, IntType value) 00098 { 00099 if (NULL != v) { 00100 v->add_size(value); 00101 } 00102 } 00103 00104 } 00105 #endif