# # patch "roster4.cc" # from [a75fc4f5b6bd0119946f3605d4588aa37d4be915] # to [6a79a267e55c5d6193893071bf39b2ab3cdc717f] # # patch "roster4.hh" # from [59f97e54978e976ba93b9afb23f06ab1108d1bab] # to [1b6763285726bb28b83abcedade46374a37b7568] # ======================================================================== --- roster4.cc a75fc4f5b6bd0119946f3605d4588aa37d4be915 +++ roster4.cc 6a79a267e55c5d6193893071bf39b2ab3cdc717f @@ -209,7 +209,42 @@ out = oss.str(); } +// helper +void +roster_t::do_deep_copy_from(roster_t const & other) +{ + MM(*this); + MM(other); + I(!root_dir); + I(nodes.empty()); + for (node_map::const_iterator i = other.nodes.begin(); i != other.nodes.end(); + ++i) + safe_insert(nodes, std::make_pair(i->first, i->second->clone())); + for (node_map::iterator i = nodes.begin(); i != nodes.end(); ++i) + if (is_dir_t(i->second)) + { + dir_map & children = downcast_to_dir_t(i->second)->children; + for (dir_map::iterator j = children.begin(); j != children.end(); ++j) + j->second = safe_get(nodes, j->second->self); + } + if (other.root_dir) + root_dir = downcast_to_dir_t(safe_get(nodes, other.root_dir->self)); +} +roster_t::roster_t(roster_t const & other) +{ + do_deep_copy_from(other); +} + +roster_t & +roster_t::operator=(roster_t const & other) +{ + root_dir.reset(); + nodes.clear(); + do_deep_copy_from(other); + return *this; +} + static inline void dirname_basename(split_path const & sp, split_path & dirname, path_component & basename) @@ -621,8 +656,11 @@ dump(roster_t const & val, std::string & out) { std::ostringstream oss; - oss << "Root node: " << val.root_dir->self << "\n" - << " at " << val.root_dir << ", uses: " << val.root_dir.use_count() << "\n"; + if (val.root_dir) + oss << "Root node: " << val.root_dir->self << "\n" + << " at " << val.root_dir << ", uses: " << val.root_dir.use_count() << "\n"; + else + oss << "root dir is NULL\n"; for (node_map::const_iterator i = val.nodes.begin(); i != val.nodes.end(); ++i) { oss << "Node " << i->first << "\n"; ======================================================================== --- roster4.hh 59f97e54978e976ba93b9afb23f06ab1108d1bab +++ roster4.hh 1b6763285726bb28b83abcedade46374a37b7568 @@ -143,13 +143,15 @@ { public: roster_t() {} + roster_t(roster_t const & other); + roster_t & operator=(roster_t const & other); bool has_root() const; node_t get_node(split_path const & sp) const; node_t get_node(node_id n) const; void get_name(node_id n, split_path & sp) const; void replace_node_id(node_id from, node_id to); - // editable_tree methods + // editable_tree operations node_id detach_node(split_path const & src); void drop_detached_node(node_id n); node_id create_dir_node(node_id_source & nid); @@ -187,6 +189,7 @@ marking_map & mm); private: + void do_deep_copy_from(roster_t const & other); void check_finite_depth() const; dir_t root_dir; node_map nodes;