2 //=======================================================================
3 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
4 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //=======================================================================
11 #ifndef BOOST_GRAPH_DETAIL_ADJ_LIST_EDGE_ITERATOR_HPP
12 #define BOOST_GRAPH_DETAIL_ADJ_LIST_EDGE_ITERATOR_HPP
16 #include <boost/detail/workaround.hpp>
18 #if BOOST_WORKAROUND( __IBMCPP__, <= 600 )
19 # define BOOST_GRAPH_NO_OPTIONAL
22 #ifdef BOOST_GRAPH_NO_OPTIONAL
23 # define BOOST_GRAPH_MEMBER .
25 # define BOOST_GRAPH_MEMBER ->
26 # include <boost/optional.hpp>
27 #endif // ndef BOOST_GRAPH_NO_OPTIONAL
33 template <class VertexIterator
, class OutEdgeIterator
, class Graph
>
34 class adj_list_edge_iterator
{
35 typedef adj_list_edge_iterator self
;
37 typedef std::forward_iterator_tag iterator_category
;
38 typedef typename
OutEdgeIterator::value_type value_type
;
39 typedef typename
OutEdgeIterator::reference reference
;
40 typedef typename
OutEdgeIterator::pointer pointer
;
41 typedef typename
OutEdgeIterator::difference_type difference_type
;
42 typedef difference_type distance_type
;
44 inline adj_list_edge_iterator() {}
46 inline adj_list_edge_iterator(const self
& x
)
47 : vBegin(x
.vBegin
), vCurr(x
.vCurr
), vEnd(x
.vEnd
),
48 edges(x
.edges
), m_g(x
.m_g
) { }
51 inline adj_list_edge_iterator(VertexIterator b
,
55 : vBegin(b
), vCurr(c
), vEnd(e
), m_g(&g
) {
56 if ( vCurr
!= vEnd
) {
57 while ( vCurr
!= vEnd
&& out_degree(*vCurr
, *m_g
) == 0 )
60 edges
= out_edges(*vCurr
, *m_g
);
65 In the directed graph cases, it is fine.
66 For undirected graphs, one edge go through twice.
68 inline self
& operator++() {
69 ++edges BOOST_GRAPH_MEMBER first
;
70 if (edges BOOST_GRAPH_MEMBER first
== edges BOOST_GRAPH_MEMBER second
)
73 while ( vCurr
!= vEnd
&& out_degree(*vCurr
, *m_g
) == 0 )
76 edges
= out_edges(*vCurr
, *m_g
);
80 inline self
operator++(int) {
85 inline value_type
operator*() const
86 { return *edges BOOST_GRAPH_MEMBER first
; }
87 inline bool operator==(const self
& x
) const {
88 return vCurr
== x
.vCurr
90 || edges BOOST_GRAPH_MEMBER first
== x
.edges BOOST_GRAPH_MEMBER first
);
92 inline bool operator!=(const self
& x
) const {
93 return vCurr
!= x
.vCurr
95 && edges BOOST_GRAPH_MEMBER first
!= x
.edges BOOST_GRAPH_MEMBER first
);
98 VertexIterator vBegin
;
102 #ifdef BOOST_GRAPH_NO_OPTIONAL
103 std::pair
<OutEdgeIterator
, OutEdgeIterator
> edges
;
105 boost::optional
<std::pair
<OutEdgeIterator
, OutEdgeIterator
> >
107 #endif // ndef BOOST_GRAPH_NO_OPTIONAL
111 } // namespace detail
115 #undef BOOST_GRAPH_MEMBER
117 #endif // BOOST_GRAPH_DETAIL_ADJ_LIST_EDGE_ITERATOR_HPP