property_iter_range.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. // graph property iterator range
  24. template <class Graph, class PropertyTag>
  25. class graph_property_iter_range {
  26. typedef typename property_map<Graph, PropertyTag>::type map_type;
  27. typedef typename property_map<Graph, PropertyTag>::const_type
  28. const_map_type;
  29. typedef typename property_kind<PropertyTag>::type Kind;
  30. typedef typename mpl::if_c<is_same<Kind, vertex_property_tag>::value,
  31. typename graph_traits<Graph>::vertex_iterator,
  32. typename graph_traits<Graph>::edge_iterator>::type iter;
  33. public:
  34. typedef typename property_map_iterator_generator<map_type, iter>::type
  35. iterator;
  36. typedef typename property_map_iterator_generator<const_map_type, iter>
  37. ::type const_iterator;
  38. typedef std::pair<iterator, iterator> type;
  39. typedef std::pair<const_iterator, const_iterator> const_type;
  40. };
  41. namespace detail {
  42. template<class Graph,class Tag>
  43. typename graph_property_iter_range<Graph,Tag>::type
  44. get_property_iter_range_kind(Graph& graph, const Tag& tag,
  45. const vertex_property_tag& )
  46. {
  47. typedef typename graph_property_iter_range<Graph,Tag>::iterator iter;
  48. return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
  49. iter(vertices(graph).second, get(tag, graph)));
  50. }
  51. template<class Graph,class Tag>
  52. typename graph_property_iter_range<Graph,Tag>::const_type
  53. get_property_iter_range_kind(const Graph& graph, const Tag& tag,
  54. const vertex_property_tag& )
  55. {
  56. typedef typename graph_property_iter_range<Graph,Tag>
  57. ::const_iterator iter;
  58. return std::make_pair(iter(vertices(graph).first, get(tag, graph)),
  59. iter(vertices(graph).second, get(tag, graph)));
  60. }
  61. template<class Graph,class Tag>
  62. typename graph_property_iter_range<Graph,Tag>::type
  63. get_property_iter_range_kind(Graph& graph, const Tag& tag,
  64. const edge_property_tag& )
  65. {
  66. typedef typename graph_property_iter_range<Graph,Tag>::iterator iter;
  67. return std::make_pair(iter(edges(graph).first, get(tag, graph)),
  68. iter(edges(graph).second, get(tag, graph)));
  69. }
  70. template<class Graph,class Tag>
  71. typename graph_property_iter_range<Graph,Tag>::const_type
  72. get_property_iter_range_kind(const Graph& graph, const Tag& tag,
  73. const edge_property_tag& )
  74. {
  75. typedef typename graph_property_iter_range<Graph,Tag>
  76. ::const_iterator iter;
  77. return std::make_pair(iter(edges(graph).first, get(tag, graph)),
  78. iter(edges(graph).second, get(tag, graph)));
  79. }
  80. } // namespace detail
  81. //======================================================================
  82. // get an iterator range of properties
  83. template<class Graph, class Tag>
  84. typename graph_property_iter_range<Graph, Tag>::type
  85. get_property_iter_range(Graph& graph, const Tag& tag)
  86. {
  87. typedef typename property_kind<Tag>::type Kind;
  88. return detail::get_property_iter_range_kind(graph, tag, Kind());
  89. }
  90. template<class Graph, class Tag>
  91. typename graph_property_iter_range<Graph, Tag>::const_type
  92. get_property_iter_range(const Graph& graph, const Tag& tag)
  93. {
  94. typedef typename property_kind<Tag>::type Kind;
  95. return detail::get_property_iter_range_kind(graph, tag, Kind());
  96. }
  97. } // namespace boost
  98. #endif // BOOST_GRAPH_PROPERTY_ITER_RANGE_HPP