1 //=======================================================================
2 // Copyright 2002 Indiana University.
3 // Copyright 2009 Trustees of Indiana University.
4 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Michael Hansen
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_INCREMENTAL_COMPONENTS_HPP
12 #define BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP
14 #include <boost/operators.hpp>
20 // Iterator for a component index linked list. The contents of
21 // each array element represent the next index in the list. A
22 // special value (the maximum index + 1) is used to terminate a
24 template <typename IndexRandomAccessIterator>
25 class component_index_iterator :
26 boost::forward_iterator_helper<component_index_iterator<IndexRandomAccessIterator>,
27 typename std::iterator_traits<IndexRandomAccessIterator>::value_type,
28 typename std::iterator_traits<IndexRandomAccessIterator>::difference_type,
29 typename std::iterator_traits<IndexRandomAccessIterator>::pointer,
30 typename std::iterator_traits<IndexRandomAccessIterator>::reference> {
33 typedef component_index_iterator<IndexRandomAccessIterator> self;
36 typedef std::forward_iterator_tag iterator_category;
37 typedef typename std::iterator_traits<IndexRandomAccessIterator>::value_type value_type;
38 typedef typename std::iterator_traits<IndexRandomAccessIterator>::difference_type reference;
39 typedef typename std::iterator_traits<IndexRandomAccessIterator>::pointer pointer;
40 typedef typename std::iterator_traits<IndexRandomAccessIterator>::reference difference_type;
42 // Constructor for "begin" iterator
43 component_index_iterator(IndexRandomAccessIterator index_iterator,
44 value_type begin_index) :
45 m_index_iterator(index_iterator),
46 m_current_index(begin_index) { }
48 // Constructor for "end" iterator (end_index should be the linked
50 component_index_iterator(value_type end_index) :
51 m_current_index(end_index) { }
53 inline value_type operator*() const {
54 return (m_current_index);
58 // Move to the next element in the linked list
59 m_current_index = m_index_iterator[m_current_index];
63 bool operator==(const self& other_iterator) const {
64 return (m_current_index == *other_iterator);
68 IndexRandomAccessIterator m_index_iterator;
69 value_type m_current_index;
71 }; // class component_index_iterator
77 #endif // BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP