]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | |
5 | // | |
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 | //======================================================================= | |
10 | ||
11 | #ifndef BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP | |
12 | #define BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP | |
13 | ||
14 | #include <boost/operators.hpp> | |
15 | ||
16 | namespace boost { | |
17 | ||
18 | namespace detail { | |
19 | ||
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 | |
23 | // list. | |
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> { | |
31 | ||
32 | private: | |
33 | typedef component_index_iterator<IndexRandomAccessIterator> self; | |
34 | ||
35 | public: | |
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; | |
41 | ||
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) { } | |
47 | ||
48 | // Constructor for "end" iterator (end_index should be the linked | |
49 | // list terminator). | |
50 | component_index_iterator(value_type end_index) : | |
51 | m_current_index(end_index) { } | |
52 | ||
53 | inline value_type operator*() const { | |
54 | return (m_current_index); | |
55 | } | |
56 | ||
57 | self& operator++() { | |
58 | // Move to the next element in the linked list | |
59 | m_current_index = m_index_iterator[m_current_index]; | |
60 | return (*this); | |
61 | } | |
62 | ||
63 | bool operator==(const self& other_iterator) const { | |
64 | return (m_current_index == *other_iterator); | |
65 | } | |
66 | ||
67 | protected: | |
68 | IndexRandomAccessIterator m_index_iterator; | |
69 | value_type m_current_index; | |
70 | ||
71 | }; // class component_index_iterator | |
72 | ||
73 | } // namespace detail | |
74 | ||
75 | } // namespace detail | |
76 | ||
77 | #endif // BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP |