adjacency_iterator.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //=======================================================================
  2. // Copyright 2002 Indiana University.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #ifndef BOOST_ADJACENCY_ITERATOR_HPP
  10. #define BOOST_ADJACENCY_ITERATOR_HPP
  11. #include <boost/iterator/iterator_adaptor.hpp>
  12. #include <boost/graph/graph_traits.hpp>
  13. namespace boost
  14. {
  15. template <class Graph, class Vertex, class OutEdgeIter, class Difference>
  16. struct adjacency_iterator
  17. : iterator_adaptor<
  18. adjacency_iterator<Graph,Vertex,OutEdgeIter,Difference>
  19. , OutEdgeIter
  20. , Vertex
  21. , use_default
  22. , Vertex
  23. , Difference
  24. >
  25. {
  26. typedef iterator_adaptor<
  27. adjacency_iterator<Graph,Vertex,OutEdgeIter,Difference>
  28. , OutEdgeIter
  29. , Vertex
  30. , use_default
  31. , Vertex
  32. , Difference
  33. > super_t;
  34. inline adjacency_iterator() {}
  35. inline adjacency_iterator(OutEdgeIter const& i, const Graph* g) : super_t(i), m_g(g) { }
  36. inline Vertex
  37. dereference() const
  38. { return target(*this->base(), *m_g); }
  39. const Graph* m_g;
  40. };
  41. template <class Graph,
  42. class Vertex = typename graph_traits<Graph>::vertex_descriptor,
  43. class OutEdgeIter=typename graph_traits<Graph>::out_edge_iterator>
  44. class adjacency_iterator_generator
  45. {
  46. typedef typename boost::detail::iterator_traits<OutEdgeIter>
  47. ::difference_type difference_type;
  48. public:
  49. typedef adjacency_iterator<Graph,Vertex,OutEdgeIter,difference_type> type;
  50. };
  51. template <class Graph, class Vertex, class InEdgeIter, class Difference>
  52. struct inv_adjacency_iterator
  53. : iterator_adaptor<
  54. inv_adjacency_iterator<Graph,Vertex,InEdgeIter,Difference>
  55. , InEdgeIter
  56. , Vertex
  57. , use_default
  58. , Vertex
  59. , Difference
  60. >
  61. {
  62. typedef iterator_adaptor<
  63. inv_adjacency_iterator<Graph,Vertex,InEdgeIter,Difference>
  64. , InEdgeIter
  65. , Vertex
  66. , use_default
  67. , Vertex
  68. , Difference
  69. > super_t;
  70. inline inv_adjacency_iterator() { }
  71. inline inv_adjacency_iterator(InEdgeIter const& i, const Graph* g) : super_t(i), m_g(g) { }
  72. inline Vertex
  73. dereference() const
  74. { return source(*this->base(), *m_g); }
  75. const Graph* m_g;
  76. };
  77. template <class Graph,
  78. class Vertex = typename graph_traits<Graph>::vertex_descriptor,
  79. class InEdgeIter = typename graph_traits<Graph>::in_edge_iterator>
  80. class inv_adjacency_iterator_generator {
  81. typedef typename boost::detail::iterator_traits<InEdgeIter>
  82. ::difference_type difference_type;
  83. public:
  84. typedef inv_adjacency_iterator<Graph, Vertex, InEdgeIter, difference_type> type;
  85. };
  86. } // namespace boost
  87. #endif // BOOST_DETAIL_ADJACENCY_ITERATOR_HPP