From 423925cf5996c0ba679d472cea20194a2dc646ad Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Tue, 26 Mar 2013 22:20:40 +0100 Subject: [PATCH] step forward functionality in edge_iterator has been lifted up --- graph.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/graph.h b/graph.h index 2decfa7..72fd132 100644 --- a/graph.h +++ b/graph.h @@ -128,18 +128,28 @@ public: reference_self_type operator=(const_reference_self_type o) { if (this != &o) { m_vertex_it = o.m_vertex_it; m_edge_it = o.m_edge_it; } return *this; } - edge_reference operator*() { if (!m_edge) { m_edge = new Edge(*m_vertex_it, (*m_edge_it).m_destination, (*m_edge_it).m_weight); } return *m_edge; } - edge_pointer operator->() { if (!m_edge) { m_edge = new Edge(*m_vertex_it, (*m_edge_it).m_destination, (*m_edge_it).m_weight); } return m_edge; } - - /// @todo implement: delete m_edge & step; -// self_type &operator++() { ++m_it; return *this; } -// self_type operator++(int) { self_type tmp(*this); ++(*this); return tmp; } -// self_type operator+(difference_type n) { self_type tmp(*this); tmp.pos_ += n; return tmp; } -// self_type &operator+=(difference_type n) { m_it += n; return *this; } - bool operator==(const_reference_self_type o) { return m_vertex_it == o.m_vertex_it && m_edge_it == o.m_edge_it; } + edge_reference operator*() { if (!m_edge) { initEdge(); } return *m_edge; } + edge_pointer operator->() { if (!m_edge) { initEdge(); } return m_edge; } + + self_type &operator++() { advance(1); return *this; } + self_type operator++(int) { self_type tmp(*this); advance(1); return tmp; } + self_type operator+(difference_type n) { self_type tmp(*this); tmp.pos_ += n; return tmp; } + self_type &operator+=(difference_type n) { advance(n); return *this; } + bool operator==(const_reference_self_type o) + { return m_vertex_it == o.m_vertex_it && m_edge_it == o.m_edge_it; } bool operator!=(const_reference_self_type o) { return !(*this == o); } private: + void initEdge() + { m_edge = new Edge(*m_vertex_it, (*m_edge_it).m_destination, (*m_edge_it).m_weight); } + void invalidateEdge() { if (m_edge) delete m_edge; } + + void advance(int n) + { + invalidateEdge(); + /// @todo Do the stepping + } + typename std::vector::iterator m_vertex_it; typename std::list::iterator m_edge_it; edge_pointer m_edge;