![]() |
zeep::xml::iterator_impl — generic iterator class.
// In header: <zeep/xml/node.hpp> template<typename NodeType, typename ContainerNodeType = std::remove_const_t<NodeType> > class iterator_impl { public: // types typedef NodeType node_type; typedef std::remove_cv_t< ContainerNodeType > container_node_type; typedef basic_node_list< container_node_type > container_type; typedef std::bidirectional_iterator_tag iterator_category; typedef node_type value_type; typedef std::ptrdiff_t difference_type; typedef value_type * pointer; typedef value_type & reference; // construct/copy/destruct iterator_impl() = default; iterator_impl(const iterator_impl &) = default; template<typename OtherNodeType, typename OtherContainerNodeType> iterator_impl(const iterator_impl< OtherNodeType, OtherContainerNodeType > &); iterator_impl(const container_type &); iterator_impl(const container_type &, node_type *); iterator_impl(node_type *); iterator_impl(iterator_impl &&); template<typename Iterator, std::enable_if_t< not std::is_same_v< std::remove_const_t< typename Iterator::value_type >, element > and std::is_base_of_v< value_type, typename Iterator::value_type >, int > = 0> iterator_impl(const Iterator &); iterator_impl & operator=(const iterator_impl &); iterator_impl & operator=(iterator_impl &&); template<typename Iterator, std::enable_if_t< std::is_base_of_v< value_type, typename Iterator::value_type >, int > = 0> iterator_impl & operator=(const Iterator &); // public member functions reference operator*(); pointer operator->() const; iterator_impl & operator++(); iterator_impl operator++(int); iterator_impl & operator--(); iterator_impl operator--(int); bool operator==(const iterator_impl &) const; bool operator!=(const iterator_impl &) const; template<typename RNodeType> bool operator==(const RNodeType *) const; template<typename RNodeType> bool operator!=(const RNodeType) const; iterator_impl & operator+=(difference_type); iterator_impl & operator-=(difference_type); iterator_impl operator+(difference_type) const; iterator_impl operator-(difference_type) const; difference_type operator-(const iterator_impl &) const; operator const pointer() const; operator pointer(); // private member functions node_type * current() const; void skip(); void skip(); void skip(); void skip(); void skip(); };
We can have iterators that point to nodes, elements and attributes. Iterating over nodes is simply following next/prev. But iterating elements is a bit more difficult, since you then have to skip nodes in between that are not an element, like comments or text.
iterator_impl
public
construct/copy/destructiterator_impl() = default;
iterator_impl(const iterator_impl & i) = default;
template<typename OtherNodeType, typename OtherContainerNodeType> iterator_impl(const iterator_impl< OtherNodeType, OtherContainerNodeType > & i);copy constructor, kind of
iterator_impl(const container_type & container);create iterator pointing to begin of parent element
iterator_impl(const container_type & container, node_type * current);create iterator pointing to end of parent element
iterator_impl(node_type * current);constructor taking a node pointer
iterator_impl(iterator_impl && i);
template<typename Iterator, std::enable_if_t< not std::is_same_v< std::remove_const_t< typename Iterator::value_type >, element > and std::is_base_of_v< value_type, typename Iterator::value_type >, int > = 0> iterator_impl(const Iterator & i);
iterator_impl & operator=(const iterator_impl & i);
iterator_impl & operator=(iterator_impl && i);
template<typename Iterator, std::enable_if_t< std::is_base_of_v< value_type, typename Iterator::value_type >, int > = 0> iterator_impl & operator=(const Iterator & i);
iterator_impl
public member functionsreference operator*();
pointer operator->() const;
iterator_impl & operator++();
iterator_impl operator++(int);
iterator_impl & operator--();
iterator_impl operator--(int);
bool operator==(const iterator_impl & other) const;
bool operator!=(const iterator_impl & other) const;
template<typename RNodeType> bool operator==(const RNodeType * n) const;
template<typename RNodeType> bool operator!=(const RNodeType n) const;
iterator_impl & operator+=(difference_type i);
iterator_impl & operator-=(difference_type i);
iterator_impl operator+(difference_type i) const;
iterator_impl operator-(difference_type i) const;
difference_type operator-(const iterator_impl & other) const;
operator const pointer() const;
operator pointer();