incidence_list_graph.ipp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef BOOST_MSM_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED
  5. #define BOOST_MSM_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED
  6. // these metafunctions provide the metadata structures needed by the public interface
  7. // in mpl_graph.hpp
  8. #include <boost/mpl/map.hpp>
  9. #include <boost/mpl/vector.hpp>
  10. #include <boost/mpl/copy.hpp>
  11. #include <boost/mpl/vector.hpp>
  12. #include <boost/mpl/next.hpp>
  13. #include <boost/mpl/front.hpp>
  14. #include <boost/mpl/back.hpp>
  15. #include <boost/mpl/deref.hpp>
  16. #include <boost/mpl/if.hpp>
  17. #include <boost/mpl/size.hpp>
  18. #include <boost/mpl/void.hpp>
  19. #include <boost/mpl/erase_key.hpp>
  20. #include <boost/mpl/has_key.hpp>
  21. #include <boost/mpl/inserter.hpp>
  22. #include <boost/mpl/back_inserter.hpp>
  23. #include <boost/mpl/set.hpp>
  24. #include <boost/mpl/insert.hpp>
  25. #include <boost/mpl/transform.hpp>
  26. #include <boost/mpl/pair.hpp>
  27. #include <boost/mpl/size.hpp>
  28. #include <boost/mpl/fold.hpp>
  29. #include <boost/mpl/transform.hpp>
  30. #include <boost/mpl/at.hpp>
  31. #include <boost/mpl/push_back.hpp>
  32. #include <boost/mpl/filter_view.hpp>
  33. #include <boost/mpl/transform_view.hpp>
  34. #include <boost/mpl/equal.hpp>
  35. #include <boost/type_traits.hpp>
  36. namespace boost {
  37. namespace msm {
  38. namespace mpl_graph {
  39. namespace detail {
  40. // tag to identify this graph implementation (not defined)
  41. struct incidence_list_tag;
  42. // clarifiers
  43. template<typename EST> struct fetch_edge :
  44. mpl::front<EST> {};
  45. template<typename EST> struct fetch_source :
  46. mpl::deref<typename mpl::next<typename mpl::begin<EST>::type>::type> {};
  47. template<typename EST> struct fetch_target :
  48. mpl::back<EST> {};
  49. // Edge->Target map for an Source for out_*, adjacent_vertices
  50. template<typename Source, typename ESTSequence>
  51. struct produce_out_map<incidence_list_tag, Source, ESTSequence> :
  52. mpl::fold<typename mpl::filter_view<ESTSequence, boost::is_same<fetch_source<mpl::_1>,Source> >::type,
  53. mpl::map<>,
  54. mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,fetch_target<mpl::_2> > > >
  55. {};
  56. // Edge->Source map for a Target for in_*, degree
  57. template<typename Target, typename ESTSequence>
  58. struct produce_in_map<incidence_list_tag, Target, ESTSequence> :
  59. mpl::fold<typename mpl::filter_view<ESTSequence,
  60. boost::is_same<fetch_target<mpl::_1>,Target> >::type,
  61. mpl::map<>,
  62. mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,fetch_source<mpl::_2> > > >
  63. {};
  64. // Edge->pair<Source,Target> map for source, target
  65. template<typename ESTSequence>
  66. struct produce_edge_st_map<incidence_list_tag, ESTSequence> :
  67. mpl::fold<ESTSequence,
  68. mpl::map<>,
  69. mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,
  70. mpl::pair<fetch_source<mpl::_2>,
  71. fetch_target<mpl::_2> > > > >
  72. {};
  73. // Vertex set for VertexListGraph
  74. template<typename ESTSequence>
  75. struct produce_vertex_set<incidence_list_tag, ESTSequence> :
  76. mpl::fold<ESTSequence,
  77. typename mpl::fold<ESTSequence,
  78. mpl::set<>,
  79. mpl::insert<mpl::_1,fetch_target<mpl::_2> >
  80. >::type,
  81. mpl::insert<mpl::_1, fetch_source<mpl::_2> > >
  82. {};
  83. // Edge set for EdgeListGraph
  84. template<typename ESTSequence>
  85. struct produce_edge_set<incidence_list_tag, ESTSequence> :
  86. mpl::fold<ESTSequence,
  87. mpl::set<>,
  88. mpl::insert<mpl::_1,fetch_edge<mpl::_2> > >
  89. {};
  90. }
  91. }
  92. }
  93. }
  94. #endif // BOOST_MSM_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED