constructor.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED
  2. #define BOOST_STATECHART_DETAIL_CONSTRUCTOR_HPP_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2002-2006 Andreas Huber Doenni
  5. // Distributed under the Boost Software License, Version 1.0. (See accompany-
  6. // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. //////////////////////////////////////////////////////////////////////////////
  8. #include <boost/mpl/eval_if.hpp>
  9. #include <boost/mpl/identity.hpp>
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/size.hpp>
  12. #include <boost/mpl/front.hpp>
  13. #include <boost/mpl/advance.hpp>
  14. #include <boost/mpl/find.hpp>
  15. #include <boost/mpl/push_front.hpp>
  16. #include <boost/mpl/pop_front.hpp>
  17. #include <boost/mpl/erase.hpp>
  18. #include <boost/mpl/reverse.hpp>
  19. #include <boost/mpl/long.hpp>
  20. namespace boost
  21. {
  22. namespace statechart
  23. {
  24. namespace detail
  25. {
  26. template< class ContextList, class OutermostContextBase >
  27. struct constructor;
  28. //////////////////////////////////////////////////////////////////////////////
  29. template< class ContextList, class OutermostContextBase >
  30. struct outer_constructor
  31. {
  32. typedef typename mpl::front< ContextList >::type to_construct;
  33. typedef typename to_construct::context_ptr_type context_ptr_type;
  34. typedef typename to_construct::inner_context_ptr_type
  35. inner_context_ptr_type;
  36. typedef typename to_construct::inner_initial_list inner_initial_list;
  37. typedef typename mpl::pop_front< ContextList >::type inner_context_list;
  38. typedef typename mpl::front< inner_context_list >::type::orthogonal_position
  39. inner_orthogonal_position;
  40. typedef typename mpl::advance<
  41. typename mpl::begin< inner_initial_list >::type,
  42. inner_orthogonal_position >::type to_construct_iter;
  43. typedef typename mpl::erase<
  44. inner_initial_list,
  45. to_construct_iter,
  46. typename mpl::end< inner_initial_list >::type
  47. >::type first_inner_initial_list;
  48. typedef typename mpl::erase<
  49. inner_initial_list,
  50. typename mpl::begin< inner_initial_list >::type,
  51. typename mpl::next< to_construct_iter >::type
  52. >::type last_inner_initial_list;
  53. static void construct(
  54. const context_ptr_type & pContext,
  55. OutermostContextBase & outermostContextBase )
  56. {
  57. const inner_context_ptr_type pInnerContext =
  58. to_construct::shallow_construct( pContext, outermostContextBase );
  59. to_construct::template deep_construct_inner<
  60. first_inner_initial_list >( pInnerContext, outermostContextBase );
  61. constructor< inner_context_list, OutermostContextBase >::construct(
  62. pInnerContext, outermostContextBase );
  63. to_construct::template deep_construct_inner<
  64. last_inner_initial_list >( pInnerContext, outermostContextBase );
  65. }
  66. };
  67. //////////////////////////////////////////////////////////////////////////////
  68. template< class ContextList, class OutermostContextBase >
  69. struct inner_constructor
  70. {
  71. typedef typename mpl::front< ContextList >::type to_construct;
  72. typedef typename to_construct::context_ptr_type context_ptr_type;
  73. static void construct(
  74. const context_ptr_type & pContext,
  75. OutermostContextBase & outermostContextBase )
  76. {
  77. to_construct::deep_construct( pContext, outermostContextBase );
  78. }
  79. };
  80. //////////////////////////////////////////////////////////////////////////////
  81. template< class ContextList, class OutermostContextBase >
  82. struct constructor_impl : public mpl::eval_if<
  83. mpl::equal_to< mpl::size< ContextList >, mpl::long_< 1 > >,
  84. mpl::identity< inner_constructor< ContextList, OutermostContextBase > >,
  85. mpl::identity< outer_constructor< ContextList, OutermostContextBase > > >
  86. {
  87. };
  88. //////////////////////////////////////////////////////////////////////////////
  89. template< class ContextList, class OutermostContextBase >
  90. struct constructor :
  91. constructor_impl< ContextList, OutermostContextBase >::type {};
  92. //////////////////////////////////////////////////////////////////////////////
  93. template< class CommonContext, class DestinationState >
  94. struct make_context_list
  95. {
  96. typedef typename mpl::reverse< typename mpl::push_front<
  97. typename mpl::erase<
  98. typename DestinationState::context_type_list,
  99. typename mpl::find<
  100. typename DestinationState::context_type_list,
  101. CommonContext
  102. >::type,
  103. typename mpl::end<
  104. typename DestinationState::context_type_list
  105. >::type
  106. >::type,
  107. DestinationState
  108. >::type >::type type;
  109. };
  110. } // namespace detail
  111. } // namespace statechart
  112. } // namespace boost
  113. #endif