reverse_graph.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. // (C) Copyright David Abrahams 2000.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef REVERSE_GRAPH_DWA092300_H_
  6. #define REVERSE_GRAPH_DWA092300_H_
  7. #include <boost/graph/adjacency_iterator.hpp>
  8. #include <boost/graph/properties.hpp>
  9. #include <boost/iterator/transform_iterator.hpp>
  10. #include <boost/tuple/tuple.hpp>
  11. #include <boost/type_traits.hpp>
  12. #include <boost/mpl/if.hpp>
  13. namespace boost
  14. {
  15. struct reverse_graph_tag
  16. {
  17. };
  18. namespace detail
  19. {
  20. template < typename EdgeDesc > class reverse_graph_edge_descriptor
  21. {
  22. public:
  23. EdgeDesc
  24. underlying_descx; // Odd name is because this needs to be public but
  25. // shouldn't be exposed to users anymore
  26. private:
  27. typedef EdgeDesc base_descriptor_type;
  28. public:
  29. explicit reverse_graph_edge_descriptor(
  30. const EdgeDesc& underlying_descx = EdgeDesc())
  31. : underlying_descx(underlying_descx)
  32. {
  33. }
  34. friend bool operator==(const reverse_graph_edge_descriptor& a,
  35. const reverse_graph_edge_descriptor& b)
  36. {
  37. return a.underlying_descx == b.underlying_descx;
  38. }
  39. friend bool operator!=(const reverse_graph_edge_descriptor& a,
  40. const reverse_graph_edge_descriptor& b)
  41. {
  42. return a.underlying_descx != b.underlying_descx;
  43. }
  44. friend bool operator<(const reverse_graph_edge_descriptor& a,
  45. const reverse_graph_edge_descriptor& b)
  46. {
  47. return a.underlying_descx < b.underlying_descx;
  48. }
  49. friend bool operator>(const reverse_graph_edge_descriptor& a,
  50. const reverse_graph_edge_descriptor& b)
  51. {
  52. return a.underlying_descx > b.underlying_descx;
  53. }
  54. friend bool operator<=(const reverse_graph_edge_descriptor& a,
  55. const reverse_graph_edge_descriptor& b)
  56. {
  57. return a.underlying_descx <= b.underlying_descx;
  58. }
  59. friend bool operator>=(const reverse_graph_edge_descriptor& a,
  60. const reverse_graph_edge_descriptor& b)
  61. {
  62. return a.underlying_descx >= b.underlying_descx;
  63. }
  64. };
  65. template < typename EdgeDesc > struct reverse_graph_edge_descriptor_maker
  66. {
  67. typedef reverse_graph_edge_descriptor< EdgeDesc > result_type;
  68. reverse_graph_edge_descriptor< EdgeDesc > operator()(
  69. const EdgeDesc& ed) const
  70. {
  71. return reverse_graph_edge_descriptor< EdgeDesc >(ed);
  72. }
  73. };
  74. template < typename EdgeDesc, typename Iter >
  75. std::pair< transform_iterator<
  76. reverse_graph_edge_descriptor_maker< EdgeDesc >, Iter >,
  77. transform_iterator< reverse_graph_edge_descriptor_maker< EdgeDesc >,
  78. Iter > >
  79. reverse_edge_iter_pair(const std::pair< Iter, Iter >& ip)
  80. {
  81. return std::make_pair(
  82. make_transform_iterator(
  83. ip.first, reverse_graph_edge_descriptor_maker< EdgeDesc >()),
  84. make_transform_iterator(
  85. ip.second, reverse_graph_edge_descriptor_maker< EdgeDesc >()));
  86. }
  87. // Get the underlying descriptor from a vertex or edge descriptor
  88. template < typename Desc >
  89. struct get_underlying_descriptor_from_reverse_descriptor
  90. {
  91. typedef Desc type;
  92. static Desc convert(const Desc& d) { return d; }
  93. };
  94. template < typename Desc >
  95. struct get_underlying_descriptor_from_reverse_descriptor<
  96. reverse_graph_edge_descriptor< Desc > >
  97. {
  98. typedef Desc type;
  99. static Desc convert(const reverse_graph_edge_descriptor< Desc >& d)
  100. {
  101. return d.underlying_descx;
  102. }
  103. };
  104. template < bool isEdgeList > struct choose_rev_edge_iter
  105. {
  106. };
  107. template <> struct choose_rev_edge_iter< true >
  108. {
  109. template < class G > struct bind_
  110. {
  111. typedef transform_iterator<
  112. reverse_graph_edge_descriptor_maker<
  113. typename graph_traits< G >::edge_descriptor >,
  114. typename graph_traits< G >::edge_iterator >
  115. type;
  116. };
  117. };
  118. template <> struct choose_rev_edge_iter< false >
  119. {
  120. template < class G > struct bind_
  121. {
  122. typedef void type;
  123. };
  124. };
  125. } // namespace detail
  126. template < class BidirectionalGraph,
  127. class GraphRef = const BidirectionalGraph& >
  128. class reverse_graph
  129. {
  130. typedef reverse_graph< BidirectionalGraph, GraphRef > Self;
  131. typedef graph_traits< BidirectionalGraph > Traits;
  132. public:
  133. typedef BidirectionalGraph base_type;
  134. typedef GraphRef base_ref_type;
  135. // Constructor
  136. reverse_graph(GraphRef g) : m_g(g) {}
  137. // Conversion from reverse_graph on non-const reference to one on const
  138. // reference
  139. reverse_graph(
  140. const reverse_graph< BidirectionalGraph, BidirectionalGraph& >& o)
  141. : m_g(o.m_g)
  142. {
  143. }
  144. // Graph requirements
  145. typedef typename Traits::vertex_descriptor vertex_descriptor;
  146. typedef detail::reverse_graph_edge_descriptor<
  147. typename Traits::edge_descriptor >
  148. edge_descriptor;
  149. typedef typename Traits::directed_category directed_category;
  150. typedef typename Traits::edge_parallel_category edge_parallel_category;
  151. typedef typename Traits::traversal_category traversal_category;
  152. // IncidenceGraph requirements
  153. typedef transform_iterator< detail::reverse_graph_edge_descriptor_maker<
  154. typename Traits::edge_descriptor >,
  155. typename Traits::in_edge_iterator >
  156. out_edge_iterator;
  157. typedef typename Traits::degree_size_type degree_size_type;
  158. // BidirectionalGraph requirements
  159. typedef transform_iterator< detail::reverse_graph_edge_descriptor_maker<
  160. typename Traits::edge_descriptor >,
  161. typename Traits::out_edge_iterator >
  162. in_edge_iterator;
  163. // AdjacencyGraph requirements
  164. typedef typename adjacency_iterator_generator< Self, vertex_descriptor,
  165. out_edge_iterator >::type adjacency_iterator;
  166. // VertexListGraph requirements
  167. typedef typename Traits::vertex_iterator vertex_iterator;
  168. // EdgeListGraph requirements
  169. enum
  170. {
  171. is_edge_list
  172. = is_convertible< traversal_category, edge_list_graph_tag >::value
  173. };
  174. typedef detail::choose_rev_edge_iter< is_edge_list > ChooseEdgeIter;
  175. typedef typename ChooseEdgeIter::template bind_< BidirectionalGraph >::type
  176. edge_iterator;
  177. typedef typename Traits::vertices_size_type vertices_size_type;
  178. typedef typename Traits::edges_size_type edges_size_type;
  179. typedef reverse_graph_tag graph_tag;
  180. #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
  181. // Bundled properties support
  182. template < typename Descriptor >
  183. typename graph::detail::bundled_result< BidirectionalGraph,
  184. typename detail::get_underlying_descriptor_from_reverse_descriptor<
  185. Descriptor >::type >::type&
  186. operator[](Descriptor x)
  187. {
  188. return m_g[detail::get_underlying_descriptor_from_reverse_descriptor<
  189. Descriptor >::convert(x)];
  190. }
  191. template < typename Descriptor >
  192. typename graph::detail::bundled_result< BidirectionalGraph,
  193. typename detail::get_underlying_descriptor_from_reverse_descriptor<
  194. Descriptor >::type >::type const&
  195. operator[](Descriptor x) const
  196. {
  197. return m_g[detail::get_underlying_descriptor_from_reverse_descriptor<
  198. Descriptor >::convert(x)];
  199. }
  200. #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES
  201. static vertex_descriptor null_vertex() { return Traits::null_vertex(); }
  202. // would be private, but template friends aren't portable enough.
  203. // private:
  204. GraphRef m_g;
  205. };
  206. // These are separate so they are not instantiated unless used (see bug 1021)
  207. template < class BidirectionalGraph, class GraphRef >
  208. struct vertex_property_type< reverse_graph< BidirectionalGraph, GraphRef > >
  209. {
  210. typedef
  211. typename boost::vertex_property_type< BidirectionalGraph >::type type;
  212. };
  213. template < class BidirectionalGraph, class GraphRef >
  214. struct edge_property_type< reverse_graph< BidirectionalGraph, GraphRef > >
  215. {
  216. typedef typename boost::edge_property_type< BidirectionalGraph >::type type;
  217. };
  218. template < class BidirectionalGraph, class GraphRef >
  219. struct graph_property_type< reverse_graph< BidirectionalGraph, GraphRef > >
  220. {
  221. typedef
  222. typename boost::graph_property_type< BidirectionalGraph >::type type;
  223. };
  224. #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
  225. template < typename Graph, typename GraphRef >
  226. struct vertex_bundle_type< reverse_graph< Graph, GraphRef > >
  227. : vertex_bundle_type< Graph >
  228. {
  229. };
  230. template < typename Graph, typename GraphRef >
  231. struct edge_bundle_type< reverse_graph< Graph, GraphRef > >
  232. : edge_bundle_type< Graph >
  233. {
  234. };
  235. template < typename Graph, typename GraphRef >
  236. struct graph_bundle_type< reverse_graph< Graph, GraphRef > >
  237. : graph_bundle_type< Graph >
  238. {
  239. };
  240. #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES
  241. template < class BidirectionalGraph >
  242. inline reverse_graph< BidirectionalGraph > make_reverse_graph(
  243. const BidirectionalGraph& g)
  244. {
  245. return reverse_graph< BidirectionalGraph >(g);
  246. }
  247. template < class BidirectionalGraph >
  248. inline reverse_graph< BidirectionalGraph, BidirectionalGraph& >
  249. make_reverse_graph(BidirectionalGraph& g)
  250. {
  251. return reverse_graph< BidirectionalGraph, BidirectionalGraph& >(g);
  252. }
  253. template < class BidirectionalGraph, class GRef >
  254. std::pair< typename reverse_graph< BidirectionalGraph >::vertex_iterator,
  255. typename reverse_graph< BidirectionalGraph >::vertex_iterator >
  256. vertices(const reverse_graph< BidirectionalGraph, GRef >& g)
  257. {
  258. return vertices(g.m_g);
  259. }
  260. template < class BidirectionalGraph, class GRef >
  261. std::pair< typename reverse_graph< BidirectionalGraph >::edge_iterator,
  262. typename reverse_graph< BidirectionalGraph >::edge_iterator >
  263. edges(const reverse_graph< BidirectionalGraph, GRef >& g)
  264. {
  265. return detail::reverse_edge_iter_pair<
  266. typename graph_traits< BidirectionalGraph >::edge_descriptor >(
  267. edges(g.m_g));
  268. }
  269. template < class BidirectionalGraph, class GRef >
  270. inline std::pair<
  271. typename reverse_graph< BidirectionalGraph >::out_edge_iterator,
  272. typename reverse_graph< BidirectionalGraph >::out_edge_iterator >
  273. out_edges(
  274. const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  275. const reverse_graph< BidirectionalGraph, GRef >& g)
  276. {
  277. return detail::reverse_edge_iter_pair<
  278. typename graph_traits< BidirectionalGraph >::edge_descriptor >(
  279. in_edges(u, g.m_g));
  280. }
  281. template < class BidirectionalGraph, class GRef >
  282. inline typename graph_traits< BidirectionalGraph >::vertices_size_type
  283. num_vertices(const reverse_graph< BidirectionalGraph, GRef >& g)
  284. {
  285. return num_vertices(g.m_g);
  286. }
  287. template < class BidirectionalGraph, class GRef >
  288. inline typename reverse_graph< BidirectionalGraph >::edges_size_type num_edges(
  289. const reverse_graph< BidirectionalGraph, GRef >& g)
  290. {
  291. return num_edges(g.m_g);
  292. }
  293. template < class BidirectionalGraph, class GRef >
  294. inline typename graph_traits< BidirectionalGraph >::degree_size_type out_degree(
  295. const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  296. const reverse_graph< BidirectionalGraph, GRef >& g)
  297. {
  298. return in_degree(u, g.m_g);
  299. }
  300. template < class BidirectionalGraph, class GRef >
  301. inline typename graph_traits< BidirectionalGraph >::vertex_descriptor vertex(
  302. const typename graph_traits< BidirectionalGraph >::vertices_size_type v,
  303. const reverse_graph< BidirectionalGraph, GRef >& g)
  304. {
  305. return vertex(v, g.m_g);
  306. }
  307. template < class BidirectionalGraph, class GRef >
  308. inline std::pair< typename graph_traits< reverse_graph< BidirectionalGraph,
  309. GRef > >::edge_descriptor,
  310. bool >
  311. edge(const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  312. const typename graph_traits< BidirectionalGraph >::vertex_descriptor v,
  313. const reverse_graph< BidirectionalGraph, GRef >& g)
  314. {
  315. typedef typename graph_traits< BidirectionalGraph >::edge_descriptor
  316. underlying_edge_descriptor;
  317. std::pair< underlying_edge_descriptor, bool > e = edge(v, u, g.m_g);
  318. return std::make_pair(
  319. detail::reverse_graph_edge_descriptor< underlying_edge_descriptor >(
  320. e.first),
  321. e.second);
  322. }
  323. template < class BidirectionalGraph, class GRef >
  324. inline std::pair<
  325. typename reverse_graph< BidirectionalGraph >::in_edge_iterator,
  326. typename reverse_graph< BidirectionalGraph >::in_edge_iterator >
  327. in_edges(const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  328. const reverse_graph< BidirectionalGraph, GRef >& g)
  329. {
  330. return detail::reverse_edge_iter_pair<
  331. typename graph_traits< BidirectionalGraph >::edge_descriptor >(
  332. out_edges(u, g.m_g));
  333. }
  334. template < class BidirectionalGraph, class GRef >
  335. inline std::pair<
  336. typename reverse_graph< BidirectionalGraph, GRef >::adjacency_iterator,
  337. typename reverse_graph< BidirectionalGraph, GRef >::adjacency_iterator >
  338. adjacent_vertices(
  339. typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  340. const reverse_graph< BidirectionalGraph, GRef >& g)
  341. {
  342. typedef reverse_graph< BidirectionalGraph, GRef > Graph;
  343. typename graph_traits< Graph >::out_edge_iterator first, last;
  344. boost::tie(first, last) = out_edges(u, g);
  345. typedef
  346. typename graph_traits< Graph >::adjacency_iterator adjacency_iterator;
  347. return std::make_pair(adjacency_iterator(first, const_cast< Graph* >(&g)),
  348. adjacency_iterator(last, const_cast< Graph* >(&g)));
  349. }
  350. template < class BidirectionalGraph, class GRef >
  351. inline typename graph_traits< BidirectionalGraph >::degree_size_type in_degree(
  352. const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  353. const reverse_graph< BidirectionalGraph, GRef >& g)
  354. {
  355. return out_degree(u, g.m_g);
  356. }
  357. template < class Edge, class BidirectionalGraph, class GRef >
  358. inline typename graph_traits< BidirectionalGraph >::vertex_descriptor source(
  359. const detail::reverse_graph_edge_descriptor< Edge >& e,
  360. const reverse_graph< BidirectionalGraph, GRef >& g)
  361. {
  362. return target(e.underlying_descx, g.m_g);
  363. }
  364. template < class Edge, class BidirectionalGraph, class GRef >
  365. inline typename graph_traits< BidirectionalGraph >::vertex_descriptor target(
  366. const detail::reverse_graph_edge_descriptor< Edge >& e,
  367. const reverse_graph< BidirectionalGraph, GRef >& g)
  368. {
  369. return source(e.underlying_descx, g.m_g);
  370. }
  371. template < class BidirectionalGraph, class GRef >
  372. inline typename graph_traits< BidirectionalGraph >::degree_size_type degree(
  373. const typename graph_traits< BidirectionalGraph >::vertex_descriptor u,
  374. const reverse_graph< BidirectionalGraph, GRef >& g)
  375. {
  376. return degree(u, g.m_g);
  377. }
  378. namespace detail
  379. {
  380. template < typename PM > struct reverse_graph_edge_property_map
  381. {
  382. private:
  383. PM underlying_pm;
  384. public:
  385. typedef reverse_graph_edge_descriptor<
  386. typename property_traits< PM >::key_type >
  387. key_type;
  388. typedef typename property_traits< PM >::value_type value_type;
  389. typedef typename property_traits< PM >::reference reference;
  390. typedef typename property_traits< PM >::category category;
  391. explicit reverse_graph_edge_property_map(const PM& pm)
  392. : underlying_pm(pm)
  393. {
  394. }
  395. friend reference get(
  396. const reverse_graph_edge_property_map& m, const key_type& e)
  397. {
  398. return get(m.underlying_pm, e.underlying_descx);
  399. }
  400. friend void put(const reverse_graph_edge_property_map& m,
  401. const key_type& e, const value_type& v)
  402. {
  403. put(m.underlying_pm, e.underlying_descx, v);
  404. }
  405. reference operator[](const key_type& k) const
  406. {
  407. return (this->underlying_pm)[k.underlying_descx];
  408. }
  409. };
  410. } // namespace detail
  411. template < class BidirGraph, class GRef, class Property >
  412. struct property_map< reverse_graph< BidirGraph, GRef >, Property >
  413. {
  414. typedef boost::is_same<
  415. typename detail::property_kind_from_graph< BidirGraph, Property >::type,
  416. edge_property_tag >
  417. is_edge_prop;
  418. typedef boost::is_const< typename boost::remove_reference< GRef >::type >
  419. is_ref_const;
  420. typedef typename boost::mpl::if_< is_ref_const,
  421. typename property_map< BidirGraph, Property >::const_type,
  422. typename property_map< BidirGraph, Property >::type >::type orig_type;
  423. typedef typename property_map< BidirGraph, Property >::const_type
  424. orig_const_type;
  425. typedef typename boost::mpl::if_< is_edge_prop,
  426. detail::reverse_graph_edge_property_map< orig_type >, orig_type >::type
  427. type;
  428. typedef typename boost::mpl::if_< is_edge_prop,
  429. detail::reverse_graph_edge_property_map< orig_const_type >,
  430. orig_const_type >::type const_type;
  431. };
  432. template < class BidirGraph, class GRef, class Property >
  433. struct property_map< const reverse_graph< BidirGraph, GRef >, Property >
  434. {
  435. typedef boost::is_same<
  436. typename detail::property_kind_from_graph< BidirGraph, Property >::type,
  437. edge_property_tag >
  438. is_edge_prop;
  439. typedef typename property_map< BidirGraph, Property >::const_type
  440. orig_const_type;
  441. typedef typename boost::mpl::if_< is_edge_prop,
  442. detail::reverse_graph_edge_property_map< orig_const_type >,
  443. orig_const_type >::type const_type;
  444. typedef const_type type;
  445. };
  446. template < class BidirGraph, class GRef, class Property >
  447. typename disable_if< is_same< Property, edge_underlying_t >,
  448. typename property_map< reverse_graph< BidirGraph, GRef >,
  449. Property >::type >::type
  450. get(Property p, reverse_graph< BidirGraph, GRef >& g)
  451. {
  452. return typename property_map< reverse_graph< BidirGraph, GRef >,
  453. Property >::type(get(p, g.m_g));
  454. }
  455. template < class BidirGraph, class GRef, class Property >
  456. typename disable_if< is_same< Property, edge_underlying_t >,
  457. typename property_map< reverse_graph< BidirGraph, GRef >,
  458. Property >::const_type >::type
  459. get(Property p, const reverse_graph< BidirGraph, GRef >& g)
  460. {
  461. const BidirGraph& gref = g.m_g; // in case GRef is non-const
  462. return typename property_map< reverse_graph< BidirGraph, GRef >,
  463. Property >::const_type(get(p, gref));
  464. }
  465. template < class BidirectionalGraph, class GRef, class Property, class Key >
  466. typename disable_if< is_same< Property, edge_underlying_t >,
  467. typename property_traits<
  468. typename property_map< reverse_graph< BidirectionalGraph, GRef >,
  469. Property >::const_type >::value_type >::type
  470. get(Property p, const reverse_graph< BidirectionalGraph, GRef >& g,
  471. const Key& k)
  472. {
  473. return get(get(p, g), k);
  474. }
  475. template < class BidirectionalGraph, class GRef, class Property, class Key,
  476. class Value >
  477. void put(Property p, reverse_graph< BidirectionalGraph, GRef >& g, const Key& k,
  478. const Value& val)
  479. {
  480. put(get(p, g), k, val);
  481. }
  482. // Get the underlying descriptor from a reverse_graph's wrapped edge descriptor
  483. namespace detail
  484. {
  485. template < class E > struct underlying_edge_desc_map_type
  486. {
  487. E operator[](const reverse_graph_edge_descriptor< E >& k) const
  488. {
  489. return k.underlying_descx;
  490. }
  491. };
  492. template < class E >
  493. E get(underlying_edge_desc_map_type< E > m,
  494. const reverse_graph_edge_descriptor< E >& k)
  495. {
  496. return m[k];
  497. }
  498. }
  499. template < class E >
  500. struct property_traits< detail::underlying_edge_desc_map_type< E > >
  501. {
  502. typedef detail::reverse_graph_edge_descriptor< E > key_type;
  503. typedef E value_type;
  504. typedef const E& reference;
  505. typedef readable_property_map_tag category;
  506. };
  507. template < class Graph, class GRef >
  508. struct property_map< reverse_graph< Graph, GRef >, edge_underlying_t >
  509. {
  510. private:
  511. typedef typename graph_traits< Graph >::edge_descriptor ed;
  512. public:
  513. typedef detail::underlying_edge_desc_map_type< ed > type;
  514. typedef detail::underlying_edge_desc_map_type< ed > const_type;
  515. };
  516. template < typename T > struct is_reverse_graph : boost::mpl::false_
  517. {
  518. };
  519. template < typename G, typename R >
  520. struct is_reverse_graph< reverse_graph< G, R > > : boost::mpl::true_
  521. {
  522. };
  523. template < class G >
  524. typename enable_if< is_reverse_graph< G >,
  525. detail::underlying_edge_desc_map_type< typename graph_traits<
  526. typename G::base_type >::edge_descriptor > >::type
  527. get(edge_underlying_t, G&)
  528. {
  529. return detail::underlying_edge_desc_map_type<
  530. typename graph_traits< typename G::base_type >::edge_descriptor >();
  531. }
  532. template < class G >
  533. typename enable_if< is_reverse_graph< G >,
  534. typename graph_traits< typename G::base_type >::edge_descriptor >::type
  535. get(edge_underlying_t, G&, const typename graph_traits< G >::edge_descriptor& k)
  536. {
  537. return k.underlying_descx;
  538. }
  539. template < class G >
  540. typename enable_if< is_reverse_graph< G >,
  541. detail::underlying_edge_desc_map_type< typename graph_traits<
  542. typename G::base_type >::edge_descriptor > >::type
  543. get(edge_underlying_t, const G&)
  544. {
  545. return detail::underlying_edge_desc_map_type<
  546. typename graph_traits< typename G::base_type >::edge_descriptor >();
  547. }
  548. template < class G >
  549. typename enable_if< is_reverse_graph< G >,
  550. typename graph_traits< typename G::base_type >::edge_descriptor >::type
  551. get(edge_underlying_t, const G&,
  552. const typename graph_traits< G >::edge_descriptor& k)
  553. {
  554. return k.underlying_descx;
  555. }
  556. // Access to wrapped graph's graph properties
  557. template < typename BidirectionalGraph, typename GRef, typename Tag,
  558. typename Value >
  559. inline void set_property(const reverse_graph< BidirectionalGraph, GRef >& g,
  560. Tag tag, const Value& value)
  561. {
  562. set_property(g.m_g, tag, value);
  563. }
  564. template < typename BidirectionalGraph, typename GRef, typename Tag >
  565. inline typename boost::mpl::if_<
  566. boost::is_const< typename boost::remove_reference< GRef >::type >,
  567. const typename graph_property< BidirectionalGraph, Tag >::type&,
  568. typename graph_property< BidirectionalGraph, Tag >::type& >::type
  569. get_property(const reverse_graph< BidirectionalGraph, GRef >& g, Tag tag)
  570. {
  571. return get_property(g.m_g, tag);
  572. }
  573. } // namespace boost
  574. #endif