directed_graph.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // (C) Copyright 2007-2009 Andrew Sutton
  2. //
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0 (See accompanying file
  5. // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GRAPH_DIRECTED_GRAPH_HPP
  7. #define BOOST_GRAPH_DIRECTED_GRAPH_HPP
  8. #include <boost/graph/adjacency_list.hpp>
  9. #include <boost/graph/properties.hpp>
  10. #include <boost/pending/property.hpp>
  11. #include <boost/property_map/transform_value_property_map.hpp>
  12. #include <boost/type_traits.hpp>
  13. #include <boost/mpl/if.hpp>
  14. namespace boost
  15. {
  16. struct directed_graph_tag { };
  17. /**
  18. * The directed_graph class template is a simplified version of the BGL
  19. * adjacency list. This class is provided for ease of use, but may not
  20. * perform as well as custom-defined adjacency list classes. Instances of
  21. * this template model the BidirectionalGraph, VertexIndexGraph, and
  22. * EdgeIndexGraph concepts. The graph is also fully mutable, supporting
  23. * both insertions and removals of vertices and edges.
  24. *
  25. * @note Special care must be taken when removing vertices or edges since
  26. * those operations can invalidate the numbering of vertices.
  27. */
  28. template <
  29. typename VertexProp = no_property,
  30. typename EdgeProp = no_property,
  31. typename GraphProp = no_property>
  32. class directed_graph
  33. {
  34. public:
  35. typedef GraphProp graph_property_type;
  36. typedef VertexProp vertex_property_type;
  37. typedef EdgeProp edge_property_type;
  38. typedef typename lookup_one_property<GraphProp, graph_bundle_t>::type graph_bundled;
  39. typedef typename lookup_one_property<VertexProp, vertex_bundle_t>::type vertex_bundled;
  40. typedef typename lookup_one_property<EdgeProp, edge_bundle_t>::type edge_bundled;
  41. public:
  42. // Embed indices into the vertex type.
  43. typedef property<vertex_index_t, unsigned, vertex_property_type> internal_vertex_property;
  44. typedef property<edge_index_t, unsigned, edge_property_type> internal_edge_property;
  45. public:
  46. typedef adjacency_list<
  47. listS, listS, bidirectionalS,
  48. internal_vertex_property, internal_edge_property, GraphProp,
  49. listS
  50. > graph_type;
  51. private:
  52. // storage selectors
  53. typedef typename graph_type::vertex_list_selector vertex_list_selector;
  54. typedef typename graph_type::edge_list_selector edge_list_selector;
  55. typedef typename graph_type::out_edge_list_selector out_edge_list_selector;
  56. typedef typename graph_type::directed_selector directed_selector;
  57. public:
  58. // more commonly used graph types
  59. typedef typename graph_type::stored_vertex stored_vertex;
  60. typedef typename graph_type::vertices_size_type vertices_size_type;
  61. typedef typename graph_type::edges_size_type edges_size_type;
  62. typedef typename graph_type::degree_size_type degree_size_type;
  63. typedef typename graph_type::vertex_descriptor vertex_descriptor;
  64. typedef typename graph_type::edge_descriptor edge_descriptor;
  65. // iterator types
  66. typedef typename graph_type::vertex_iterator vertex_iterator;
  67. typedef typename graph_type::edge_iterator edge_iterator;
  68. typedef typename graph_type::out_edge_iterator out_edge_iterator;
  69. typedef typename graph_type::in_edge_iterator in_edge_iterator;
  70. typedef typename graph_type::adjacency_iterator adjacency_iterator;
  71. // miscellaneous types
  72. typedef directed_graph_tag graph_tag;
  73. typedef typename graph_type::directed_category directed_category;
  74. typedef typename graph_type::edge_parallel_category edge_parallel_category;
  75. typedef typename graph_type::traversal_category traversal_category;
  76. typedef std::size_t vertex_index_type;
  77. typedef std::size_t edge_index_type;
  78. directed_graph(GraphProp const& p = GraphProp())
  79. : m_graph(p), m_num_vertices(0), m_num_edges(0), m_max_vertex_index(0)
  80. , m_max_edge_index(0)
  81. { }
  82. directed_graph(directed_graph const& x)
  83. : m_graph(x.m_graph), m_num_vertices(x.m_num_vertices), m_num_edges(x.m_num_edges)
  84. , m_max_vertex_index(x.m_max_vertex_index), m_max_edge_index(x.m_max_edge_index)
  85. { }
  86. directed_graph(vertices_size_type n, GraphProp const& p = GraphProp())
  87. : m_graph(n, p), m_num_vertices(n), m_num_edges(0), m_max_vertex_index(n)
  88. , m_max_edge_index(0)
  89. { renumber_vertex_indices(); }
  90. template <typename EdgeIterator>
  91. directed_graph(EdgeIterator f,
  92. EdgeIterator l,
  93. vertices_size_type n,
  94. edges_size_type m = 0,
  95. GraphProp const& p = GraphProp())
  96. : m_graph(f, l, n, m, p), m_num_vertices(n), m_num_edges(0)
  97. , m_max_vertex_index(n), m_max_edge_index(0)
  98. {
  99. // Unfortunately, we have to renumber the entire graph.
  100. renumber_indices();
  101. // Can't always guarantee that the number of edges is actually
  102. // m if distance(f, l) != m (or is undefined).
  103. m_num_edges = m_max_edge_index = boost::num_edges(m_graph);
  104. }
  105. directed_graph& operator=(directed_graph const& g) {
  106. if(&g != this) {
  107. m_graph = g.m_graph;
  108. m_num_vertices = g.m_num_vertices;
  109. m_num_edges = g.m_num_edges;
  110. m_max_vertex_index = g.m_max_vertex_index;
  111. m_max_edge_index = g.m_max_edge_index;
  112. }
  113. return *this;
  114. }
  115. // The impl_() methods are not part of the public interface.
  116. graph_type& impl()
  117. { return m_graph; }
  118. graph_type const& impl() const
  119. { return m_graph; }
  120. // The following methods are not part of the public interface
  121. vertices_size_type num_vertices() const
  122. { return m_num_vertices; }
  123. private:
  124. // This helper function manages the attribution of vertex indices.
  125. vertex_descriptor make_index(vertex_descriptor v) {
  126. boost::put(vertex_index, m_graph, v, m_max_vertex_index);
  127. m_num_vertices++;
  128. m_max_vertex_index++;
  129. return v;
  130. }
  131. public:
  132. vertex_descriptor add_vertex()
  133. { return make_index(boost::add_vertex(m_graph)); }
  134. vertex_descriptor add_vertex(vertex_property_type const& p)
  135. { return make_index(boost::add_vertex(internal_vertex_property(0u, p), m_graph)); }
  136. void clear_vertex(vertex_descriptor v)
  137. {
  138. m_num_edges -= boost::degree(v, m_graph);
  139. boost::clear_vertex(v, m_graph);
  140. }
  141. void remove_vertex(vertex_descriptor v)
  142. {
  143. boost::remove_vertex(v, m_graph);
  144. --m_num_vertices;
  145. }
  146. edges_size_type num_edges() const
  147. { return m_num_edges; }
  148. private:
  149. // A helper function for managing edge index attributes.
  150. std::pair<edge_descriptor, bool> const&
  151. make_index(std::pair<edge_descriptor, bool> const& x)
  152. {
  153. if(x.second) {
  154. boost::put(edge_index, m_graph, x.first, m_max_edge_index);
  155. ++m_num_edges;
  156. ++m_max_edge_index;
  157. }
  158. return x;
  159. }
  160. public:
  161. std::pair<edge_descriptor, bool>
  162. add_edge(vertex_descriptor u, vertex_descriptor v)
  163. { return make_index(boost::add_edge(u, v, m_graph)); }
  164. std::pair<edge_descriptor, bool>
  165. add_edge(vertex_descriptor u, vertex_descriptor v, edge_property_type const& p)
  166. { return make_index(boost::add_edge(u, v, internal_edge_property(0u, p), m_graph)); }
  167. void remove_edge(vertex_descriptor u, vertex_descriptor v)
  168. {
  169. // find all edges, (u, v)
  170. std::vector<edge_descriptor> edges;
  171. out_edge_iterator i, i_end;
  172. for(boost::tie(i, i_end) = boost::out_edges(u, m_graph); i != i_end; ++i) {
  173. if(boost::target(*i, m_graph) == v) {
  174. edges.push_back(*i);
  175. }
  176. }
  177. // remove all edges, (u, v)
  178. typename std::vector<edge_descriptor>::iterator
  179. j = edges.begin(), j_end = edges.end();
  180. for( ; j != j_end; ++j) {
  181. remove_edge(*j);
  182. }
  183. }
  184. void remove_edge(edge_iterator i)
  185. {
  186. remove_edge(*i);
  187. }
  188. void remove_edge(edge_descriptor e)
  189. {
  190. boost::remove_edge(e, m_graph);
  191. --m_num_edges;
  192. }
  193. vertex_index_type max_vertex_index() const
  194. { return m_max_vertex_index; }
  195. void
  196. renumber_vertex_indices()
  197. {
  198. vertex_iterator i, end;
  199. boost::tie(i, end) = vertices(m_graph);
  200. m_max_vertex_index = renumber_vertex_indices(i, end, 0);
  201. }
  202. void
  203. remove_vertex_and_renumber_indices(vertex_iterator i)
  204. {
  205. vertex_iterator j = next(i), end = vertices(m_graph).second;
  206. vertex_index_type n = get(vertex_index, m_graph, *i);
  207. // remove the offending vertex and renumber everything after
  208. remove_vertex(*i);
  209. m_max_vertex_index = renumber_vertex_indices(j, end, n);
  210. }
  211. edge_index_type
  212. max_edge_index() const
  213. { return m_max_edge_index; }
  214. void
  215. renumber_edge_indices()
  216. {
  217. edge_iterator i, end;
  218. boost::tie(i, end) = edges(m_graph);
  219. m_max_edge_index = renumber_edge_indices(i, end, 0);
  220. }
  221. void
  222. remove_edge_and_renumber_indices(edge_iterator i)
  223. {
  224. edge_iterator j = next(i), end = edges(m_graph).second;
  225. edge_index_type n = get(edge_index, m_graph, *i);
  226. // remove the offending edge and renumber everything after
  227. remove_edge(*i);
  228. m_max_edge_index = renumber_edge_indices(j, end, n);
  229. }
  230. void
  231. renumber_indices()
  232. {
  233. renumber_vertex_indices();
  234. renumber_edge_indices();
  235. }
  236. // bundled property support
  237. #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
  238. vertex_bundled& operator[](vertex_descriptor v)
  239. { return m_graph[v]; }
  240. vertex_bundled const& operator[](vertex_descriptor v) const
  241. { return m_graph[v]; }
  242. edge_bundled& operator[](edge_descriptor e)
  243. { return m_graph[e]; }
  244. edge_bundled const& operator[](edge_descriptor e) const
  245. { return m_graph[e]; }
  246. graph_bundled& operator[](graph_bundle_t)
  247. { return get_property(*this); }
  248. graph_bundled const& operator[](graph_bundle_t) const
  249. { return get_property(*this); }
  250. #endif
  251. // Graph concepts
  252. static vertex_descriptor null_vertex()
  253. { return graph_type::null_vertex(); }
  254. void clear()
  255. {
  256. m_graph.clear();
  257. m_num_vertices = m_max_vertex_index = 0;
  258. m_num_edges = m_max_edge_index = 0;
  259. }
  260. void swap(directed_graph& g)
  261. {
  262. m_graph.swap(g.m_graph);
  263. std::swap(m_num_vertices, g.m_num_vertices);
  264. std::swap(m_max_vertex_index, g.m_max_vertex_index);
  265. std::swap(m_num_edges, g.m_num_edges);
  266. std::swap(m_max_edge_index, g.m_max_edge_index);
  267. }
  268. private:
  269. vertices_size_type
  270. renumber_vertex_indices(vertex_iterator i,
  271. vertex_iterator end,
  272. vertices_size_type n)
  273. {
  274. typedef typename property_map<graph_type, vertex_index_t>::type IndexMap;
  275. IndexMap indices = get(vertex_index, m_graph);
  276. for( ; i != end; ++i) {
  277. indices[*i] = n++;
  278. }
  279. return n;
  280. }
  281. vertices_size_type
  282. renumber_edge_indices(edge_iterator i,
  283. edge_iterator end,
  284. vertices_size_type n)
  285. {
  286. typedef typename property_map<graph_type, edge_index_t>::type IndexMap;
  287. IndexMap indices = get(edge_index, m_graph);
  288. for( ; i != end; ++i) {
  289. indices[*i] = n++;
  290. }
  291. return n;
  292. }
  293. graph_type m_graph;
  294. vertices_size_type m_num_vertices;
  295. edges_size_type m_num_edges;
  296. vertex_index_type m_max_vertex_index;
  297. edge_index_type m_max_edge_index;
  298. };
  299. #define DIRECTED_GRAPH_PARAMS typename VP, typename EP, typename GP
  300. #define DIRECTED_GRAPH directed_graph<VP,EP,GP>
  301. // IncidenceGraph concepts
  302. template <DIRECTED_GRAPH_PARAMS>
  303. inline typename DIRECTED_GRAPH::vertex_descriptor
  304. source(typename DIRECTED_GRAPH::edge_descriptor e, DIRECTED_GRAPH const& g)
  305. { return source(e, g.impl()); }
  306. template <DIRECTED_GRAPH_PARAMS>
  307. inline typename DIRECTED_GRAPH::vertex_descriptor
  308. target(typename DIRECTED_GRAPH::edge_descriptor e, DIRECTED_GRAPH const& g)
  309. { return target(e, g.impl()); }
  310. template <DIRECTED_GRAPH_PARAMS>
  311. inline typename DIRECTED_GRAPH::degree_size_type
  312. out_degree(typename DIRECTED_GRAPH::vertex_descriptor v, DIRECTED_GRAPH const& g)
  313. { return out_degree(v, g.impl()); }
  314. template <DIRECTED_GRAPH_PARAMS>
  315. inline std::pair<
  316. typename DIRECTED_GRAPH::out_edge_iterator,
  317. typename DIRECTED_GRAPH::out_edge_iterator
  318. >
  319. out_edges(typename DIRECTED_GRAPH::vertex_descriptor v,
  320. DIRECTED_GRAPH const& g)
  321. { return out_edges(v, g.impl()); }
  322. // BidirectionalGraph concepts
  323. template <DIRECTED_GRAPH_PARAMS>
  324. inline typename DIRECTED_GRAPH::degree_size_type
  325. in_degree(typename DIRECTED_GRAPH::vertex_descriptor v, DIRECTED_GRAPH const& g)
  326. { return in_degree(v, g.impl()); }
  327. template <DIRECTED_GRAPH_PARAMS>
  328. inline std::pair<
  329. typename DIRECTED_GRAPH::in_edge_iterator,
  330. typename DIRECTED_GRAPH::in_edge_iterator
  331. >
  332. in_edges(typename DIRECTED_GRAPH::vertex_descriptor v,
  333. DIRECTED_GRAPH const& g)
  334. { return in_edges(v, g.impl()); }
  335. template <DIRECTED_GRAPH_PARAMS>
  336. inline typename DIRECTED_GRAPH::degree_size_type
  337. degree(typename DIRECTED_GRAPH::vertex_descriptor v, DIRECTED_GRAPH const& g)
  338. { return degree(v, g.impl()); }
  339. // AdjacencyGraph concepts
  340. template <DIRECTED_GRAPH_PARAMS>
  341. inline std::pair<
  342. typename DIRECTED_GRAPH::adjacency_iterator,
  343. typename DIRECTED_GRAPH::adjacency_iterator
  344. >
  345. adjacent_vertices(typename DIRECTED_GRAPH::vertex_descriptor v,
  346. DIRECTED_GRAPH const& g)
  347. { return adjacent_vertices(v, g.impl()); }
  348. template <DIRECTED_GRAPH_PARAMS>
  349. typename DIRECTED_GRAPH::vertex_descriptor
  350. vertex(typename DIRECTED_GRAPH::vertices_size_type n,
  351. DIRECTED_GRAPH const& g)
  352. { return vertex(n, g.impl()); }
  353. template <DIRECTED_GRAPH_PARAMS>
  354. std::pair<typename DIRECTED_GRAPH::edge_descriptor, bool>
  355. edge(typename DIRECTED_GRAPH::vertex_descriptor u,
  356. typename DIRECTED_GRAPH::vertex_descriptor v,
  357. DIRECTED_GRAPH const& g)
  358. { return edge(u, v, g.impl()); }
  359. // VertexListGraph concepts
  360. template <DIRECTED_GRAPH_PARAMS>
  361. inline typename DIRECTED_GRAPH::vertices_size_type
  362. num_vertices(DIRECTED_GRAPH const& g)
  363. { return g.num_vertices(); }
  364. template <DIRECTED_GRAPH_PARAMS>
  365. inline std::pair<
  366. typename DIRECTED_GRAPH::vertex_iterator,
  367. typename DIRECTED_GRAPH::vertex_iterator
  368. >
  369. vertices(DIRECTED_GRAPH const& g)
  370. { return vertices(g.impl()); }
  371. // EdgeListGraph concepts
  372. template <DIRECTED_GRAPH_PARAMS>
  373. inline typename DIRECTED_GRAPH::edges_size_type
  374. num_edges(DIRECTED_GRAPH const& g)
  375. { return g.num_edges(); }
  376. template <DIRECTED_GRAPH_PARAMS>
  377. inline std::pair<
  378. typename DIRECTED_GRAPH::edge_iterator,
  379. typename DIRECTED_GRAPH::edge_iterator
  380. >
  381. edges(DIRECTED_GRAPH const& g)
  382. { return edges(g.impl()); }
  383. // MutableGraph concepts
  384. template <DIRECTED_GRAPH_PARAMS>
  385. inline typename DIRECTED_GRAPH::vertex_descriptor
  386. add_vertex(DIRECTED_GRAPH& g)
  387. { return g.add_vertex(); }
  388. template <DIRECTED_GRAPH_PARAMS>
  389. inline typename DIRECTED_GRAPH::vertex_descriptor
  390. add_vertex(typename DIRECTED_GRAPH::vertex_property_type const& p,
  391. DIRECTED_GRAPH& g)
  392. { return g.add_vertex(p); }
  393. template <DIRECTED_GRAPH_PARAMS>
  394. inline void
  395. clear_vertex(typename DIRECTED_GRAPH::vertex_descriptor v,
  396. DIRECTED_GRAPH& g)
  397. { return g.clear_vertex(v); }
  398. template <DIRECTED_GRAPH_PARAMS>
  399. inline void
  400. remove_vertex(typename DIRECTED_GRAPH::vertex_descriptor v,
  401. DIRECTED_GRAPH& g)
  402. { return g.remove_vertex(v); }
  403. template <DIRECTED_GRAPH_PARAMS>
  404. inline std::pair<typename DIRECTED_GRAPH::edge_descriptor, bool>
  405. add_edge(typename DIRECTED_GRAPH::vertex_descriptor u,
  406. typename DIRECTED_GRAPH::vertex_descriptor v,
  407. DIRECTED_GRAPH& g)
  408. { return g.add_edge(u, v); }
  409. template <DIRECTED_GRAPH_PARAMS>
  410. inline std::pair<typename DIRECTED_GRAPH::edge_descriptor, bool>
  411. add_edge(typename DIRECTED_GRAPH::vertex_descriptor u,
  412. typename DIRECTED_GRAPH::vertex_descriptor v,
  413. typename DIRECTED_GRAPH::edge_property_type const& p,
  414. DIRECTED_GRAPH& g)
  415. { return g.add_edge(u, v, p); }
  416. template <DIRECTED_GRAPH_PARAMS>
  417. inline void remove_edge(typename DIRECTED_GRAPH::vertex_descriptor u,
  418. typename DIRECTED_GRAPH::vertex_descriptor v,
  419. DIRECTED_GRAPH& g)
  420. { return g.remove_edge(u, v); }
  421. template <DIRECTED_GRAPH_PARAMS>
  422. inline void remove_edge(typename DIRECTED_GRAPH::edge_descriptor e, DIRECTED_GRAPH& g)
  423. { return g.remove_edge(e); }
  424. template <DIRECTED_GRAPH_PARAMS>
  425. inline void remove_edge(typename DIRECTED_GRAPH::edge_iterator i, DIRECTED_GRAPH& g)
  426. { return g.remove_edge(i); }
  427. template <DIRECTED_GRAPH_PARAMS, class Predicate>
  428. inline void remove_edge_if(Predicate pred, DIRECTED_GRAPH& g)
  429. { return remove_edge_if(pred, g.impl()); }
  430. template <DIRECTED_GRAPH_PARAMS, class Predicate>
  431. inline void
  432. remove_out_edge_if(typename DIRECTED_GRAPH::vertex_descriptor v,
  433. Predicate pred,
  434. DIRECTED_GRAPH& g)
  435. { return remove_out_edge_if(v, pred, g.impl()); }
  436. template <DIRECTED_GRAPH_PARAMS, class Predicate>
  437. inline void
  438. remove_in_edge_if(typename DIRECTED_GRAPH::vertex_descriptor v,
  439. Predicate pred,
  440. DIRECTED_GRAPH& g)
  441. { return remove_in_edge_if(v, pred, g.impl()); }
  442. template <DIRECTED_GRAPH_PARAMS, typename Property>
  443. struct property_map<DIRECTED_GRAPH, Property>: property_map<typename DIRECTED_GRAPH::graph_type, Property> {};
  444. template <DIRECTED_GRAPH_PARAMS>
  445. struct property_map<DIRECTED_GRAPH, vertex_all_t> {
  446. typedef transform_value_property_map<
  447. detail::remove_first_property,
  448. typename property_map<typename DIRECTED_GRAPH::graph_type, vertex_all_t>::const_type>
  449. const_type;
  450. typedef transform_value_property_map<
  451. detail::remove_first_property,
  452. typename property_map<typename DIRECTED_GRAPH::graph_type, vertex_all_t>::type>
  453. type;
  454. };
  455. template <DIRECTED_GRAPH_PARAMS>
  456. struct property_map<DIRECTED_GRAPH, edge_all_t> {
  457. typedef transform_value_property_map<
  458. detail::remove_first_property,
  459. typename property_map<typename DIRECTED_GRAPH::graph_type, edge_all_t>::const_type>
  460. const_type;
  461. typedef transform_value_property_map<
  462. detail::remove_first_property,
  463. typename property_map<typename DIRECTED_GRAPH::graph_type, edge_all_t>::type>
  464. type;
  465. };
  466. // PropertyGraph concepts
  467. template <DIRECTED_GRAPH_PARAMS, typename Property>
  468. inline typename property_map<DIRECTED_GRAPH, Property>::type
  469. get(Property p, DIRECTED_GRAPH& g)
  470. { return get(p, g.impl()); }
  471. template <DIRECTED_GRAPH_PARAMS, typename Property>
  472. inline typename property_map<DIRECTED_GRAPH, Property>::const_type
  473. get(Property p, DIRECTED_GRAPH const& g)
  474. { return get(p, g.impl()); }
  475. template <DIRECTED_GRAPH_PARAMS>
  476. inline typename property_map<DIRECTED_GRAPH, vertex_all_t>::type
  477. get(vertex_all_t, DIRECTED_GRAPH& g)
  478. { return typename property_map<DIRECTED_GRAPH, vertex_all_t>::type(detail::remove_first_property(), get(vertex_all, g.impl())); }
  479. template <DIRECTED_GRAPH_PARAMS>
  480. inline typename property_map<DIRECTED_GRAPH, vertex_all_t>::const_type
  481. get(vertex_all_t, DIRECTED_GRAPH const& g)
  482. { return typename property_map<DIRECTED_GRAPH, vertex_all_t>::const_type(detail::remove_first_property(), get(vertex_all, g.impl())); }
  483. template <DIRECTED_GRAPH_PARAMS>
  484. inline typename property_map<DIRECTED_GRAPH, edge_all_t>::type
  485. get(edge_all_t, DIRECTED_GRAPH& g)
  486. { return typename property_map<DIRECTED_GRAPH, edge_all_t>::type(detail::remove_first_property(), get(edge_all, g.impl())); }
  487. template <DIRECTED_GRAPH_PARAMS>
  488. inline typename property_map<DIRECTED_GRAPH, edge_all_t>::const_type
  489. get(edge_all_t, DIRECTED_GRAPH const& g)
  490. { return typename property_map<DIRECTED_GRAPH, edge_all_t>::const_type(detail::remove_first_property(), get(edge_all, g.impl())); }
  491. template <DIRECTED_GRAPH_PARAMS, typename Property, typename Key>
  492. inline typename property_traits<
  493. typename property_map<
  494. typename DIRECTED_GRAPH::graph_type, Property
  495. >::const_type
  496. >::value_type
  497. get(Property p, DIRECTED_GRAPH const& g, Key const& k)
  498. { return get(p, g.impl(), k); }
  499. template <DIRECTED_GRAPH_PARAMS, typename Key>
  500. inline typename property_traits<
  501. typename property_map<
  502. typename DIRECTED_GRAPH::graph_type, vertex_all_t
  503. >::const_type
  504. >::value_type
  505. get(vertex_all_t, DIRECTED_GRAPH const& g, Key const& k)
  506. { return get(vertex_all, g.impl(), k).m_base; }
  507. template <DIRECTED_GRAPH_PARAMS, typename Key>
  508. inline typename property_traits<
  509. typename property_map<
  510. typename DIRECTED_GRAPH::graph_type, edge_all_t
  511. >::const_type
  512. >::value_type
  513. get(edge_all_t, DIRECTED_GRAPH const& g, Key const& k)
  514. { return get(edge_all, g.impl(), k).m_base; }
  515. template <DIRECTED_GRAPH_PARAMS, typename Property, typename Key, typename Value>
  516. inline void put(Property p, DIRECTED_GRAPH& g, Key const& k, Value const& v)
  517. { put(p, g.impl(), k, v); }
  518. template <DIRECTED_GRAPH_PARAMS, typename Key, typename Value>
  519. inline void put(vertex_all_t, DIRECTED_GRAPH& g, Key const& k, Value const& v)
  520. { put(vertex_all, g.impl(), k,
  521. typename DIRECTED_GRAPH::internal_vertex_property(get(vertex_index, g.impl(), k), v));
  522. }
  523. template <DIRECTED_GRAPH_PARAMS, typename Key, typename Value>
  524. inline void put(edge_all_t, DIRECTED_GRAPH& g, Key const& k, Value const& v)
  525. { put(edge_all, g.impl(), k,
  526. typename DIRECTED_GRAPH::internal_vertex_property(get(edge_index, g.impl(), k), v));
  527. }
  528. template <DIRECTED_GRAPH_PARAMS, class Property>
  529. typename graph_property<DIRECTED_GRAPH, Property>::type&
  530. get_property(DIRECTED_GRAPH& g, Property p)
  531. { return get_property(g.impl(), p); }
  532. template <DIRECTED_GRAPH_PARAMS, class Property>
  533. typename graph_property<DIRECTED_GRAPH, Property>::type const&
  534. get_property(DIRECTED_GRAPH const& g, Property p)
  535. { return get_property(g.impl(), p); }
  536. template <DIRECTED_GRAPH_PARAMS, class Property, class Value>
  537. void
  538. set_property(DIRECTED_GRAPH& g, Property p, Value v)
  539. { return set_property(g.impl(), p, v); }
  540. // Vertex index management
  541. template <DIRECTED_GRAPH_PARAMS>
  542. inline typename DIRECTED_GRAPH::vertex_index_type
  543. get_vertex_index(typename DIRECTED_GRAPH::vertex_descriptor v,
  544. DIRECTED_GRAPH const& g)
  545. { return get(vertex_index, g, v); }
  546. template <DIRECTED_GRAPH_PARAMS>
  547. typename DIRECTED_GRAPH::vertex_index_type
  548. max_vertex_index(DIRECTED_GRAPH const& g)
  549. { return g.max_vertex_index(); }
  550. template <DIRECTED_GRAPH_PARAMS>
  551. inline void
  552. renumber_vertex_indices(DIRECTED_GRAPH& g)
  553. { g.renumber_vertex_indices(); }
  554. template <DIRECTED_GRAPH_PARAMS>
  555. inline void
  556. remove_vertex_and_renumber_indices(typename DIRECTED_GRAPH::vertex_iterator i,
  557. DIRECTED_GRAPH& g)
  558. { g.remove_vertex_and_renumber_indices(i); }
  559. // Edge index management
  560. template <DIRECTED_GRAPH_PARAMS>
  561. inline typename DIRECTED_GRAPH::edge_index_type
  562. get_edge_index(typename DIRECTED_GRAPH::edge_descriptor v, DIRECTED_GRAPH const& g)
  563. { return get(edge_index, g, v); }
  564. template <DIRECTED_GRAPH_PARAMS>
  565. typename DIRECTED_GRAPH::edge_index_type
  566. max_edge_index(DIRECTED_GRAPH const& g)
  567. { return g.max_edge_index(); }
  568. template <DIRECTED_GRAPH_PARAMS>
  569. inline void renumber_edge_indices(DIRECTED_GRAPH& g)
  570. { g.renumber_edge_indices(); }
  571. template <DIRECTED_GRAPH_PARAMS>
  572. inline void
  573. remove_edge_and_renumber_indices(typename DIRECTED_GRAPH::edge_iterator i,
  574. DIRECTED_GRAPH& g)
  575. { g.remove_edge_and_renumber_indices(i); }
  576. // Index management
  577. template <DIRECTED_GRAPH_PARAMS>
  578. inline void
  579. renumber_indices(DIRECTED_GRAPH& g)
  580. { g.renumber_indices(); }
  581. // Mutability Traits
  582. template <DIRECTED_GRAPH_PARAMS>
  583. struct graph_mutability_traits<DIRECTED_GRAPH> {
  584. typedef mutable_property_graph_tag category;
  585. };
  586. #undef DIRECTED_GRAPH_PARAMS
  587. #undef DIRECTED_GRAPH
  588. } /* namespace boost */
  589. #endif