Chris@16
|
1 //=======================================================================
|
Chris@16
|
2 // Copyright 2009 Trustees of Indiana University
|
Chris@16
|
3 // Author: Jeremiah Willcock
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //=======================================================================
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_GRAPH_LOOKUP_EDGE_HPP
|
Chris@16
|
11 #define BOOST_GRAPH_LOOKUP_EDGE_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include <utility>
|
Chris@16
|
14 #include <boost/config.hpp>
|
Chris@16
|
15 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
16 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 // lookup_edge: a function that acts like edge() but falls back to out_edges()
|
Chris@16
|
19 // and a search when edge() is not provided.
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost {
|
Chris@16
|
22
|
Chris@16
|
23 template <typename Graph>
|
Chris@16
|
24 std::pair<typename boost::graph_traits<Graph>::edge_descriptor, bool>
|
Chris@16
|
25 lookup_edge(typename boost::graph_traits<Graph>::vertex_descriptor src,
|
Chris@16
|
26 typename boost::graph_traits<Graph>::vertex_descriptor tgt,
|
Chris@16
|
27 const Graph& g,
|
Chris@16
|
28 typename boost::enable_if<is_adjacency_matrix<Graph>, int>::type = 0) {
|
Chris@16
|
29 return edge(src, tgt, g);
|
Chris@16
|
30 }
|
Chris@16
|
31
|
Chris@16
|
32 template <typename Graph>
|
Chris@16
|
33 std::pair<typename boost::graph_traits<Graph>::edge_descriptor, bool>
|
Chris@16
|
34 lookup_edge(typename boost::graph_traits<Graph>::vertex_descriptor src,
|
Chris@16
|
35 typename boost::graph_traits<Graph>::vertex_descriptor tgt,
|
Chris@16
|
36 const Graph& g,
|
Chris@16
|
37 typename boost::disable_if<is_adjacency_matrix<Graph>, int>::type = 0) {
|
Chris@16
|
38 typedef typename boost::graph_traits<Graph>::out_edge_iterator it;
|
Chris@16
|
39 typedef typename boost::graph_traits<Graph>::edge_descriptor edesc;
|
Chris@16
|
40 std::pair<it, it> oe = out_edges(src, g);
|
Chris@16
|
41 for (; oe.first != oe.second; ++oe.first) {
|
Chris@16
|
42 edesc e = *oe.first;
|
Chris@16
|
43 if (target(e, g) == tgt) return std::make_pair(e, true);
|
Chris@16
|
44 }
|
Chris@16
|
45 return std::make_pair(edesc(), false);
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 }
|
Chris@16
|
49
|
Chris@16
|
50 #endif // BOOST_GRAPH_LOOKUP_EDGE_HPP
|