incremental_components.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP
  11. #define BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP
  12. #include <boost/operators.hpp>
  13. namespace boost
  14. {
  15. namespace detail
  16. {
  17. // Iterator for a component index linked list. The contents of
  18. // each array element represent the next index in the list. A
  19. // special value (the maximum index + 1) is used to terminate a
  20. // list.
  21. template < typename IndexRandomAccessIterator >
  22. class component_index_iterator
  23. : boost::forward_iterator_helper<
  24. component_index_iterator< IndexRandomAccessIterator >,
  25. typename std::iterator_traits<
  26. IndexRandomAccessIterator >::value_type,
  27. typename std::iterator_traits<
  28. IndexRandomAccessIterator >::difference_type,
  29. typename std::iterator_traits< IndexRandomAccessIterator >::pointer,
  30. typename std::iterator_traits<
  31. IndexRandomAccessIterator >::reference >
  32. {
  33. private:
  34. typedef component_index_iterator< IndexRandomAccessIterator > self;
  35. public:
  36. typedef std::forward_iterator_tag iterator_category;
  37. typedef typename std::iterator_traits<
  38. IndexRandomAccessIterator >::value_type value_type;
  39. typedef typename std::iterator_traits<
  40. IndexRandomAccessIterator >::difference_type reference;
  41. typedef
  42. typename std::iterator_traits< IndexRandomAccessIterator >::pointer
  43. pointer;
  44. typedef typename std::iterator_traits<
  45. IndexRandomAccessIterator >::reference difference_type;
  46. // Constructor for "begin" iterator
  47. component_index_iterator(
  48. IndexRandomAccessIterator index_iterator, value_type begin_index)
  49. : m_index_iterator(index_iterator), m_current_index(begin_index)
  50. {
  51. }
  52. // Constructor for "end" iterator (end_index should be the linked
  53. // list terminator).
  54. component_index_iterator(value_type end_index)
  55. : m_current_index(end_index)
  56. {
  57. }
  58. inline value_type operator*() const { return (m_current_index); }
  59. self& operator++()
  60. {
  61. // Move to the next element in the linked list
  62. m_current_index = m_index_iterator[m_current_index];
  63. return (*this);
  64. }
  65. bool operator==(const self& other_iterator) const
  66. {
  67. return (m_current_index == *other_iterator);
  68. }
  69. protected:
  70. IndexRandomAccessIterator m_index_iterator;
  71. value_type m_current_index;
  72. }; // class component_index_iterator
  73. } // namespace detail
  74. } // namespace detail
  75. #endif // BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP