/Src/Dependencies/Boost/boost/graph/undirected_graph.hpp

http://hadesmem.googlecode.com/ · C++ Header · 698 lines · 534 code · 114 blank · 50 comment · 13 complexity · ca443b8d35db4d1740921c223d2188dc MD5 · raw file

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