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
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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&
|
||||
|
||||
Reference in New Issue
Block a user