stanford_graph.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //=======================================================================
  2. // Copyright 1997-2001 University of Notre Dame.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #ifndef BOOST_GRAPH_SGB_GRAPH_HPP
  10. #define BOOST_GRAPH_SGB_GRAPH_HPP
  11. #include <boost/config.hpp>
  12. #include <boost/iterator.hpp>
  13. #include <boost/operators.hpp>
  14. #include <boost/property_map/property_map.hpp>
  15. #include <boost/graph/graph_traits.hpp>
  16. #include <boost/graph/properties.hpp>
  17. // Thanks to Andreas Scherer for numerous suggestions and fixes!
  18. // This file adapts a Stanford GraphBase (SGB) Graph pointer into a
  19. // VertexListGraph. Note that a graph adaptor class is not needed,
  20. // SGB's Graph* is used as is. The VertexListGraph concept is fulfilled by
  21. // defining the appropriate non-member functions for Graph*.
  22. //
  23. // The PROTOTYPES change file extensions to SGB must be applied so
  24. // that the SGB functions have real prototypes which are necessary for
  25. // the C++ compiler. To apply the PROTOTYPES extensions, before you do
  26. // "make tests install" for SGB do "ln -s PROTOTYPES/* ." to the SGB
  27. // root directory (or just copy all the files from the PROTOTYPES
  28. // directory to the SGB root directory).
  29. //
  30. extern "C" {
  31. // We include all global definitions for the general stuff
  32. // of The Stanford GraphBase and its various graph generator
  33. // functions by reading all SGB headerfiles as in section 2 of
  34. // the "test_sample" program.
  35. #include <gb_graph.h> /* SGB data structures */
  36. #include <gb_io.h> /* SGB input/output routines */
  37. #include <gb_flip.h> /* random number generator */
  38. #include <gb_dijk.h> /* routines for shortest paths */
  39. #include <gb_basic.h> /* the basic graph operations */
  40. #undef empty /* avoid name clash with C++ standard library */
  41. inline Graph* empty( long n ) /* and provide workaround */
  42. { return board(n,0L,0L,0L,2L,0L,0L); }
  43. #include <gb_books.h> /* graphs based on literature */
  44. #include <gb_econ.h> /* graphs based on economic data */
  45. #include <gb_games.h> /* graphs based on football scores */
  46. #include <gb_gates.h> /* graphs based on logic circuits */
  47. #undef val /* avoid name clash with g++ headerfile stl_tempbuf.h */
  48. // val ==> Vertex::x.I
  49. #include <gb_lisa.h> /* graphs based on Mona Lisa */
  50. #include <gb_miles.h> /* graphs based on mileage data */
  51. #include <gb_plane.h> /* planar graphs */
  52. #include <gb_raman.h> /* Ramanujan graphs */
  53. #include <gb_rand.h> /* random graphs */
  54. #include <gb_roget.h> /* graphs based on Roget's Thesaurus */
  55. #include <gb_save.h> /* we save results in ASCII format */
  56. #include <gb_words.h> /* five-letter-word graphs */
  57. #undef weight /* avoid name clash with BGL parameter */
  58. // weight ==> Vertex::u.I
  59. }
  60. namespace boost {
  61. class sgb_edge;
  62. }
  63. class sgb_out_edge_iterator;
  64. class sgb_adj_iterator;
  65. class sgb_vertex_iterator;
  66. namespace boost {
  67. typedef Graph* sgb_graph_ptr;
  68. typedef const Graph* sgb_const_graph_ptr;
  69. struct sgb_traversal_tag :
  70. public virtual vertex_list_graph_tag,
  71. public virtual incidence_graph_tag,
  72. public virtual adjacency_graph_tag { };
  73. template <> struct graph_traits<sgb_graph_ptr> {
  74. typedef Vertex* vertex_descriptor;
  75. typedef boost::sgb_edge edge_descriptor;
  76. typedef sgb_out_edge_iterator out_edge_iterator;
  77. typedef void in_edge_iterator;
  78. typedef sgb_adj_iterator adjacency_iterator;
  79. typedef sgb_vertex_iterator vertex_iterator;
  80. typedef void edge_iterator;
  81. typedef long vertices_size_type;
  82. typedef long edge_size_type;
  83. typedef long degree_size_type;
  84. typedef directed_tag directed_category;
  85. typedef sgb_traversal_tag traversal_category;
  86. typedef allow_parallel_edge_tag edge_parallel_category;
  87. };
  88. template <> struct graph_traits<sgb_const_graph_ptr> {
  89. typedef Vertex* vertex_descriptor;
  90. typedef boost::sgb_edge edge_descriptor;
  91. typedef sgb_out_edge_iterator out_edge_iterator;
  92. typedef void in_edge_iterator;
  93. typedef sgb_adj_iterator adjacency_iterator;
  94. typedef sgb_vertex_iterator vertex_iterator;
  95. typedef void edge_iterator;
  96. typedef long vertices_size_type;
  97. typedef long edge_size_type;
  98. typedef long degree_size_type;
  99. typedef directed_tag directed_category;
  100. typedef sgb_traversal_tag traversal_category;
  101. typedef allow_parallel_edge_tag edge_parallel_category;
  102. };
  103. }
  104. namespace boost {
  105. struct edge_length_t {
  106. typedef edge_property_tag kind;
  107. };
  108. // We could just use Arc* as the edge descriptor type, but
  109. // we want to add the source(e,g) function which requires
  110. // that we carry along a pointer to the source vertex.
  111. class sgb_edge {
  112. typedef sgb_edge self;
  113. public:
  114. sgb_edge() : _arc(0), _src(0) { }
  115. sgb_edge(Arc* a, Vertex* s) : _arc(a), _src(s) { }
  116. friend Vertex* source(self e, sgb_const_graph_ptr) { return e._src; }
  117. friend Vertex* target(self e, sgb_const_graph_ptr) { return e._arc->tip; }
  118. friend bool operator==(const self& a, const self& b) {
  119. return a._arc == b._arc; }
  120. friend bool operator!=(const self& a, const self& b) {
  121. return a._arc != b._arc; }
  122. #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
  123. template <class Ref> friend class sgb_edge_length_map;
  124. template <class Tag, class Ref> friend class sgb_edge_util_map;
  125. friend long get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key);
  126. friend long get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key);
  127. friend void put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value);
  128. protected:
  129. #endif
  130. Arc* _arc;
  131. Vertex* _src;
  132. };
  133. } // namespace boost
  134. class sgb_out_edge_iterator
  135. : public boost::forward_iterator_helper<
  136. sgb_out_edge_iterator, boost::sgb_edge,
  137. std::ptrdiff_t, boost::sgb_edge*, boost::sgb_edge>
  138. {
  139. typedef sgb_out_edge_iterator self;
  140. public:
  141. sgb_out_edge_iterator() : _src(0), _arc(0) {}
  142. sgb_out_edge_iterator(Vertex* s, Arc* d) : _src(s), _arc(d) {}
  143. boost::sgb_edge operator*() { return boost::sgb_edge(_arc, _src); }
  144. self& operator++() { _arc = _arc->next; return *this; }
  145. friend bool operator==(const self& x, const self& y) {
  146. return x._arc == y._arc; }
  147. protected:
  148. Vertex* _src;
  149. Arc* _arc;
  150. };
  151. class sgb_adj_iterator
  152. : public boost::forward_iterator_helper<
  153. sgb_adj_iterator, Vertex*, std::ptrdiff_t, Vertex**,Vertex*>
  154. {
  155. typedef sgb_adj_iterator self;
  156. public:
  157. sgb_adj_iterator() : _arc(0) {}
  158. sgb_adj_iterator(Arc* d) : _arc(d) {}
  159. Vertex* operator*() { return _arc->tip; }
  160. self& operator++() { _arc = _arc->next; return *this; }
  161. friend bool operator==(const self& x, const self& y) {
  162. return x._arc == y._arc; }
  163. protected:
  164. Arc* _arc;
  165. };
  166. // The reason we have this instead of just using Vertex* is that we
  167. // want to use Vertex* as the vertex_descriptor instead of just
  168. // Vertex, which avoids problems with boost passing vertex descriptors
  169. // by value and how that interacts with the sgb_vertex_id_map.
  170. class sgb_vertex_iterator
  171. : public boost::forward_iterator_helper<
  172. sgb_vertex_iterator, Vertex*, std::ptrdiff_t, Vertex**, Vertex*>
  173. {
  174. typedef sgb_vertex_iterator self;
  175. public:
  176. sgb_vertex_iterator() : _v(0) { }
  177. sgb_vertex_iterator(Vertex* v) : _v(v) { }
  178. Vertex* operator*() { return _v; }
  179. self& operator++() { ++_v; return *this; }
  180. friend bool operator==(const self& x, const self& y) {
  181. return x._v == y._v; }
  182. protected:
  183. Vertex* _v;
  184. };
  185. namespace boost {
  186. inline std::pair<sgb_vertex_iterator,sgb_vertex_iterator>
  187. vertices(sgb_const_graph_ptr g)
  188. {
  189. return std::make_pair(sgb_vertex_iterator(g->vertices),
  190. sgb_vertex_iterator(g->vertices + g->n));
  191. }
  192. inline std::pair<sgb_out_edge_iterator,sgb_out_edge_iterator>
  193. out_edges(Vertex* u, sgb_const_graph_ptr)
  194. {
  195. return std::make_pair( sgb_out_edge_iterator(u, u->arcs),
  196. sgb_out_edge_iterator(u, 0) );
  197. }
  198. inline boost::graph_traits<sgb_graph_ptr>::degree_size_type
  199. out_degree(Vertex* u, sgb_const_graph_ptr g)
  200. {
  201. boost::graph_traits<sgb_graph_ptr>::out_edge_iterator i, i_end;
  202. boost::tie(i, i_end) = out_edges(u, g);
  203. return std::distance(i, i_end);
  204. }
  205. // in_edges?
  206. inline std::pair<sgb_adj_iterator,sgb_adj_iterator>
  207. adjacent_vertices(Vertex* u, sgb_const_graph_ptr)
  208. {
  209. return std::make_pair( sgb_adj_iterator(u->arcs),
  210. sgb_adj_iterator(0) );
  211. }
  212. inline long num_vertices(sgb_const_graph_ptr g) { return g->n; }
  213. inline long num_edges(sgb_const_graph_ptr g) { return g->m; }
  214. inline Vertex* vertex(long v, sgb_const_graph_ptr g)
  215. { return g->vertices + v; }
  216. // Various Property Maps
  217. // Vertex ID
  218. class sgb_vertex_id_map
  219. : public boost::put_get_helper<long, sgb_vertex_id_map>
  220. {
  221. public:
  222. typedef boost::readable_property_map_tag category;
  223. typedef long value_type;
  224. typedef long reference;
  225. typedef Vertex* key_type;
  226. sgb_vertex_id_map() : _g(0) { }
  227. sgb_vertex_id_map(sgb_graph_ptr g) : _g(g) { }
  228. long operator[](Vertex* v) const { return v - _g->vertices; }
  229. protected:
  230. sgb_graph_ptr _g;
  231. };
  232. inline sgb_vertex_id_map get(vertex_index_t, sgb_graph_ptr g) {
  233. return sgb_vertex_id_map(g);
  234. }
  235. // Vertex Name
  236. class sgb_vertex_name_map
  237. : public boost::put_get_helper<char*, sgb_vertex_name_map>
  238. {
  239. public:
  240. typedef boost::readable_property_map_tag category;
  241. typedef char* value_type;
  242. typedef char* reference;
  243. typedef Vertex* key_type;
  244. char* operator[](Vertex* v) const { return v->name; }
  245. };
  246. inline sgb_vertex_name_map get(vertex_name_t, sgb_graph_ptr) {
  247. return sgb_vertex_name_map();
  248. }
  249. // Vertex Property Tags
  250. #define SGB_PROPERTY_TAG(KIND,TAG) \
  251. template <class T> struct TAG##_property { \
  252. typedef KIND##_property_tag kind; \
  253. typedef T type; \
  254. };
  255. SGB_PROPERTY_TAG(vertex, u)
  256. SGB_PROPERTY_TAG(vertex, v)
  257. SGB_PROPERTY_TAG(vertex, w)
  258. SGB_PROPERTY_TAG(vertex, x)
  259. SGB_PROPERTY_TAG(vertex, y)
  260. SGB_PROPERTY_TAG(vertex, z)
  261. // Edge Property Tags
  262. SGB_PROPERTY_TAG(edge, a)
  263. SGB_PROPERTY_TAG(edge, b)
  264. // Various Utility Maps
  265. // helpers
  266. inline Vertex*& get_util(util& u, Vertex*) { return u.V; }
  267. inline Arc*& get_util(util& u, Arc*) { return u.A; }
  268. inline sgb_graph_ptr& get_util(util& u, sgb_graph_ptr) { return u.G; }
  269. inline char*& get_util(util& u, char*) { return u.S; }
  270. inline long& get_util(util& u, long) { return u.I; }
  271. #define SGB_GET_UTIL_FIELD(KIND,X) \
  272. template <class T> \
  273. inline T& get_util_field(KIND* k, X##_property<T>) { \
  274. return get_util(k->X, T()); }
  275. SGB_GET_UTIL_FIELD(Vertex, u)
  276. SGB_GET_UTIL_FIELD(Vertex, v)
  277. SGB_GET_UTIL_FIELD(Vertex, w)
  278. SGB_GET_UTIL_FIELD(Vertex, x)
  279. SGB_GET_UTIL_FIELD(Vertex, y)
  280. SGB_GET_UTIL_FIELD(Vertex, z)
  281. SGB_GET_UTIL_FIELD(Arc, a)
  282. SGB_GET_UTIL_FIELD(Arc, b)
  283. // Vertex Utility Map
  284. template <class Tag, class Ref>
  285. class sgb_vertex_util_map
  286. : public boost::put_get_helper<Ref, sgb_vertex_util_map<Tag, Ref> >
  287. {
  288. Tag tag;
  289. public:
  290. explicit sgb_vertex_util_map(Tag tag = Tag()): tag(tag) {}
  291. typedef boost::lvalue_property_map_tag category;
  292. typedef typename Tag::type value_type;
  293. typedef Vertex* key_type;
  294. typedef Ref reference;
  295. reference operator[](Vertex* v) const {
  296. return get_util_field(v, tag);
  297. }
  298. };
  299. // Edge Utility Map
  300. template <class Tag, class Ref>
  301. class sgb_edge_util_map
  302. : public boost::put_get_helper<Ref, sgb_edge_util_map<Tag, Ref> >
  303. {
  304. Tag tag;
  305. public:
  306. explicit sgb_edge_util_map(Tag tag = Tag()): tag(tag) {}
  307. typedef boost::lvalue_property_map_tag category;
  308. typedef typename Tag::type value_type;
  309. typedef Vertex* key_type;
  310. typedef Ref reference;
  311. reference operator[](const sgb_edge& e) const {
  312. return get_util_field(e._arc, tag);
  313. }
  314. };
  315. #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  316. template <class Tag>
  317. inline sgb_vertex_util_map<Tag, const typename Tag::type&>
  318. get_property_map(Tag, const sgb_graph_ptr& g, vertex_property_tag) {
  319. return sgb_vertex_util_map<Tag, const typename Tag::type&>();
  320. }
  321. template <class Tag>
  322. inline sgb_vertex_util_map<Tag, typename Tag::type&>
  323. get_property_map(Tag, sgb_graph_ptr& g, vertex_property_tag) {
  324. return sgb_vertex_util_map<Tag, typename Tag::type&>();
  325. }
  326. template <class Tag>
  327. inline sgb_edge_util_map<Tag, const typename Tag::type&>
  328. get_property_map(Tag, const sgb_graph_ptr& g, edge_property_tag) {
  329. return sgb_edge_util_map<Tag, const typename Tag::type&>();
  330. }
  331. template <class Tag>
  332. inline sgb_edge_util_map<Tag, typename Tag::type&>
  333. get_property_map(Tag, sgb_graph_ptr& g, edge_property_tag) {
  334. return sgb_edge_util_map<Tag, typename Tag::type&>();
  335. }
  336. #endif // ! BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  337. // Edge Length Access
  338. template <class Ref>
  339. class sgb_edge_length_map
  340. : public boost::put_get_helper<Ref, sgb_edge_length_map<Ref> >
  341. {
  342. public:
  343. typedef boost::lvalue_property_map_tag category;
  344. typedef long value_type;
  345. typedef sgb_edge key_type;
  346. typedef Ref reference;
  347. reference operator[](const sgb_edge& e) const {
  348. return e._arc->len;
  349. }
  350. };
  351. inline sgb_edge_length_map<const long&>
  352. get(edge_length_t, const sgb_graph_ptr&) {
  353. return sgb_edge_length_map<const long&>();
  354. }
  355. inline sgb_edge_length_map<const long&>
  356. get(edge_length_t, const sgb_const_graph_ptr&) {
  357. return sgb_edge_length_map<const long&>();
  358. }
  359. inline sgb_edge_length_map<long&>
  360. get(edge_length_t, sgb_graph_ptr&) {
  361. return sgb_edge_length_map<long&>();
  362. }
  363. inline long
  364. get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key) {
  365. return key._arc->len;
  366. }
  367. inline long
  368. get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key) {
  369. return key._arc->len;
  370. }
  371. inline void
  372. put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value)
  373. {
  374. key._arc->len = value;
  375. }
  376. // Property Map Traits Classes
  377. template <>
  378. struct property_map<sgb_graph_ptr, edge_length_t> {
  379. typedef sgb_edge_length_map<long&> type;
  380. typedef sgb_edge_length_map<const long&> const_type;
  381. };
  382. template <>
  383. struct property_map<sgb_graph_ptr, vertex_index_t> {
  384. typedef sgb_vertex_id_map type;
  385. typedef sgb_vertex_id_map const_type;
  386. };
  387. template <>
  388. struct property_map<sgb_graph_ptr, vertex_name_t> {
  389. typedef sgb_vertex_name_map type;
  390. typedef sgb_vertex_name_map const_type;
  391. };
  392. template <>
  393. struct property_map<sgb_const_graph_ptr, edge_length_t> {
  394. typedef sgb_edge_length_map<const long&> const_type;
  395. };
  396. template <>
  397. struct property_map<sgb_const_graph_ptr, vertex_index_t> {
  398. typedef sgb_vertex_id_map const_type;
  399. };
  400. template <>
  401. struct property_map<sgb_const_graph_ptr, vertex_name_t> {
  402. typedef sgb_vertex_name_map const_type;
  403. };
  404. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  405. namespace detail {
  406. template <class Kind, class PropertyTag>
  407. struct sgb_choose_property_map { };
  408. template <class PropertyTag>
  409. struct sgb_choose_property_map<vertex_property_tag, PropertyTag> {
  410. typedef typename PropertyTag::type value_type;
  411. typedef sgb_vertex_util_map<PropertyTag, value_type&> type;
  412. typedef sgb_vertex_util_map<PropertyTag, const value_type&> const_type;
  413. };
  414. template <class PropertyTag>
  415. struct sgb_choose_property_map<edge_property_tag, PropertyTag> {
  416. typedef typename PropertyTag::type value_type;
  417. typedef sgb_edge_util_map<PropertyTag, value_type&> type;
  418. typedef sgb_edge_util_map<PropertyTag, const value_type&> const_type;
  419. };
  420. } // namespace detail
  421. template <class PropertyTag>
  422. struct property_map<sgb_graph_ptr, PropertyTag> {
  423. typedef typename property_kind<PropertyTag>::type Kind;
  424. typedef detail::sgb_choose_property_map<Kind, PropertyTag> Choice;
  425. typedef typename Choice::type type;
  426. typedef typename Choice::const_type const_type;
  427. };
  428. template <class PropertyTag>
  429. struct property_map<sgb_const_graph_ptr, PropertyTag> {
  430. typedef typename property_kind<PropertyTag>::type Kind;
  431. typedef detail::sgb_choose_property_map<Kind, PropertyTag> Choice;
  432. typedef typename Choice::const_type const_type;
  433. };
  434. #define SGB_UTIL_ACCESSOR(KIND,X) \
  435. template <class T> \
  436. inline sgb_##KIND##_util_map< X##_property<T>, T&> \
  437. get(X##_property<T>, sgb_graph_ptr&) { \
  438. return sgb_##KIND##_util_map< X##_property<T>, T&>(); \
  439. } \
  440. template <class T> \
  441. inline sgb_##KIND##_util_map< X##_property<T>, const T&> \
  442. get(X##_property<T>, const sgb_graph_ptr&) { \
  443. return sgb_##KIND##_util_map< X##_property<T>, const T&>(); \
  444. } \
  445. template <class T> \
  446. inline sgb_##KIND##_util_map< X##_property<T>, const T&> \
  447. get(X##_property<T>, const sgb_const_graph_ptr&) { \
  448. return sgb_##KIND##_util_map< X##_property<T>, const T&>(); \
  449. } \
  450. template <class T, class Key> \
  451. inline typename \
  452. sgb_##KIND##_util_map< X##_property<T>, const T&>::value_type \
  453. get(X##_property<T>, const sgb_graph_ptr&, const Key& key) { \
  454. return sgb_##KIND##_util_map< X##_property<T>, const T&>()[key]; \
  455. } \
  456. template <class T, class Key> \
  457. inline typename \
  458. sgb_##KIND##_util_map< X##_property<T>, const T&>::value_type \
  459. get(X##_property<T>, const sgb_const_graph_ptr&, const Key& key) { \
  460. return sgb_##KIND##_util_map< X##_property<T>, const T&>()[key]; \
  461. } \
  462. template <class T, class Key, class Value> \
  463. inline void \
  464. put(X##_property<T>, sgb_graph_ptr&, const Key& key, const Value& value) { \
  465. sgb_##KIND##_util_map< X##_property<T>, T&>()[key] = value; \
  466. }
  467. #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  468. #define SGB_UTIL_ACCESSOR_TYPE(KIND,TAG,TYPE) \
  469. inline sgb_##KIND##_util_map< TAG<TYPE>, TYPE& > \
  470. get(TAG<TYPE>, sgb_graph_ptr&) { \
  471. return sgb_##KIND##_util_map< TAG<TYPE>, TYPE& >(); \
  472. } \
  473. inline sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& > \
  474. get(TAG<TYPE>, const sgb_graph_ptr&) { \
  475. return sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >(); \
  476. } \
  477. inline sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& > \
  478. get(TAG<TYPE>, const sgb_const_graph_ptr&) { \
  479. return sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >(); \
  480. } \
  481. template <class Key> \
  482. inline typename sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >::value_type \
  483. get(TAG<TYPE>, const sgb_graph_ptr&, const Key& key) { \
  484. return sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >()[key]; \
  485. } \
  486. template <class Key> \
  487. inline typename sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >::value_type \
  488. get(TAG<TYPE>, const sgb_const_graph_ptr&, const Key& key) { \
  489. return sgb_##KIND##_util_map< TAG<TYPE>, const TYPE& >()[key]; \
  490. } \
  491. template <class Key, class Value> \
  492. inline void \
  493. put(TAG<TYPE>, sgb_graph_ptr&, const Key& key, const Value& value) { \
  494. sgb_##KIND##_util_map< TAG<TYPE>, TYPE& >()[key] = value; \
  495. } \
  496. template <> struct property_map<sgb_graph_ptr, TAG<TYPE> > { \
  497. typedef sgb_##KIND##_util_map< TAG<TYPE>, TYPE&> type; \
  498. typedef sgb_##KIND##_util_map< TAG<TYPE>, const TYPE&> const_type; \
  499. }
  500. #define SGB_UTIL_ACCESSOR(KIND,TAG) \
  501. SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, Vertex*); \
  502. SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, Arc*); \
  503. SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, sgb_graph_ptr); \
  504. SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, long); \
  505. SGB_UTIL_ACCESSOR_TYPE(KIND, TAG##_property, char*);
  506. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  507. SGB_UTIL_ACCESSOR(vertex, u)
  508. SGB_UTIL_ACCESSOR(vertex, v)
  509. SGB_UTIL_ACCESSOR(vertex, w)
  510. SGB_UTIL_ACCESSOR(vertex, x)
  511. SGB_UTIL_ACCESSOR(vertex, y)
  512. SGB_UTIL_ACCESSOR(vertex, z)
  513. SGB_UTIL_ACCESSOR(edge, a)
  514. SGB_UTIL_ACCESSOR(edge, b)
  515. } // namespace boost
  516. #endif // BOOST_GRAPH_SGB_GRAPH_HPP