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
10namespace rapidxml
11{
12
13 //! Iterator of child nodes of xml_node
14 template <class Ch>
16 {
17
18 public:
19 using value_type = typename xml_node<Ch>;
20 using reference = typename xml_node<Ch>&;
21 using pointer = typename xml_node<Ch>*;
22 using difference_type = std::ptrdiff_t;
23 using iterator_category = std::bidirectional_iterator_tag;
24
25 node_iterator() : m_node(0)
26 {
27 }
28
29 node_iterator(xml_node<Ch>* node) : m_node(node->first_node())
30 {
31 }
32
34 operator*() const
35 {
36 assert(m_node);
37 return *m_node;
38 }
39
41 operator->() const
42 {
43 assert(m_node);
44 return m_node;
45 }
46
49 {
50 assert(m_node);
51 m_node = m_node->next_sibling();
52 return *this;
53 }
54
57 {
58 node_iterator tmp = *this;
59 ++this;
60 return tmp;
61 }
62
65 {
66 assert(m_node && m_node->previous_sibling());
67 m_node = m_node->previous_sibling();
68 return *this;
69 }
70
73 {
74 node_iterator tmp = *this;
75 ++this;
76 return tmp;
77 }
78
79 bool
81 {
82 return m_node == rhs.m_node;
83 }
84
85 bool
87 {
88 return m_node != rhs.m_node;
89 }
90
91 private:
92 xml_node<Ch>* m_node;
93 };
94
95 //! Iterator of child attributes of xml_node
96 template <class Ch>
98 {
99
100 public:
102 using reference = typename xml_attribute<Ch>&;
103 using pointer = typename xml_attribute<Ch>*;
104 using difference_type = std::ptrdiff_t;
105 using iterator_category = std::bidirectional_iterator_tag;
106
107 attribute_iterator() : m_attribute(0)
108 {
109 }
110
111 attribute_iterator(xml_node<Ch>* node) : m_attribute(node->first_attribute())
112 {
113 }
114
116 operator*() const
117 {
118 assert(m_attribute);
119 return *m_attribute;
120 }
121
122 pointer
124 {
125 assert(m_attribute);
126 return m_attribute;
127 }
128
131 {
132 assert(m_attribute);
133 m_attribute = m_attribute->next_attribute();
134 return *this;
135 }
136
139 {
140 attribute_iterator tmp = *this;
141 ++this;
142 return tmp;
143 }
144
147 {
148 assert(m_attribute && m_attribute->previous_attribute());
149 m_attribute = m_attribute->previous_attribute();
150 return *this;
151 }
152
155 {
156 attribute_iterator tmp = *this;
157 ++this;
158 return tmp;
159 }
160
161 bool
163 {
164 return m_attribute == rhs.m_attribute;
165 }
166
167 bool
169 {
170 return m_attribute != rhs.m_attribute;
171 }
172
173 private:
174 xml_attribute<Ch>* m_attribute;
175 };
176
177} // namespace rapidxml
Iterator of child attributes of xml_node.
std::bidirectional_iterator_tag iterator_category
attribute_iterator & operator--()
attribute_iterator(xml_node< Ch > *node)
bool operator==(const attribute_iterator< Ch > &rhs)
bool operator!=(const attribute_iterator< Ch > &rhs)
typename xml_attribute< Ch > & reference
typename xml_attribute< Ch > * pointer
attribute_iterator operator--(int)
attribute_iterator operator++(int)
attribute_iterator & operator++()
typename xml_attribute< Ch > value_type
Iterator of child nodes of xml_node.
std::bidirectional_iterator_tag iterator_category
node_iterator operator--(int)
bool operator==(const node_iterator< Ch > &rhs)
node_iterator operator++(int)
typename xml_node< Ch > value_type
node_iterator(xml_node< Ch > *node)
typename xml_node< Ch > & reference
bool operator!=(const node_iterator< Ch > &rhs)
typename xml_node< Ch > * pointer
Class representing attribute node of XML document.
Definition rapidxml.hpp:907
Class representing a node of XML document.
This file contains rapidxml parser and DOM implementation.