Added a (recursive) ordering, so we have a canonical output that we can compare.

This commit is contained in:
beder
2008-07-06 00:06:36 +00:00
parent 3cad5a2ed0
commit 1acc0e4982
15 changed files with 217 additions and 51 deletions

View File

@@ -9,6 +9,12 @@
namespace YAML
{
// the ordering!
bool ltnode::operator ()(const Node *pNode1, const Node *pNode2) const
{
return *pNode1 < *pNode2;
}
Node::Node(): m_pContent(0), m_alias(false)
{
}
@@ -150,7 +156,7 @@ namespace YAML
if(m_pContent->GetBegin(seqIter))
return Iterator(seqIter);
std::map <Node *, Node *>::const_iterator mapIter;
std::map <Node *, Node *, ltnode>::const_iterator mapIter;
if(m_pContent->GetBegin(mapIter))
return Iterator(mapIter);
@@ -168,7 +174,7 @@ namespace YAML
if(m_pContent->GetEnd(seqIter))
return Iterator(seqIter);
std::map <Node *, Node *>::const_iterator mapIter;
std::map <Node *, Node *, ltnode>::const_iterator mapIter;
if(m_pContent->GetEnd(mapIter))
return Iterator(mapIter);
@@ -274,4 +280,24 @@ namespace YAML
node.Write(out, 0, false, false);
return out;
}
int Node::Compare(const Node& rhs) const
{
// Step 1: no content is the smallest
if(!m_pContent) {
if(rhs.m_pContent)
return -1;
else
return 0;
}
if(!rhs.m_pContent)
return 1;
return m_pContent->Compare(rhs.m_pContent);
}
bool operator < (const Node& n1, const Node& n2)
{
return n1.Compare(n2) < 0;
}
}