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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/mpl/eval_if.hpp>
12 #include <boost/mpl/identity.hpp>
13 #include <boost/mpl/equal_to.hpp>
14 #include <boost/mpl/size.hpp>
15 #include <boost/mpl/front.hpp>
16 #include <boost/mpl/advance.hpp>
17 #include <boost/mpl/find.hpp>
18 #include <boost/mpl/push_front.hpp>
19 #include <boost/mpl/pop_front.hpp>
20 #include <boost/mpl/erase.hpp>
21 #include <boost/mpl/reverse.hpp>
22 #include <boost/mpl/long.hpp>
35 template< class ContextList, class OutermostContextBase >
38 //////////////////////////////////////////////////////////////////////////////
39 template< class ContextList, class OutermostContextBase >
40 struct outer_constructor
42 typedef typename mpl::front< ContextList >::type to_construct;
43 typedef typename to_construct::context_ptr_type context_ptr_type;
44 typedef typename to_construct::inner_context_ptr_type
45 inner_context_ptr_type;
47 typedef typename to_construct::inner_initial_list inner_initial_list;
48 typedef typename mpl::pop_front< ContextList >::type inner_context_list;
49 typedef typename mpl::front< inner_context_list >::type::orthogonal_position
50 inner_orthogonal_position;
51 typedef typename mpl::advance<
52 typename mpl::begin< inner_initial_list >::type,
53 inner_orthogonal_position >::type to_construct_iter;
55 typedef typename mpl::erase<
58 typename mpl::end< inner_initial_list >::type
59 >::type first_inner_initial_list;
61 typedef typename mpl::erase<
63 typename mpl::begin< inner_initial_list >::type,
64 typename mpl::next< to_construct_iter >::type
65 >::type last_inner_initial_list;
67 static void construct(
68 const context_ptr_type & pContext,
69 OutermostContextBase & outermostContextBase )
71 const inner_context_ptr_type pInnerContext =
72 to_construct::shallow_construct( pContext, outermostContextBase );
73 to_construct::template deep_construct_inner<
74 first_inner_initial_list >( pInnerContext, outermostContextBase );
75 constructor< inner_context_list, OutermostContextBase >::construct(
76 pInnerContext, outermostContextBase );
77 to_construct::template deep_construct_inner<
78 last_inner_initial_list >( pInnerContext, outermostContextBase );
82 //////////////////////////////////////////////////////////////////////////////
83 template< class ContextList, class OutermostContextBase >
84 struct inner_constructor
86 typedef typename mpl::front< ContextList >::type to_construct;
87 typedef typename to_construct::context_ptr_type context_ptr_type;
89 static void construct(
90 const context_ptr_type & pContext,
91 OutermostContextBase & outermostContextBase )
93 to_construct::deep_construct( pContext, outermostContextBase );
97 //////////////////////////////////////////////////////////////////////////////
98 template< class ContextList, class OutermostContextBase >
99 struct constructor_impl : public mpl::eval_if<
100 mpl::equal_to< mpl::size< ContextList >, mpl::long_< 1 > >,
101 mpl::identity< inner_constructor< ContextList, OutermostContextBase > >,
102 mpl::identity< outer_constructor< ContextList, OutermostContextBase > > >
107 //////////////////////////////////////////////////////////////////////////////
108 template< class ContextList, class OutermostContextBase >
110 constructor_impl< ContextList, OutermostContextBase >::type {};
112 //////////////////////////////////////////////////////////////////////////////
113 template< class CommonContext, class DestinationState >
114 struct make_context_list
116 typedef typename mpl::reverse< typename mpl::push_front<
118 typename DestinationState::context_type_list,
120 typename DestinationState::context_type_list,
124 typename DestinationState::context_type_list
128 >::type >::type type;
133 } // namespace detail
134 } // namespace statechart