mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 22:11:26 +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
65
node.h
65
node.h
|
@ -2,19 +2,42 @@
|
|||
|
||||
#include <string>
|
||||
#include <ios>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "parserstate.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
namespace YAML
|
||||
{
|
||||
const std::string StrTag = "!!str";
|
||||
const std::string SeqTag = "!!seq";
|
||||
const std::string MapTag = "!!map";
|
||||
|
||||
class Content;
|
||||
class Scanner;
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator();
|
||||
Iterator(std::vector <Node *>::const_iterator it);
|
||||
Iterator(std::map <Node *, Node *>::const_iterator it);
|
||||
~Iterator();
|
||||
|
||||
friend bool operator == (const Iterator& it, const Iterator& jt);
|
||||
friend bool operator != (const Iterator& it, const Iterator& jt);
|
||||
Iterator& operator ++ ();
|
||||
const Node& operator * ();
|
||||
const Node& first();
|
||||
const Node& second();
|
||||
|
||||
private:
|
||||
enum ITER_TYPE { IT_NONE, IT_SEQ, IT_MAP };
|
||||
ITER_TYPE type;
|
||||
|
||||
std::vector <Node *>::const_iterator seqIter;
|
||||
std::map <Node *, Node *>::const_iterator mapIter;
|
||||
};
|
||||
|
||||
public:
|
||||
Node();
|
||||
~Node();
|
||||
|
@ -23,6 +46,40 @@ namespace YAML
|
|||
void Parse(Scanner *pScanner, const ParserState& state);
|
||||
void Write(std::ostream& out, int indent);
|
||||
|
||||
Iterator begin() const;
|
||||
Iterator end() const;
|
||||
|
||||
template <typename T>
|
||||
const Node& operator [] (const T& key) const {
|
||||
if(!m_pContent)
|
||||
throw BadDereference();
|
||||
|
||||
for(Iterator it=begin();it!=end();++it) {
|
||||
T t;
|
||||
try {
|
||||
it.first() >> t;
|
||||
if(key == t)
|
||||
return it.second();
|
||||
} catch(InvalidScalar&) {
|
||||
}
|
||||
}
|
||||
|
||||
throw BadDereference();
|
||||
}
|
||||
|
||||
const Node& operator [] (const char *key) const {
|
||||
return operator [] (std::string(key));
|
||||
}
|
||||
|
||||
// extraction
|
||||
friend void operator >> (const Node& node, std::string& s);
|
||||
friend void operator >> (const Node& node, int& i);
|
||||
friend void operator >> (const Node& node, unsigned& u);
|
||||
friend void operator >> (const Node& node, long& l);
|
||||
friend void operator >> (const Node& node, float& f);
|
||||
friend void operator >> (const Node& node, double& d);
|
||||
friend void operator >> (const Node& node, char& c);
|
||||
|
||||
private:
|
||||
void ParseHeader(Scanner *pScanner, const ParserState& state);
|
||||
void ParseTag(Scanner *pScanner, const ParserState& state);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue