edge.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifndef BOOST_GRAPH_DETAIL_EDGE_HPP
  11. #define BOOST_GRAPH_DETAIL_EDGE_HPP
  12. #include <iosfwd>
  13. #include <boost/functional/hash.hpp>
  14. namespace boost {
  15. namespace detail {
  16. template <typename Directed, typename Vertex>
  17. struct edge_base
  18. {
  19. inline edge_base() {}
  20. inline edge_base(Vertex s, Vertex d)
  21. : m_source(s), m_target(d) { }
  22. Vertex m_source;
  23. Vertex m_target;
  24. };
  25. template <typename Directed, typename Vertex>
  26. class edge_desc_impl : public edge_base<Directed,Vertex> {
  27. typedef edge_desc_impl self;
  28. typedef edge_base<Directed,Vertex> Base;
  29. public:
  30. typedef void property_type;
  31. inline edge_desc_impl() : m_eproperty(0) {}
  32. inline edge_desc_impl(Vertex s, Vertex d, const property_type* eplug)
  33. : Base(s,d), m_eproperty(const_cast<property_type*>(eplug)) { }
  34. property_type* get_property() { return m_eproperty; }
  35. const property_type* get_property() const { return m_eproperty; }
  36. // protected:
  37. property_type* m_eproperty;
  38. };
  39. template <class D, class V>
  40. inline bool
  41. operator==(const detail::edge_desc_impl<D,V>& a,
  42. const detail::edge_desc_impl<D,V>& b)
  43. {
  44. return a.get_property() == b.get_property();
  45. }
  46. template <class D, class V>
  47. inline bool
  48. operator!=(const detail::edge_desc_impl<D,V>& a,
  49. const detail::edge_desc_impl<D,V>& b)
  50. {
  51. return ! (a.get_property() == b.get_property());
  52. }
  53. // Order edges according to the address of their property object
  54. template <class D, class V>
  55. inline bool
  56. operator<(const detail::edge_desc_impl<D,V>& a,
  57. const detail::edge_desc_impl<D,V>& b)
  58. {
  59. return a.get_property() < b.get_property();
  60. }
  61. template <class D, class V>
  62. inline bool
  63. operator<=(const detail::edge_desc_impl<D,V>& a,
  64. const detail::edge_desc_impl<D,V>& b)
  65. {
  66. return a.get_property() <= b.get_property();
  67. }
  68. template <class D, class V>
  69. inline bool
  70. operator>(const detail::edge_desc_impl<D,V>& a,
  71. const detail::edge_desc_impl<D,V>& b)
  72. {
  73. return a.get_property() > b.get_property();
  74. }
  75. template <class D, class V>
  76. inline bool
  77. operator>=(const detail::edge_desc_impl<D,V>& a,
  78. const detail::edge_desc_impl<D,V>& b)
  79. {
  80. return a.get_property() >= b.get_property();
  81. }
  82. } //namespace detail
  83. } // namespace boost
  84. namespace std {
  85. template <class Char, class Traits, class D, class V>
  86. std::basic_ostream<Char, Traits>&
  87. operator<<(std::basic_ostream<Char, Traits>& os,
  88. const boost::detail::edge_desc_impl<D,V>& e)
  89. {
  90. return os << "(" << e.m_source << "," << e.m_target << ")";
  91. }
  92. }
  93. // Boost's functional/hash
  94. namespace boost {
  95. template<typename D, typename V>
  96. struct hash<boost::detail::edge_desc_impl<D, V> >
  97. {
  98. std::size_t operator()(const boost::detail::edge_desc_impl<D, V> & x) const
  99. { return hash_value(x.get_property()); }
  100. };
  101. }
  102. #endif // BOOST_GRAPH_DETAIL_DETAIL_EDGE_HPP