adjacency_iterator.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <iterator>
  12. #include <boost/iterator/iterator_adaptor.hpp>
  13. #include <boost/graph/graph_traits.hpp>
  14. namespace boost
  15. {
  16. template < class Graph, class Vertex, class OutEdgeIter, class Difference >
  17. struct adjacency_iterator
  18. : iterator_adaptor<
  19. adjacency_iterator< Graph, Vertex, OutEdgeIter, Difference >, OutEdgeIter,
  20. Vertex, use_default, Vertex, Difference >
  21. {
  22. typedef iterator_adaptor<
  23. adjacency_iterator< Graph, Vertex, OutEdgeIter, Difference >,
  24. OutEdgeIter, Vertex, use_default, Vertex, Difference >
  25. super_t;
  26. inline adjacency_iterator() {}
  27. inline adjacency_iterator(OutEdgeIter const& i, const Graph* g)
  28. : super_t(i), m_g(g)
  29. {
  30. }
  31. inline Vertex dereference() const { return target(*this->base(), *m_g); }
  32. const Graph* m_g;
  33. };
  34. template < class Graph,
  35. class Vertex = typename graph_traits< Graph >::vertex_descriptor,
  36. class OutEdgeIter = typename graph_traits< Graph >::out_edge_iterator >
  37. class adjacency_iterator_generator
  38. {
  39. typedef
  40. typename std::iterator_traits< OutEdgeIter >::difference_type
  41. difference_type;
  42. public:
  43. typedef adjacency_iterator< Graph, Vertex, OutEdgeIter, difference_type >
  44. type;
  45. };
  46. template < class Graph, class Vertex, class InEdgeIter, class Difference >
  47. struct inv_adjacency_iterator
  48. : iterator_adaptor<
  49. inv_adjacency_iterator< Graph, Vertex, InEdgeIter, Difference >,
  50. InEdgeIter, Vertex, use_default, Vertex, Difference >
  51. {
  52. typedef iterator_adaptor<
  53. inv_adjacency_iterator< Graph, Vertex, InEdgeIter, Difference >,
  54. InEdgeIter, Vertex, use_default, Vertex, Difference >
  55. super_t;
  56. inline inv_adjacency_iterator() {}
  57. inline inv_adjacency_iterator(InEdgeIter const& i, const Graph* g)
  58. : super_t(i), m_g(g)
  59. {
  60. }
  61. inline Vertex dereference() const { return source(*this->base(), *m_g); }
  62. const Graph* m_g;
  63. };
  64. template < class Graph,
  65. class Vertex = typename graph_traits< Graph >::vertex_descriptor,
  66. class InEdgeIter = typename graph_traits< Graph >::in_edge_iterator >
  67. class inv_adjacency_iterator_generator
  68. {
  69. typedef
  70. typename std::iterator_traits< InEdgeIter >::difference_type
  71. difference_type;
  72. public:
  73. typedef inv_adjacency_iterator< Graph, Vertex, InEdgeIter, difference_type >
  74. type;
  75. };
  76. } // namespace boost
  77. #endif // BOOST_DETAIL_ADJACENCY_ITERATOR_HPP