property_iter_range.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // (C) Copyright Francois Faure, iMAGIS-GRAVIR / UJF, 2001.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Revision History:
  8. // 03 May 2001 Jeremy Siek
  9. // Generalized the property map iterator and moved that
  10. // part to boost/property_map.hpp. Also modified to
  11. // differentiate between const/mutable graphs and
  12. // added a workaround to avoid partial specialization.
  13. // 02 May 2001 Francois Faure
  14. // Initial version.
  15. #ifndef BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
  16. #define BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP
  17. #include <boost/property_map/property_map_iterator.hpp>
  18. #include <boost/graph/properties.hpp>
  19. #include <boost/mpl/if.hpp>
  20. #include <boost/type_traits/same_traits.hpp>
  21. namespace boost
  22. {
  23. //======================================================================
  24. // graph property iterator range
  25. template < class Graph, class PropertyTag > class graph_property_iter_range
  26. {
  27. typedef typename property_map< Graph, PropertyTag >::type map_type;
  28. typedef
  29. typename property_map< Graph, PropertyTag >::const_type const_map_type;
  30. typedef typename property_kind< PropertyTag >::type Kind;
  31. typedef typename mpl::if_c< is_same< Kind, vertex_property_tag >::value,
  32. typename graph_traits< Graph >::vertex_iterator,
  33. typename graph_traits< Graph >::edge_iterator >::type iter;
  34. public:
  35. typedef typename property_map_iterator_generator< map_type, iter >::type
  36. iterator;
  37. typedef
  38. typename property_map_iterator_generator< const_map_type, iter >::type
  39. const_iterator;
  40. typedef std::pair< iterator, iterator > type;
  41. typedef std::pair< const_iterator, const_iterator > const_type;
  42. };
  43. namespace detail
  44. {
  45. template < class Graph, class Tag >
  46. typename graph_property_iter_range< Graph, Tag >::type
  47. get_property_iter_range_kind(
  48. Graph& graph, const Tag& tag, const vertex_property_tag&)
  49. {
  50. typedef typename graph_property_iter_range< Graph, Tag >::iterator iter;
  51. return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
  52. iter(vertices(graph).second, get(tag, graph)));
  53. }
  54. template < class Graph, class Tag >
  55. typename graph_property_iter_range< Graph, Tag >::const_type
  56. get_property_iter_range_kind(
  57. const Graph& graph, const Tag& tag, const vertex_property_tag&)
  58. {
  59. typedef typename graph_property_iter_range< Graph, Tag >::const_iterator
  60. iter;
  61. return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
  62. iter(vertices(graph).second, get(tag, graph)));
  63. }
  64. template < class Graph, class Tag >
  65. typename graph_property_iter_range< Graph, Tag >::type
  66. get_property_iter_range_kind(
  67. Graph& graph, const Tag& tag, const edge_property_tag&)
  68. {
  69. typedef typename graph_property_iter_range< Graph, Tag >::iterator iter;
  70. return std::make_pair(iter(edges(graph).first, get(tag, graph)),
  71. iter(edges(graph).second, get(tag, graph)));
  72. }
  73. template < class Graph, class Tag >
  74. typename graph_property_iter_range< Graph, Tag >::const_type
  75. get_property_iter_range_kind(
  76. const Graph& graph, const Tag& tag, const edge_property_tag&)
  77. {
  78. typedef typename graph_property_iter_range< Graph, Tag >::const_iterator
  79. iter;
  80. return std::make_pair(iter(edges(graph).first, get(tag, graph)),
  81. iter(edges(graph).second, get(tag, graph)));
  82. }
  83. } // namespace detail
  84. //======================================================================
  85. // get an iterator range of properties
  86. template < class Graph, class Tag >
  87. typename graph_property_iter_range< Graph, Tag >::type get_property_iter_range(
  88. Graph& graph, const Tag& tag)
  89. {
  90. typedef typename property_kind< Tag >::type Kind;
  91. return detail::get_property_iter_range_kind(graph, tag, Kind());
  92. }
  93. template < class Graph, class Tag >
  94. typename graph_property_iter_range< Graph, Tag >::const_type
  95. get_property_iter_range(const Graph& graph, const Tag& tag)
  96. {
  97. typedef typename property_kind< Tag >::type Kind;
  98. return detail::get_property_iter_range_kind(graph, tag, Kind());
  99. }
  100. } // namespace boost
  101. #endif // BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP