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