• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 namespace detail
20 {
21 
22     // Iterator for a component index linked list.  The contents of
23     // each array element represent the next index in the list.  A
24     // special value (the maximum index + 1) is used to terminate a
25     // list.
26     template < typename IndexRandomAccessIterator >
27     class component_index_iterator
28     : boost::forward_iterator_helper<
29           component_index_iterator< IndexRandomAccessIterator >,
30           typename std::iterator_traits<
31               IndexRandomAccessIterator >::value_type,
32           typename std::iterator_traits<
33               IndexRandomAccessIterator >::difference_type,
34           typename std::iterator_traits< IndexRandomAccessIterator >::pointer,
35           typename std::iterator_traits<
36               IndexRandomAccessIterator >::reference >
37     {
38 
39     private:
40         typedef component_index_iterator< IndexRandomAccessIterator > self;
41 
42     public:
43         typedef std::forward_iterator_tag iterator_category;
44         typedef typename std::iterator_traits<
45             IndexRandomAccessIterator >::value_type value_type;
46         typedef typename std::iterator_traits<
47             IndexRandomAccessIterator >::difference_type reference;
48         typedef
49             typename std::iterator_traits< IndexRandomAccessIterator >::pointer
50                 pointer;
51         typedef typename std::iterator_traits<
52             IndexRandomAccessIterator >::reference difference_type;
53 
54         // Constructor for "begin" iterator
component_index_iterator(IndexRandomAccessIterator index_iterator,value_type begin_index)55         component_index_iterator(
56             IndexRandomAccessIterator index_iterator, value_type begin_index)
57         : m_index_iterator(index_iterator), m_current_index(begin_index)
58         {
59         }
60 
61         // Constructor for "end" iterator (end_index should be the linked
62         // list terminator).
component_index_iterator(value_type end_index)63         component_index_iterator(value_type end_index)
64         : m_current_index(end_index)
65         {
66         }
67 
operator *() const68         inline value_type operator*() const { return (m_current_index); }
69 
operator ++()70         self& operator++()
71         {
72             // Move to the next element in the linked list
73             m_current_index = m_index_iterator[m_current_index];
74             return (*this);
75         }
76 
operator ==(const self & other_iterator) const77         bool operator==(const self& other_iterator) const
78         {
79             return (m_current_index == *other_iterator);
80         }
81 
82     protected:
83         IndexRandomAccessIterator m_index_iterator;
84         value_type m_current_index;
85 
86     }; // class component_index_iterator
87 
88 } // namespace detail
89 
90 } // namespace detail
91 
92 #endif // BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP
93