incidence_iterator.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. namespace detail {
  18. // EdgeDir tags
  19. struct in_edge_tag { };
  20. struct out_edge_tag { };
  21. template <class Vertex, class Edge, class Iterator1D, class EdgeDir>
  22. struct bidir_incidence_iterator {
  23. typedef bidir_incidence_iterator self;
  24. typedef Edge edge_type;
  25. typedef typename Edge::property_type EdgeProperty;
  26. public:
  27. typedef int difference_type;
  28. typedef std::forward_iterator_tag iterator_category;
  29. typedef edge_type reference;
  30. typedef edge_type value_type;
  31. typedef value_type* pointer;
  32. inline bidir_incidence_iterator() {}
  33. inline bidir_incidence_iterator(Iterator1D ii, Vertex src)
  34. : i(ii), _src(src) { }
  35. inline self& operator++() { ++i; return *this; }
  36. inline self operator++(int) { self tmp = *this; ++(*this); return tmp; }
  37. inline reference operator*() const {
  38. return deref_helper(EdgeDir());
  39. }
  40. inline self* operator->() { return this; }
  41. Iterator1D& iter() { return i; }
  42. const Iterator1D& iter() const { return i; }
  43. Iterator1D i;
  44. Vertex _src;
  45. protected:
  46. inline reference deref_helper(out_edge_tag) const {
  47. return edge_type( _src, (*i).get_target(), &(*i).get_property() );
  48. }
  49. inline reference deref_helper(in_edge_tag) const {
  50. return edge_type((*i).get_target(), _src, &(*i).get_property() );
  51. }
  52. };
  53. template <class V, class E, class Iter, class Dir>
  54. inline bool operator==(const bidir_incidence_iterator<V,E,Iter,Dir>& x,
  55. const bidir_incidence_iterator<V,E,Iter,Dir>& y)
  56. {
  57. return x.i == y.i;
  58. }
  59. template <class V, class E, class Iter, class Dir>
  60. inline bool operator!=(const bidir_incidence_iterator<V,E,Iter,Dir>& x,
  61. const bidir_incidence_iterator<V,E,Iter,Dir>& y)
  62. {
  63. return x.i != y.i;
  64. }
  65. }
  66. }
  67. #endif