"docs/source/en/api/diffusion_pipeline.md" did not exist on "a6e2c1fe5c02cae8a9f077f5d4e11b73d5791723"
iterator.cpp 2.01 KB
Newer Older
1
#include "crt.h"
2
3
#include "node.h"
#include "exceptions.h"
4
#include "iterpriv.h"
5
6
7

namespace YAML
{
8
	Iterator::Iterator(): m_pData(0)
9
	{
10
		m_pData = new IterPriv;
11
12
	}

13
	Iterator::Iterator(IterPriv *pData): m_pData(pData)
14
15
16
	{
	}

17
	Iterator::Iterator(const Iterator& rhs): m_pData(0)
18
	{
19
		m_pData = new IterPriv(*rhs.m_pData);
20
21
	}

22
	Iterator& Iterator::operator = (const Iterator& rhs)
23
	{
24
25
26
27
28
29
30
31
32
33
34
		if(this == &rhs)
			return *this;

		delete m_pData;
		m_pData = new IterPriv(*rhs.m_pData);
		return *this;
	}

	Iterator::~Iterator()
	{
		delete m_pData;
35
36
	}

37
	Iterator& Iterator::operator ++ ()
38
	{
39
40
41
42
		if(m_pData->type == IterPriv::IT_SEQ)
			++m_pData->seqIter;
		else if(m_pData->type == IterPriv::IT_MAP)
			++m_pData->mapIter;
43
44
45
46

		return *this;
	}

47
	Iterator Iterator::operator ++ (int)
Jesse Beder's avatar
Jesse Beder committed
48
49
50
	{
		Iterator temp = *this;

51
52
53
54
		if(m_pData->type == IterPriv::IT_SEQ)
			++m_pData->seqIter;
		else if(m_pData->type == IterPriv::IT_MAP)
			++m_pData->mapIter;
Jesse Beder's avatar
Jesse Beder committed
55
56
57
58

		return temp;
	}

59
	const Node& Iterator::operator * ()
60
	{
61
62
		if(m_pData->type == IterPriv::IT_SEQ)
			return **m_pData->seqIter;
63
64
65
66

		throw BadDereference();
	}

67
	const Node *Iterator::operator -> ()
68
	{
69
70
		if(m_pData->type == IterPriv::IT_SEQ)
			return &**m_pData->seqIter;
71
72
73
74

		throw BadDereference();
	}

75
	const Node& Iterator::first()
76
	{
77
78
		if(m_pData->type == IterPriv::IT_MAP)
			return *m_pData->mapIter->first;
79
80
81
82

		throw BadDereference();
	}

83
	const Node& Iterator::second()
84
	{
85
86
		if(m_pData->type == IterPriv::IT_MAP)
			return *m_pData->mapIter->second;
87
88
89
90

		throw BadDereference();
	}

91
	bool operator == (const Iterator& it, const Iterator& jt)
92
	{
93
		if(it.m_pData->type != jt.m_pData->type)
94
95
			return false;

96
97
98
99
		if(it.m_pData->type == IterPriv::IT_SEQ)
			return it.m_pData->seqIter == jt.m_pData->seqIter;
		else if(it.m_pData->type == IterPriv::IT_MAP)
			return it.m_pData->mapIter == jt.m_pData->mapIter;
100
101
102
103

		return true;
	}

104
	bool operator != (const Iterator& it, const Iterator& jt)
105
106
107
108
	{
		return !(it == jt);
	}
}