index.hpp 2.6 KB

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