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