Specialized the overloaded [] operator for int/unsigned, and added a size() function, so that you can iterate through a sequence node like a vector.

This commit is contained in:
Jesse Beder 2008-07-02 21:41:54 +00:00
parent 2ccbfeff47
commit 2be40919de
8 changed files with 81 additions and 25 deletions

View file

@ -173,6 +173,41 @@ namespace YAML
return Iterator();
}
// size
// . Returns the size of this node, if it's a sequence node.
// . Otherwise, returns zero.
unsigned Node::size() const
{
if(!m_pContent)
return 0;
return m_pContent->GetSize();
}
const Node& Node::operator [] (unsigned u) const
{
if(!m_pContent)
throw BadDereference();
Node *pNode = m_pContent->GetNode(u);
if(pNode)
return *pNode;
return GetValue(u);
}
const Node& Node::operator [] (int i) const
{
if(!m_pContent)
throw BadDereference();
Node *pNode = m_pContent->GetNode(i);
if(pNode)
return *pNode;
return GetValue(i);
}
///////////////////////////////////////////////////////
// Extraction