diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-03-07 02:07:35 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-03-07 02:07:35 +0000 |
commit | 3c7f9586aec6d1e26966c4b836fb2ee9505e0146 (patch) | |
tree | 6b48893152fe7a9191e295f420e6b5633aaca121 | |
parent | fb6895ba8634d86fc57f9638f0e0c61d32eb131f (diff) |
implement XMLNode::operator=() as a deep operation with the same semantics as the XMLNode copy constructor. attempt to share as much code as possible between them and the destructor
git-svn-id: svn://localhost/ardour2/branches/3.0@11612 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | libs/pbd/pbd/xml++.h | 4 | ||||
-rw-r--r-- | libs/pbd/xml++.cc | 60 |
2 files changed, 47 insertions, 17 deletions
diff --git a/libs/pbd/pbd/xml++.h b/libs/pbd/pbd/xml++.h index 6a5097780e..6b6ba34f6d 100644 --- a/libs/pbd/pbd/xml++.h +++ b/libs/pbd/pbd/xml++.h @@ -75,6 +75,8 @@ public: XMLNode(const XMLNode& other); ~XMLNode(); + XMLNode& operator= (const XMLNode& other); + const std::string& name() const { return _name; } bool is_content() const { return _is_content; } @@ -121,6 +123,8 @@ private: XMLPropertyList _proplist; XMLPropertyMap _propmap; mutable XMLNodeList _selected_children; + + void clear_lists (); }; class XMLProperty { diff --git a/libs/pbd/xml++.cc b/libs/pbd/xml++.cc index 58a0c4e747..b97310eea5 100644 --- a/libs/pbd/xml++.cc +++ b/libs/pbd/xml++.cc @@ -206,37 +206,63 @@ XMLNode::XMLNode(const string& n, const string& c) XMLNode::XMLNode(const XMLNode& from) { - XMLPropertyList props; - XMLPropertyIterator curprop; - XMLNodeList nodes; - XMLNodeIterator curnode; - - _name = from.name(); - set_content(from.content()); - - props = from.properties(); - for (curprop = props.begin(); curprop != props.end(); ++curprop) { - add_property((*curprop)->name().c_str(), (*curprop)->value()); - } - - nodes = from.children(); - for (curnode = nodes.begin(); curnode != nodes.end(); ++curnode) { - add_child_copy(**curnode); - } + *this = from; } XMLNode::~XMLNode() { + clear_lists (); +} + +void +XMLNode::clear_lists () +{ XMLNodeIterator curchild; XMLPropertyIterator curprop; + _selected_children.clear (); + _propmap.clear (); + for (curchild = _children.begin(); curchild != _children.end(); ++curchild) { delete *curchild; } + _children.clear (); + for (curprop = _proplist.begin(); curprop != _proplist.end(); ++curprop) { delete *curprop; } + + _proplist.clear (); +} + +XMLNode& +XMLNode::operator= (const XMLNode& from) +{ + if (&from != this) { + + XMLPropertyList props; + XMLPropertyIterator curprop; + XMLNodeList nodes; + XMLNodeIterator curnode; + + clear_lists (); + + _name = from.name(); + set_content(from.content()); + + props = from.properties(); + for (curprop = props.begin(); curprop != props.end(); ++curprop) { + add_property((*curprop)->name().c_str(), (*curprop)->value()); + } + + nodes = from.children(); + for (curnode = nodes.begin(); curnode != nodes.end(); ++curnode) { + add_child_copy(**curnode); + } + } + + return *this; } const string& |