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