scide: implement selectionLength for openDocument
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / iterator.cpp
blobf4159e32ffd1b62a90049829457a3555560f13d0
1 #include "yaml-cpp/node.h"
2 #include "yaml-cpp/exceptions.h"
3 #include "iterpriv.h"
5 namespace YAML
7 Iterator::Iterator(): m_pData(new IterPriv)
11 Iterator::Iterator(std::auto_ptr<IterPriv> pData): m_pData(pData)
15 Iterator::Iterator(const Iterator& rhs): m_pData(new IterPriv(*rhs.m_pData))
19 Iterator& Iterator::operator = (const Iterator& rhs)
21 if(this == &rhs)
22 return *this;
24 m_pData.reset(new IterPriv(*rhs.m_pData));
25 return *this;
28 Iterator::~Iterator()
32 Iterator& Iterator::operator ++ ()
34 if(m_pData->type == IterPriv::IT_SEQ)
35 ++m_pData->seqIter;
36 else if(m_pData->type == IterPriv::IT_MAP)
37 ++m_pData->mapIter;
39 return *this;
42 Iterator Iterator::operator ++ (int)
44 Iterator temp = *this;
46 if(m_pData->type == IterPriv::IT_SEQ)
47 ++m_pData->seqIter;
48 else if(m_pData->type == IterPriv::IT_MAP)
49 ++m_pData->mapIter;
51 return temp;
54 const Node& Iterator::operator * () const
56 if(m_pData->type == IterPriv::IT_SEQ)
57 return **m_pData->seqIter;
59 throw BadDereference();
62 const Node *Iterator::operator -> () const
64 if(m_pData->type == IterPriv::IT_SEQ)
65 return *m_pData->seqIter;
67 throw BadDereference();
70 const Node& Iterator::first() const
72 if(m_pData->type == IterPriv::IT_MAP)
73 return *m_pData->mapIter->first;
75 throw BadDereference();
78 const Node& Iterator::second() const
80 if(m_pData->type == IterPriv::IT_MAP)
81 return *m_pData->mapIter->second;
83 throw BadDereference();
86 bool operator == (const Iterator& it, const Iterator& jt)
88 if(it.m_pData->type != jt.m_pData->type)
89 return false;
91 if(it.m_pData->type == IterPriv::IT_SEQ)
92 return it.m_pData->seqIter == jt.m_pData->seqIter;
93 else if(it.m_pData->type == IterPriv::IT_MAP)
94 return it.m_pData->mapIter == jt.m_pData->mapIter;
96 return true;
99 bool operator != (const Iterator& it, const Iterator& jt)
101 return !(it == jt);