rapidxml_iterators.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // Copyright (C) 2006, 2009 Marcin Kalicinski
4 // Version 1.13
5 // Revision $DateTime: 2009/05/13 01:46:17 $
6 //! \file rapidxml_iterators.hpp This file contains rapidxml iterators
7 
8 #include "rapidxml.hpp"
9 
10 namespace rapidxml
11 {
12 
13  //! Iterator of child nodes of xml_node
14  template<class Ch>
16  {
17 
18  public:
19 
20  using value_type = typename xml_node<Ch>;
21  using reference = typename xml_node<Ch>& ;
22  using pointer = typename xml_node<Ch>* ;
23  using difference_type = std::ptrdiff_t;
24  using iterator_category = std::bidirectional_iterator_tag;
25 
27  : m_node(0)
28  {
29  }
30 
32  : m_node(node->first_node())
33  {
34  }
35 
37  {
38  assert(m_node);
39  return *m_node;
40  }
41 
43  {
44  assert(m_node);
45  return m_node;
46  }
47 
49  {
50  assert(m_node);
51  m_node = m_node->next_sibling();
52  return *this;
53  }
54 
56  {
57  node_iterator tmp = *this;
58  ++this;
59  return tmp;
60  }
61 
63  {
64  assert(m_node && m_node->previous_sibling());
65  m_node = m_node->previous_sibling();
66  return *this;
67  }
68 
70  {
71  node_iterator tmp = *this;
72  ++this;
73  return tmp;
74  }
75 
76  bool operator ==(const node_iterator<Ch>& rhs)
77  {
78  return m_node == rhs.m_node;
79  }
80 
81  bool operator !=(const node_iterator<Ch>& rhs)
82  {
83  return m_node != rhs.m_node;
84  }
85 
86  private:
87 
88  xml_node<Ch>* m_node;
89 
90  };
91 
92  //! Iterator of child attributes of xml_node
93  template<class Ch>
95  {
96 
97  public:
98 
99  using value_type = typename xml_attribute<Ch>;
100  using reference = typename xml_attribute<Ch>& ;
101  using pointer = typename xml_attribute<Ch>* ;
102  using difference_type = std::ptrdiff_t;
103  using iterator_category = std::bidirectional_iterator_tag;
104 
106  : m_attribute(0)
107  {
108  }
109 
111  : m_attribute(node->first_attribute())
112  {
113  }
114 
116  {
117  assert(m_attribute);
118  return *m_attribute;
119  }
120 
122  {
123  assert(m_attribute);
124  return m_attribute;
125  }
126 
128  {
129  assert(m_attribute);
130  m_attribute = m_attribute->next_attribute();
131  return *this;
132  }
133 
135  {
136  attribute_iterator tmp = *this;
137  ++this;
138  return tmp;
139  }
140 
142  {
143  assert(m_attribute && m_attribute->previous_attribute());
144  m_attribute = m_attribute->previous_attribute();
145  return *this;
146  }
147 
149  {
150  attribute_iterator tmp = *this;
151  ++this;
152  return tmp;
153  }
154 
156  {
157  return m_attribute == rhs.m_attribute;
158  }
159 
161  {
162  return m_attribute != rhs.m_attribute;
163  }
164 
165  private:
166 
167  xml_attribute<Ch>* m_attribute;
168 
169  };
170 
171 }
172 
rapidxml::node_iterator::node_iterator
node_iterator()
Definition: rapidxml_iterators.hpp:26
rapidxml::attribute_iterator
Iterator of child attributes of xml_node.
Definition: rapidxml_iterators.hpp:94
rapidxml::node_iterator::node_iterator
node_iterator(xml_node< Ch > *node)
Definition: rapidxml_iterators.hpp:31
rapidxml::attribute_iterator::value_type
typename xml_attribute< Ch > value_type
Definition: rapidxml_iterators.hpp:99
rapidxml::node_iterator::operator==
bool operator==(const node_iterator< Ch > &rhs)
Definition: rapidxml_iterators.hpp:76
rapidxml::node_iterator::operator!=
bool operator!=(const node_iterator< Ch > &rhs)
Definition: rapidxml_iterators.hpp:81
rapidxml::attribute_iterator::pointer
typename xml_attribute< Ch > * pointer
Definition: rapidxml_iterators.hpp:101
rapidxml::node_iterator::reference
typename xml_node< Ch > & reference
Definition: rapidxml_iterators.hpp:21
rapidxml::attribute_iterator::operator++
attribute_iterator operator++(int)
Definition: rapidxml_iterators.hpp:134
rapidxml::attribute_iterator::operator==
bool operator==(const attribute_iterator< Ch > &rhs)
Definition: rapidxml_iterators.hpp:155
rapidxml::attribute_iterator::operator*
reference operator*() const
Definition: rapidxml_iterators.hpp:115
rapidxml::attribute_iterator::operator++
attribute_iterator & operator++()
Definition: rapidxml_iterators.hpp:127
rapidxml::attribute_iterator::attribute_iterator
attribute_iterator()
Definition: rapidxml_iterators.hpp:105
rapidxml::attribute_iterator::operator!=
bool operator!=(const attribute_iterator< Ch > &rhs)
Definition: rapidxml_iterators.hpp:160
rapidxml::node_iterator::value_type
typename xml_node< Ch > value_type
Definition: rapidxml_iterators.hpp:20
rapidxml::node_iterator::operator--
node_iterator operator--(int)
Definition: rapidxml_iterators.hpp:69
rapidxml::xml_attribute
Class representing attribute node of XML document.
Definition: rapidxml.hpp:139
rapidxml::attribute_iterator::difference_type
std::ptrdiff_t difference_type
Definition: rapidxml_iterators.hpp:102
rapidxml::attribute_iterator::attribute_iterator
attribute_iterator(xml_node< Ch > *node)
Definition: rapidxml_iterators.hpp:110
rapidxml
Definition: rapidxml.hpp:58
rapidxml::node_iterator::operator--
node_iterator & operator--()
Definition: rapidxml_iterators.hpp:62
rapidxml::attribute_iterator::reference
typename xml_attribute< Ch > & reference
Definition: rapidxml_iterators.hpp:100
rapidxml::node_iterator
Iterator of child nodes of xml_node.
Definition: rapidxml_iterators.hpp:15
rapidxml::node_iterator::operator*
reference operator*() const
Definition: rapidxml_iterators.hpp:36
rapidxml::node_iterator::operator++
node_iterator & operator++()
Definition: rapidxml_iterators.hpp:48
rapidxml::node_iterator::operator->
pointer operator->() const
Definition: rapidxml_iterators.hpp:42
rapidxml::node_iterator::operator++
node_iterator operator++(int)
Definition: rapidxml_iterators.hpp:55
rapidxml::node_iterator::difference_type
std::ptrdiff_t difference_type
Definition: rapidxml_iterators.hpp:23
rapidxml::node_iterator::pointer
typename xml_node< Ch > * pointer
Definition: rapidxml_iterators.hpp:22
rapidxml::xml_node
Class representing a node of XML document.
Definition: rapidxml.hpp:138
rapidxml::attribute_iterator::operator--
attribute_iterator operator--(int)
Definition: rapidxml_iterators.hpp:148
rapidxml::attribute_iterator::operator--
attribute_iterator & operator--()
Definition: rapidxml_iterators.hpp:141
rapidxml::attribute_iterator::operator->
pointer operator->() const
Definition: rapidxml_iterators.hpp:121
rapidxml.hpp
rapidxml::node_iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: rapidxml_iterators.hpp:24
rapidxml::attribute_iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: rapidxml_iterators.hpp:103