1 #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
2 #define RAPIDXML_ITERATORS_HPP_INCLUDED
4 // Copyright (C) 2006, 2009 Marcin Kalicinski
6 // Revision $DateTime: 2009/05/13 01:46:17 $
7 //! \file rapidxml_iterators.hpp This file contains rapidxml iterators
9 #include "rapidxml.hpp"
14 //! Iterator of child nodes of xml_node
21 typedef typename xml_node<Ch> value_type;
22 typedef typename xml_node<Ch> &reference;
23 typedef typename xml_node<Ch> *pointer;
24 typedef std::ptrdiff_t difference_type;
25 typedef std::bidirectional_iterator_tag iterator_category;
32 node_iterator(xml_node<Ch> *node)
33 : m_node(node->first_node())
37 reference operator *() const
43 pointer operator->() const
49 node_iterator &operator++()
52 m_node = m_node->next_sibling();
56 node_iterator operator++(int)
58 node_iterator tmp = *this;
63 node_iterator &operator--()
65 assert(m_node && m_node->previous_sibling());
66 m_node = m_node->previous_sibling();
70 node_iterator operator--(int)
72 node_iterator tmp = *this;
77 bool operator ==(const node_iterator<Ch> &rhs)
79 return m_node == rhs.m_node;
82 bool operator !=(const node_iterator<Ch> &rhs)
84 return m_node != rhs.m_node;
93 //! Iterator of child attributes of xml_node
95 class attribute_iterator
100 typedef typename xml_attribute<Ch> value_type;
101 typedef typename xml_attribute<Ch> &reference;
102 typedef typename xml_attribute<Ch> *pointer;
103 typedef std::ptrdiff_t difference_type;
104 typedef std::bidirectional_iterator_tag iterator_category;
111 attribute_iterator(xml_node<Ch> *node)
112 : m_attribute(node->first_attribute())
116 reference operator *() const
122 pointer operator->() const
128 attribute_iterator &operator++()
131 m_attribute = m_attribute->next_attribute();
135 attribute_iterator operator++(int)
137 attribute_iterator tmp = *this;
142 attribute_iterator &operator--()
144 assert(m_attribute && m_attribute->previous_attribute());
145 m_attribute = m_attribute->previous_attribute();
149 attribute_iterator operator--(int)
151 attribute_iterator tmp = *this;
156 bool operator ==(const attribute_iterator<Ch> &rhs)
158 return m_attribute == rhs.m_attribute;
161 bool operator !=(const attribute_iterator<Ch> &rhs)
163 return m_attribute != rhs.m_attribute;
168 xml_attribute<Ch> *m_attribute;