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