Add XMLNode::operator==/!=() for comparing XMLNode instances
Implemented to be able to test that when writing an XML document via XMLTree and then reading back into another XMLTree the structure is equivalent as a general API test of pbd/xml++.h to check for breakage when changing implementation.
This commit is contained in:
parent
734a4c10e4
commit
4b2987d0f2
|
@ -101,6 +101,9 @@ public:
|
|||
|
||||
XMLNode& operator= (const XMLNode& other);
|
||||
|
||||
bool operator== (const XMLNode& other) const;
|
||||
bool operator!= (const XMLNode& other) const;
|
||||
|
||||
const std::string& name() const { return _name; }
|
||||
|
||||
bool is_content() const { return _is_content; }
|
||||
|
|
|
@ -289,6 +289,70 @@ XMLNode::operator= (const XMLNode& from)
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool
|
||||
XMLNode::operator== (const XMLNode& other) const
|
||||
{
|
||||
if (is_content () != other.is_content ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_content ()) {
|
||||
if (content () != other.content ()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (name () != other.name ()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
XMLPropertyList const& other_properties = other.properties ();
|
||||
|
||||
if (_proplist.size () != other_properties.size ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XMLPropertyConstIterator our_prop_iter = _proplist.begin();
|
||||
XMLPropertyConstIterator other_prop_iter = other_properties.begin();
|
||||
|
||||
while (our_prop_iter != _proplist.end ()) {
|
||||
XMLProperty const* our_prop = *our_prop_iter;
|
||||
XMLProperty const* other_prop = *other_prop_iter;
|
||||
if (our_prop->name () != other_prop->name () || our_prop->value () != other_prop->value ()) {
|
||||
return false;
|
||||
}
|
||||
++our_prop_iter;
|
||||
++other_prop_iter;
|
||||
}
|
||||
|
||||
XMLNodeList const& other_children = other.children();
|
||||
|
||||
if (_children.size() != other_children.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
XMLNodeConstIterator our_child_iter = _children.begin ();
|
||||
XMLNodeConstIterator other_child_iter = other_children.begin ();
|
||||
|
||||
while (our_child_iter != _children.end()) {
|
||||
XMLNode const* our_child = *our_child_iter;
|
||||
XMLNode const* other_child = *other_child_iter;
|
||||
|
||||
if (*our_child != *other_child) {
|
||||
return false;
|
||||
}
|
||||
++our_child_iter;
|
||||
++other_child_iter;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
XMLNode::operator!= (const XMLNode& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
const string&
|
||||
XMLNode::set_content(const string& c)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user