edge.hpp 3.5 KB

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