mpl_graph.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2008-2010 Gordon Woodhull
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. // mpl_graph - defines a metadata implementation of the BGL immutable graph concepts
  5. // (c) 2008 Gordon Woodhull
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSEmpl::_1_0.txt or copy at
  8. // http://www.boost.org/LICENSEmpl::_1_0.txt)
  9. #ifndef BOOST_MSM_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED
  10. #define BOOST_MSM_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED
  11. #include <boost/msm/mpl_graph/detail/graph_implementation_interface.ipp>
  12. #include <boost/mpl/vector.hpp>
  13. #include <boost/mpl/pair.hpp>
  14. #include <boost/mpl/fold.hpp>
  15. #include <boost/mpl/push_back.hpp>
  16. #include <boost/mpl/at.hpp>
  17. #include <boost/mpl/size.hpp>
  18. #include <boost/mpl/plus.hpp>
  19. #include <boost/mpl/transform.hpp>
  20. #include <boost/mpl/back_inserter.hpp>
  21. namespace boost {
  22. namespace msm {
  23. namespace mpl_graph {
  24. // Boost Graph concepts, MPL style
  25. // The metafunctions of the public interface rely
  26. // metafunctions in the graph implementation to transform the input
  27. // into the maps which are required to deliver results. Since the
  28. // maps are produced lazily and are memoized, all of the graph
  29. // concepts can be supported with no cost until they are actually
  30. // used.
  31. // Each of these dispatch to the correct producer metafunctions based
  32. // on the representation inner type tag
  33. // IncidenceGraph
  34. template<typename Edge, typename Graph>
  35. struct source :
  36. mpl::first<typename mpl::at<typename detail::produce_edge_st_map<typename Graph::representation, typename Graph::data>::type,Edge>::type>
  37. {};
  38. template<typename Edge, typename Graph>
  39. struct target :
  40. mpl::second<typename mpl::at<typename detail::produce_edge_st_map<typename Graph::representation, typename Graph::data>::type,Edge>::type>
  41. {};
  42. template<typename Vertex, typename Graph>
  43. struct out_edges :
  44. mpl::fold<typename detail::produce_out_map<typename Graph::representation, Vertex, typename Graph::data>::type,
  45. mpl::vector<>,
  46. mpl::push_back<mpl::_1, mpl::first<mpl::_2> > >
  47. {};
  48. template<typename Vertex, typename Graph>
  49. struct out_degree :
  50. mpl::size<typename out_edges<Vertex, Graph>::type>
  51. {};
  52. // BidirectionalGraph
  53. template<typename Vertex, typename Graph>
  54. struct in_edges :
  55. mpl::fold<typename detail::produce_in_map<typename Graph::representation, Vertex, typename Graph::data>::type,
  56. mpl::vector<>,
  57. mpl::push_back<mpl::_1, mpl::first<mpl::_2> > >
  58. {};
  59. template<typename Vertex, typename Graph>
  60. struct in_degree :
  61. mpl::size<typename in_edges<Vertex, Graph>::type>
  62. {};
  63. template<typename Vertex, typename Graph>
  64. struct degree :
  65. mpl::plus<typename out_degree<Vertex, Graph>::type,typename in_degree<Vertex, Graph>::type>
  66. {};
  67. // AdjacencyGraph
  68. template<typename Vertex, typename Graph>
  69. struct adjacent_vertices :
  70. mpl::transform<typename detail::produce_out_map<typename Graph::representation, Vertex, typename Graph::data>::type,
  71. mpl::second<mpl::_1>,
  72. mpl::back_inserter<mpl::vector<> > >
  73. {};
  74. // VertexListGraph
  75. template<typename Graph>
  76. struct vertices :
  77. detail::produce_vertex_set<typename Graph::representation, typename Graph::data>
  78. {};
  79. template<typename Graph>
  80. struct num_vertices :
  81. mpl::size<typename vertices<Graph>::type>
  82. {};
  83. // EdgeListGraph
  84. template<typename Graph>
  85. struct edges :
  86. detail::produce_edge_set<typename Graph::representation, typename Graph::data>
  87. {};
  88. template<typename Graph>
  89. struct num_edges :
  90. mpl::size<typename edges<Graph>::type>
  91. {};
  92. // source and target are defined in IncidenceGraph
  93. } // mpl_graph
  94. } // msm
  95. } // boost
  96. #endif // BOOST_MSM_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED