incremental_components.hpp 3.0 KB

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