index.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_DETAIL_INDEX_HPP
  7. #define BOOST_GRAPH_DETAIL_INDEX_HPP
  8. #include <boost/graph/graph_traits.hpp>
  9. // The structures in this module are responsible for selecting and defining
  10. // types for accessing a builting index map. Note that the selection of these
  11. // types requires the Graph parameter to model either VertexIndexGraph or
  12. // EdgeIndexGraph.
  13. namespace boost
  14. {
  15. namespace detail
  16. {
  17. template <typename Graph>
  18. struct vertex_indexer
  19. {
  20. typedef vertex_index_t index_type;
  21. typedef typename property_map<Graph, vertex_index_t>::type map_type;
  22. typedef typename property_map<Graph, vertex_index_t>::const_type const_map_type;
  23. typedef typename property_traits<map_type>::value_type value_type;
  24. typedef typename graph_traits<Graph>::vertex_descriptor key_type;
  25. static const_map_type index_map(const Graph& g)
  26. { return get(vertex_index, g); }
  27. static map_type index_map(Graph& g)
  28. { return get(vertex_index, g); }
  29. static value_type index(key_type k, const Graph& g)
  30. { return get(vertex_index, g, k); }
  31. };
  32. template <typename Graph>
  33. struct edge_indexer
  34. {
  35. typedef edge_index_t index_type;
  36. typedef typename property_map<Graph, edge_index_t>::type map_type;
  37. typedef typename property_map<Graph, edge_index_t>::const_type const_map_type;
  38. typedef typename property_traits<map_type>::value_type value_type;
  39. typedef typename graph_traits<Graph>::edge_descriptor key_type;
  40. static const_map_type index_map(const Graph& g)
  41. { return get(edge_index, g); }
  42. static map_type index_map(Graph& g)
  43. { return get(edge_index, g); }
  44. static value_type index(key_type k, const Graph& g)
  45. { return get(edge_index, g, k); }
  46. };
  47. // NOTE: The Graph parameter MUST be a model of VertexIndexGraph or
  48. // VertexEdgeGraph - whichever type Key is selecting.
  49. template <typename Graph, typename Key>
  50. struct choose_indexer
  51. {
  52. typedef typename mpl::if_<
  53. is_same<Key, typename graph_traits<Graph>::vertex_descriptor>,
  54. vertex_indexer<Graph>,
  55. edge_indexer<Graph>
  56. >::type indexer_type;
  57. typedef typename indexer_type::index_type index_type;
  58. };
  59. }
  60. }
  61. #endif