incidence_iterator.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. //=======================================================================
  3. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  4. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  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. //
  11. #ifndef BOOST_GRAPH_DETAIL_INCIDENCE_ITERATOR_HPP
  12. #define BOOST_GRAPH_DETAIL_INCIDENCE_ITERATOR_HPP
  13. #include <utility>
  14. #include <iterator>
  15. // OBSOLETE
  16. namespace boost
  17. {
  18. namespace detail
  19. {
  20. // EdgeDir tags
  21. struct in_edge_tag
  22. {
  23. };
  24. struct out_edge_tag
  25. {
  26. };
  27. template < class Vertex, class Edge, class Iterator1D, class EdgeDir >
  28. struct bidir_incidence_iterator
  29. {
  30. typedef bidir_incidence_iterator self;
  31. typedef Edge edge_type;
  32. typedef typename Edge::property_type EdgeProperty;
  33. public:
  34. typedef int difference_type;
  35. typedef std::forward_iterator_tag iterator_category;
  36. typedef edge_type reference;
  37. typedef edge_type value_type;
  38. typedef value_type* pointer;
  39. inline bidir_incidence_iterator() {}
  40. inline bidir_incidence_iterator(Iterator1D ii, Vertex src)
  41. : i(ii), _src(src)
  42. {
  43. }
  44. inline self& operator++()
  45. {
  46. ++i;
  47. return *this;
  48. }
  49. inline self operator++(int)
  50. {
  51. self tmp = *this;
  52. ++(*this);
  53. return tmp;
  54. }
  55. inline reference operator*() const { return deref_helper(EdgeDir()); }
  56. inline self* operator->() { return this; }
  57. Iterator1D& iter() { return i; }
  58. const Iterator1D& iter() const { return i; }
  59. Iterator1D i;
  60. Vertex _src;
  61. protected:
  62. inline reference deref_helper(out_edge_tag) const
  63. {
  64. return edge_type(_src, (*i).get_target(), &(*i).get_property());
  65. }
  66. inline reference deref_helper(in_edge_tag) const
  67. {
  68. return edge_type((*i).get_target(), _src, &(*i).get_property());
  69. }
  70. };
  71. template < class V, class E, class Iter, class Dir >
  72. inline bool operator==(const bidir_incidence_iterator< V, E, Iter, Dir >& x,
  73. const bidir_incidence_iterator< V, E, Iter, Dir >& y)
  74. {
  75. return x.i == y.i;
  76. }
  77. template < class V, class E, class Iter, class Dir >
  78. inline bool operator!=(const bidir_incidence_iterator< V, E, Iter, Dir >& x,
  79. const bidir_incidence_iterator< V, E, Iter, Dir >& y)
  80. {
  81. return x.i != y.i;
  82. }
  83. }
  84. }
  85. #endif