Switched the Iterator implementation to a dedicated helper class (to hide the specific implementation, since it's pretty messy and may change).

This commit is contained in:
Jesse Beder
2008-07-21 02:54:39 +00:00
parent 09d7ab365f
commit cc87c83b01
10 changed files with 143 additions and 68 deletions

29
include/iterator.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
namespace YAML
{
class Node;
struct IterPriv;
class Iterator
{
public:
Iterator();
Iterator(IterPriv *pData);
Iterator(const Iterator& rhs);
~Iterator();
friend bool operator == (const Iterator& it, const Iterator& jt);
friend bool operator != (const Iterator& it, const Iterator& jt);
Iterator& operator = (const Iterator& rhs);
Iterator& operator ++ ();
Iterator operator ++ (int);
const Node& operator * ();
const Node *operator -> ();
const Node& first();
const Node& second();
private:
IterPriv *m_pData;
};
}

View File

@@ -1,10 +0,0 @@
#pragma once
namespace YAML
{
class Node;
struct ltnode {
bool operator()(const Node *pNode1, const Node *pNode2) const;
};
}

View File

@@ -6,7 +6,7 @@
#include <map>
#include "parserstate.h"
#include "exceptions.h"
#include "ltnode.h"
#include "iterator.h"
namespace YAML
{
@@ -15,32 +15,6 @@ namespace YAML
class Node
{
public:
class Iterator
{
public:
Iterator();
Iterator(std::vector <Node *>::const_iterator it);
Iterator(std::map <Node *, Node *, ltnode>::const_iterator it);
~Iterator();
friend bool operator == (const Iterator& it, const Iterator& jt);
friend bool operator != (const Iterator& it, const Iterator& jt);
Iterator& operator ++ ();
Iterator operator ++ (int);
const Node& 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 *, ltnode>::const_iterator mapIter;
};
public:
Node();
~Node();

View File

@@ -3,4 +3,5 @@
#include "crt.h"
#include "parser.h"
#include "node.h"
#include "iterator.h"
#include "exceptions.h"