mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
Added an iterator class that can iterate through both sequence and map nodes.
This commit is contained in:
parent
f7358701f2
commit
d56b54b34f
16 changed files with 393 additions and 105 deletions
73
iterator.cpp
Normal file
73
iterator.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "node.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
Node::Iterator::Iterator(): type(IT_NONE)
|
||||
{
|
||||
}
|
||||
|
||||
Node::Iterator::Iterator(std::vector <Node *>::const_iterator it): seqIter(it), type(IT_SEQ)
|
||||
{
|
||||
}
|
||||
|
||||
Node::Iterator::Iterator(std::map <Node *, Node *>::const_iterator it): mapIter(it), type(IT_MAP)
|
||||
{
|
||||
}
|
||||
|
||||
Node::Iterator::~Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
Node::Iterator& Node::Iterator::operator ++ ()
|
||||
{
|
||||
if(type == IT_SEQ)
|
||||
++seqIter;
|
||||
else if(type == IT_MAP)
|
||||
++mapIter;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const Node& Node::Iterator::operator * ()
|
||||
{
|
||||
if(type == IT_SEQ)
|
||||
return **seqIter;
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
const Node& Node::Iterator::first()
|
||||
{
|
||||
if(type == IT_MAP)
|
||||
return *mapIter->first;
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
const Node& Node::Iterator::second()
|
||||
{
|
||||
if(type == IT_MAP)
|
||||
return *mapIter->second;
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
bool operator == (const Node::Iterator& it, const Node::Iterator& jt)
|
||||
{
|
||||
if(it.type != jt.type)
|
||||
return false;
|
||||
|
||||
if(it.type == Node::Iterator::IT_SEQ)
|
||||
return it.seqIter == jt.seqIter;
|
||||
else if(it.type == Node::Iterator::IT_MAP)
|
||||
return it.mapIter == jt.mapIter;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator != (const Node::Iterator& it, const Node::Iterator& jt)
|
||||
{
|
||||
return !(it == jt);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue