Chris@16
|
1 //
|
Chris@16
|
2 //=======================================================================
|
Chris@16
|
3 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
|
Chris@16
|
4 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
Chris@16
|
5 //
|
Chris@16
|
6 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
7 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //=======================================================================
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_GRAPH_DETAIL_EDGE_HPP
|
Chris@16
|
12 #define BOOST_GRAPH_DETAIL_EDGE_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <iosfwd>
|
Chris@16
|
15
|
Chris@16
|
16 namespace boost {
|
Chris@16
|
17
|
Chris@16
|
18 namespace detail {
|
Chris@16
|
19
|
Chris@16
|
20 template <typename Directed, typename Vertex>
|
Chris@16
|
21 struct edge_base
|
Chris@16
|
22 {
|
Chris@16
|
23 inline edge_base() {}
|
Chris@16
|
24 inline edge_base(Vertex s, Vertex d)
|
Chris@16
|
25 : m_source(s), m_target(d) { }
|
Chris@16
|
26 Vertex m_source;
|
Chris@16
|
27 Vertex m_target;
|
Chris@16
|
28 };
|
Chris@16
|
29
|
Chris@16
|
30 template <typename Directed, typename Vertex>
|
Chris@16
|
31 class edge_desc_impl : public edge_base<Directed,Vertex> {
|
Chris@16
|
32 typedef edge_desc_impl self;
|
Chris@16
|
33 typedef edge_base<Directed,Vertex> Base;
|
Chris@16
|
34 public:
|
Chris@16
|
35 typedef void property_type;
|
Chris@16
|
36
|
Chris@16
|
37 inline edge_desc_impl() : m_eproperty(0) {}
|
Chris@16
|
38
|
Chris@16
|
39 inline edge_desc_impl(Vertex s, Vertex d, const property_type* eplug)
|
Chris@16
|
40 : Base(s,d), m_eproperty(const_cast<property_type*>(eplug)) { }
|
Chris@16
|
41
|
Chris@16
|
42 property_type* get_property() { return m_eproperty; }
|
Chris@16
|
43 const property_type* get_property() const { return m_eproperty; }
|
Chris@16
|
44
|
Chris@16
|
45 // protected:
|
Chris@16
|
46 property_type* m_eproperty;
|
Chris@16
|
47 };
|
Chris@16
|
48
|
Chris@16
|
49 template <class D, class V>
|
Chris@16
|
50 inline bool
|
Chris@16
|
51 operator==(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
52 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
53 {
|
Chris@16
|
54 return a.get_property() == b.get_property();
|
Chris@16
|
55 }
|
Chris@16
|
56 template <class D, class V>
|
Chris@16
|
57 inline bool
|
Chris@16
|
58 operator!=(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
59 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
60 {
|
Chris@16
|
61 return ! (a.get_property() == b.get_property());
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 // Order edges according to the address of their property object
|
Chris@16
|
65 template <class D, class V>
|
Chris@16
|
66 inline bool
|
Chris@16
|
67 operator<(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
68 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
69 {
|
Chris@16
|
70 return a.get_property() < b.get_property();
|
Chris@16
|
71 }
|
Chris@16
|
72 template <class D, class V>
|
Chris@16
|
73 inline bool
|
Chris@16
|
74 operator<=(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
75 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
76 {
|
Chris@16
|
77 return a.get_property() <= b.get_property();
|
Chris@16
|
78 }
|
Chris@16
|
79 template <class D, class V>
|
Chris@16
|
80 inline bool
|
Chris@16
|
81 operator>(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
82 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
83 {
|
Chris@16
|
84 return a.get_property() > b.get_property();
|
Chris@16
|
85 }
|
Chris@16
|
86 template <class D, class V>
|
Chris@16
|
87 inline bool
|
Chris@16
|
88 operator>=(const detail::edge_desc_impl<D,V>& a,
|
Chris@16
|
89 const detail::edge_desc_impl<D,V>& b)
|
Chris@16
|
90 {
|
Chris@16
|
91 return a.get_property() >= b.get_property();
|
Chris@16
|
92 }
|
Chris@16
|
93
|
Chris@16
|
94 } //namespace detail
|
Chris@16
|
95
|
Chris@16
|
96 } // namespace boost
|
Chris@16
|
97
|
Chris@16
|
98 namespace std {
|
Chris@16
|
99 template <class Char, class Traits, class D, class V>
|
Chris@16
|
100 std::basic_ostream<Char, Traits>&
|
Chris@16
|
101 operator<<(std::basic_ostream<Char, Traits>& os,
|
Chris@16
|
102 const boost::detail::edge_desc_impl<D,V>& e)
|
Chris@16
|
103 {
|
Chris@16
|
104 return os << "(" << e.m_source << "," << e.m_target << ")";
|
Chris@16
|
105 }
|
Chris@16
|
106 }
|
Chris@16
|
107
|
Chris@101
|
108 // Boost's functional/hash
|
Chris@101
|
109 namespace boost {
|
Chris@101
|
110 template<typename D, typename V>
|
Chris@101
|
111 struct hash<boost::detail::edge_desc_impl<D, V> >
|
Chris@101
|
112 {
|
Chris@101
|
113 std::size_t operator()(const boost::detail::edge_desc_impl<D, V> & x) const
|
Chris@101
|
114 { return hash_value(x.get_property()); }
|
Chris@101
|
115 };
|
Chris@101
|
116 }
|
Chris@101
|
117
|
Chris@16
|
118
|
Chris@16
|
119 #endif // BOOST_GRAPH_DETAIL_DETAIL_EDGE_HPP
|