mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-10 04:51:17 +00:00
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:
35
node.cpp
35
node.cpp
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user