rapidxml_iterators.hpp
Go to the documentation of this file.
00001 #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
00002 #define RAPIDXML_ITERATORS_HPP_INCLUDED
00003 
00004 // Copyright (C) 2006, 2009 Marcin Kalicinski
00005 // Version 1.13
00006 // Revision $DateTime: 2009/05/13 01:46:17 $
00008 
00009 #include "rapidxml.hpp"
00010 
00011 namespace rapidxml
00012 {
00013 
00015     template<class Ch>
00016     class node_iterator
00017     {
00018     
00019     public:
00020 
00021         typedef typename xml_node<Ch> value_type;
00022         typedef typename xml_node<Ch> &reference;
00023         typedef typename xml_node<Ch> *pointer;
00024         typedef std::ptrdiff_t difference_type;
00025         typedef std::bidirectional_iterator_tag iterator_category;
00026         
00027         node_iterator()
00028             : m_node(0)
00029         {
00030         }
00031 
00032         node_iterator(xml_node<Ch> *node)
00033             : m_node(node->first_node())
00034         {
00035         }
00036         
00037         reference operator *() const
00038         {
00039             assert(m_node);
00040             return *m_node;
00041         }
00042 
00043         pointer operator->() const
00044         {
00045             assert(m_node);
00046             return m_node;
00047         }
00048 
00049         node_iterator& operator++()
00050         {
00051             assert(m_node);
00052             m_node = m_node->next_sibling();
00053             return *this;
00054         }
00055 
00056         node_iterator operator++(int)
00057         {
00058             node_iterator tmp = *this;
00059             ++this;
00060             return tmp;
00061         }
00062 
00063         node_iterator& operator--()
00064         {
00065             assert(m_node && m_node->previous_sibling());
00066             m_node = m_node->previous_sibling();
00067             return *this;
00068         }
00069 
00070         node_iterator operator--(int)
00071         {
00072             node_iterator tmp = *this;
00073             ++this;
00074             return tmp;
00075         }
00076 
00077         bool operator ==(const node_iterator<Ch> &rhs)
00078         {
00079             return m_node == rhs.m_node;
00080         }
00081 
00082         bool operator !=(const node_iterator<Ch> &rhs)
00083         {
00084             return m_node != rhs.m_node;
00085         }
00086 
00087     private:
00088 
00089         xml_node<Ch> *m_node;
00090 
00091     };
00092 
00094     template<class Ch>
00095     class attribute_iterator
00096     {
00097     
00098     public:
00099 
00100         typedef typename xml_attribute<Ch> value_type;
00101         typedef typename xml_attribute<Ch> &reference;
00102         typedef typename xml_attribute<Ch> *pointer;
00103         typedef std::ptrdiff_t difference_type;
00104         typedef std::bidirectional_iterator_tag iterator_category;
00105         
00106         attribute_iterator()
00107             : m_attribute(0)
00108         {
00109         }
00110 
00111         attribute_iterator(xml_node<Ch> *node)
00112             : m_attribute(node->first_attribute())
00113         {
00114         }
00115         
00116         reference operator *() const
00117         {
00118             assert(m_attribute);
00119             return *m_attribute;
00120         }
00121 
00122         pointer operator->() const
00123         {
00124             assert(m_attribute);
00125             return m_attribute;
00126         }
00127 
00128         attribute_iterator& operator++()
00129         {
00130             assert(m_attribute);
00131             m_attribute = m_attribute->next_attribute();
00132             return *this;
00133         }
00134 
00135         attribute_iterator operator++(int)
00136         {
00137             attribute_iterator tmp = *this;
00138             ++this;
00139             return tmp;
00140         }
00141 
00142         attribute_iterator& operator--()
00143         {
00144             assert(m_attribute && m_attribute->previous_attribute());
00145             m_attribute = m_attribute->previous_attribute();
00146             return *this;
00147         }
00148 
00149         attribute_iterator operator--(int)
00150         {
00151             attribute_iterator tmp = *this;
00152             ++this;
00153             return tmp;
00154         }
00155 
00156         bool operator ==(const attribute_iterator<Ch> &rhs)
00157         {
00158             return m_attribute == rhs.m_attribute;
00159         }
00160 
00161         bool operator !=(const attribute_iterator<Ch> &rhs)
00162         {
00163             return m_attribute != rhs.m_attribute;
00164         }
00165 
00166     private:
00167 
00168         xml_attribute<Ch> *m_attribute;
00169 
00170     };
00171 
00172 }
00173 
00174 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:17