All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
vertex_to_edge_iterator.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_VERTEX_TO_EDGE_ITERATOR_HPP
16 #define PAAL_VERTEX_TO_EDGE_ITERATOR_HPP
17 
19 
20 namespace paal {
21 namespace data_structures {
22 
23 // TODO use boost:::iterator_fascade
32 template <typename vertex_iterator> class vertex_to_edge_iterator {
33  public:
34  typedef typename std::iterator_traits<vertex_iterator>::value_type Vertex;
35  typedef std::pair<Vertex, Vertex> Edge;
36 
37  typedef std::forward_iterator_tag iterator_category;
38  typedef Edge value_type;
39  typedef ptrdiff_t difference_type;
40  typedef Edge *pointer;
41  typedef const Edge &reference;
42 
49  vertex_to_edge_iterator(vertex_iterator b, vertex_iterator e)
50  : m_idx(b), m_begin(b), m_end(e) {
51  move_curr();
52  }
53 
54  vertex_to_edge_iterator() = default;
55 
62  ++m_idx;
63  move_curr();
64 
65  return *this;
66  }
67 
74  vertex_to_edge_iterator i(*this);
75  operator++();
76  return i;
77  }
78 
87  return !operator==(ei);
88  }
89 
98  return m_idx == ei.m_idx;
99  }
100 
106  const Edge *const operator->() const { return &m_curr; }
107 
113  const Edge &operator*() const { return m_curr; }
114 
115  private:
119  void move_curr() {
120  if (m_idx != m_end) {
121  m_curr.first = *m_idx;
122  vertex_iterator next = m_idx;
123  ++next;
124  if (next == m_end) {
125  m_curr.second = *m_begin;
126  } else {
127  m_curr.second = *next;
128  }
129  }
130  }
131 
132  vertex_iterator m_idx;
133  vertex_iterator m_begin;
134  vertex_iterator m_end;
135  Edge m_curr;
136 };
137 
147 template <typename vertex_iterator>
148 vertex_to_edge_iterator<vertex_iterator>
149 make_vertex_to_edge_iterator(vertex_iterator b, vertex_iterator e) {
151 }
152 
161 template <typename vertex_iterator>
162 vertex_to_edge_iterator<vertex_iterator>
163 make_vertex_to_edge_iterator(std::pair<vertex_iterator, vertex_iterator> r) {
164  return vertex_to_edge_iterator<vertex_iterator>(r.first, r.second);
165 }
166 
167 } // data_structures
168 } // paal
169 
170 #endif // PAAL_VERTEX_TO_EDGE_ITERATOR_HPP
bool operator!=(vertex_to_edge_iterator ei) const
operator !=
bool operator==(vertex_to_edge_iterator ei) const
operator==
vertex_to_edge_iterator(vertex_iterator b, vertex_iterator e)
constructor
const Edge *const operator->() const
operator-&gt;
vertex_to_edge_iterator operator++(int)
operator++ pre increment
transforms collection to collection of pairs consecutive elements of the input collection. The last element and the first element are considered consecutive.
vertex_to_edge_iterator & operator++()
operator++ post increment
vertex_to_edge_iterator< vertex_iterator > make_vertex_to_edge_iterator(vertex_iterator b, vertex_iterator e)
make for vertex_to_edge_iterator