edge.hpp 3.5 KB

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