iterator.cpp
Go to the documentation of this file.
1 #include "yaml-cpp-pm/node.h"
3 #include "iterpriv.h"
4 
5 namespace YAML_PM
6 {
7  Iterator::Iterator(): m_pData(new IterPriv)
8  {
9  }
10 
11  Iterator::Iterator(std::auto_ptr<IterPriv> pData): m_pData(pData)
12  {
13  }
14 
15  Iterator::Iterator(const Iterator& rhs): m_pData(new IterPriv(*rhs.m_pData))
16  {
17  }
18 
20  {
21  if(this == &rhs)
22  return *this;
23 
24  m_pData.reset(new IterPriv(*rhs.m_pData));
25  return *this;
26  }
27 
29  {
30  }
31 
33  {
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;
38 
39  return *this;
40  }
41 
43  {
44  Iterator temp = *this;
45 
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;
50 
51  return temp;
52  }
53 
54  const Node& Iterator::operator * () const
55  {
56  if(m_pData->type == IterPriv::IT_SEQ)
57  return **m_pData->seqIter;
58 
59  throw BadDereference();
60  }
61 
63  {
64  if(m_pData->type == IterPriv::IT_SEQ)
65  return *m_pData->seqIter;
66 
67  throw BadDereference();
68  }
69 
70  const Node& Iterator::first() const
71  {
72  if(m_pData->type == IterPriv::IT_MAP)
73  return *m_pData->mapIter->first;
74 
75  throw BadDereference();
76  }
77 
78  const Node& Iterator::second() const
79  {
80  if(m_pData->type == IterPriv::IT_MAP)
81  return *m_pData->mapIter->second;
82 
83  throw BadDereference();
84  }
85 
86  bool operator == (const Iterator& it, const Iterator& jt)
87  {
88  if(it.m_pData->type != jt.m_pData->type)
89  return false;
90 
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;
95 
96  return true;
97  }
98 
99  bool operator != (const Iterator& it, const Iterator& jt)
100  {
101  return !(it == jt);
102  }
103 }
YAML_PM::Iterator::m_pData
std::auto_ptr< IterPriv > m_pData
Definition: iterator.h:36
exceptions.h
YAML_PM::Iterator::~Iterator
~Iterator()
Definition: iterator.cpp:28
YAML_PM::operator!=
bool operator!=(const _Null &, const _Null &)
Definition: null.h:17
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::operator==
bool operator==(const _Null &, const _Null &)
Definition: null.h:16
YAML_PM::IterPriv::IT_SEQ
@ IT_SEQ
Definition: iterpriv.h:25
YAML_PM::Iterator::operator++
Iterator & operator++()
Definition: iterator.cpp:32
YAML_PM::Iterator::Iterator
Iterator()
Definition: iterator.cpp:7
node.h
YAML_PM::IterPriv
Definition: iterpriv.h:19
YAML_PM::Iterator::operator*
const Node & operator*() const
Definition: iterator.cpp:54
YAML_PM::Iterator::operator=
Iterator & operator=(const Iterator &rhs)
Definition: iterator.cpp:19
iterpriv.h
YAML_PM::Node
Definition: node.h:33
YAML_PM::IterPriv::IT_MAP
@ IT_MAP
Definition: iterpriv.h:25
YAML_PM::BadDereference
Definition: exceptions.h:151
YAML_PM::Iterator
Definition: iterator.h:16
YAML_PM::Iterator::operator->
const Node * operator->() const
Definition: iterator.cpp:62
YAML_PM::Iterator::second
const Node & second() const
Definition: iterator.cpp:78
YAML_PM::Iterator::first
const Node & first() const
Definition: iterator.cpp:70


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:59