summaryrefslogtreecommitdiff
path: root/libs/pbd/xml++.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2012-03-07 02:07:35 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2012-03-07 02:07:35 +0000
commit3c7f9586aec6d1e26966c4b836fb2ee9505e0146 (patch)
tree6b48893152fe7a9191e295f420e6b5633aaca121 /libs/pbd/xml++.cc
parentfb6895ba8634d86fc57f9638f0e0c61d32eb131f (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
Diffstat (limited to 'libs/pbd/xml++.cc')
-rw-r--r--libs/pbd/xml++.cc60
1 files changed, 43 insertions, 17 deletions
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&