File: incremental_components.hpp

package info (click to toggle)
boost1.62 1.62.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 686,420 kB
  • sloc: cpp: 2,609,004; xml: 972,558; ansic: 53,674; python: 32,437; sh: 8,829; asm: 3,071; cs: 2,121; makefile: 964; perl: 859; yacc: 472; php: 132; ruby: 94; f90: 55; sql: 13; csh: 6
file content (77 lines) | stat: -rw-r--r-- 3,104 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//=======================================================================
// Copyright 2002 Indiana University.
// Copyright 2009 Trustees of Indiana University.
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Michael Hansen
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#ifndef BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP
#define BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP

#include <boost/operators.hpp>

namespace boost {

  namespace detail {

    // Iterator for a component index linked list.  The contents of
    // each array element represent the next index in the list.  A
    // special value (the maximum index + 1) is used to terminate a
    // list.
    template <typename IndexRandomAccessIterator> 
    class component_index_iterator :
      boost::forward_iterator_helper<component_index_iterator<IndexRandomAccessIterator>,
                                     typename std::iterator_traits<IndexRandomAccessIterator>::value_type,
                                     typename std::iterator_traits<IndexRandomAccessIterator>::difference_type,
                                     typename std::iterator_traits<IndexRandomAccessIterator>::pointer,
                                     typename std::iterator_traits<IndexRandomAccessIterator>::reference> {

    private:
      typedef component_index_iterator<IndexRandomAccessIterator> self;

    public:
      typedef std::forward_iterator_tag iterator_category;
      typedef typename std::iterator_traits<IndexRandomAccessIterator>::value_type value_type;
      typedef typename std::iterator_traits<IndexRandomAccessIterator>::difference_type reference;
      typedef typename std::iterator_traits<IndexRandomAccessIterator>::pointer pointer;
      typedef typename std::iterator_traits<IndexRandomAccessIterator>::reference difference_type;

      // Constructor for "begin" iterator
      component_index_iterator(IndexRandomAccessIterator index_iterator,
                               value_type begin_index) :
        m_index_iterator(index_iterator),
        m_current_index(begin_index) { }

      // Constructor for "end" iterator (end_index should be the linked
      // list terminator).
      component_index_iterator(value_type end_index) :
        m_current_index(end_index) { }

      inline value_type operator*() const {
        return (m_current_index);
      }
    
      self& operator++() {
        // Move to the next element in the linked list
        m_current_index = m_index_iterator[m_current_index];
        return (*this);
      }

      bool operator==(const self& other_iterator) const {
        return (m_current_index == *other_iterator);
      }

    protected:
      IndexRandomAccessIterator m_index_iterator;
      value_type m_current_index;

    }; // class component_index_iterator

  } // namespace detail
  
} // namespace detail

#endif // BOOST_GRAPH_DETAIL_INCREMENTAL_COMPONENTS_HPP