]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/msm/include/boost/msm/front/euml/transformation.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / msm / include / boost / msm / front / euml / transformation.hpp
1 // Copyright 2008 Christophe Henry
2 // henry UNDERSCORE christophe AT hotmail DOT com
3 // This is an extended version of the state machine available in the boost::mpl library
4 // Distributed under the same license as the original.
5 // Copyright for the original version:
6 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
7 // under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_MSM_FRONT_EUML_TRANSFORMATION_H
12 #define BOOST_MSM_FRONT_EUML_TRANSFORMATION_H
13
14 #include <algorithm>
15 #include <boost/msm/front/euml/common.hpp>
16
17 namespace boost { namespace msm { namespace front { namespace euml
18 {
19 #ifdef __STL_CONFIG_H
20 BOOST_MSM_EUML_FUNCTION(FillN_ , std::fill_n , fill_n_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
21 BOOST_MSM_EUML_FUNCTION(Rotate_ , std::rotate , rotate_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
22 BOOST_MSM_EUML_FUNCTION(GenerateN_ , std::generate_n , generate_n_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
23
24 #else
25 BOOST_MSM_EUML_FUNCTION(FillN_ , std::fill_n , fill_n_ , void , void )
26 BOOST_MSM_EUML_FUNCTION(Rotate_ , std::rotate , rotate_ , void , void )
27 BOOST_MSM_EUML_FUNCTION(GenerateN_ , std::generate_n , generate_n_ , void , void )
28 #endif
29
30 BOOST_MSM_EUML_FUNCTION(Copy_ , std::copy , copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
31 BOOST_MSM_EUML_FUNCTION(CopyBackward_ , std::copy_backward , copy_backward_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
32 BOOST_MSM_EUML_FUNCTION(Reverse_ , std::reverse , reverse_ , void , void )
33 BOOST_MSM_EUML_FUNCTION(ReverseCopy_ , std::reverse_copy , reverse_copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
34 BOOST_MSM_EUML_FUNCTION(Remove_ , std::remove , remove_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
35 BOOST_MSM_EUML_FUNCTION(RemoveIf_ , std::remove_if , remove_if_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
36 BOOST_MSM_EUML_FUNCTION(RemoveCopy_ , std::remove_copy , remove_copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
37 BOOST_MSM_EUML_FUNCTION(RemoveCopyIf_ , std::remove_copy_if , remove_copy_if_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
38 BOOST_MSM_EUML_FUNCTION(Fill_ , std::fill , fill_ , void , void )
39 BOOST_MSM_EUML_FUNCTION(Generate_ , std::generate , generate_ , void , void )
40 BOOST_MSM_EUML_FUNCTION(Unique_ , std::unique , unique_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
41 BOOST_MSM_EUML_FUNCTION(UniqueCopy_ , std::unique_copy , unique_copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
42 BOOST_MSM_EUML_FUNCTION(RandomShuffle_ , std::random_shuffle , random_shuffle_ , void , void )
43 BOOST_MSM_EUML_FUNCTION(RotateCopy_ , std::rotate_copy , rotate_copy_ , RESULT_TYPE_PARAM4 , RESULT_TYPE2_PARAM4 )
44 BOOST_MSM_EUML_FUNCTION(Partition_ , std::partition , partition_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
45 BOOST_MSM_EUML_FUNCTION(StablePartition_ , std::stable_partition , stable_partition_ , RESULT_TYPE_PARAM1 , RESULT_TYPE2_PARAM1 )
46 BOOST_MSM_EUML_FUNCTION(Sort_ , std::sort , sort_ , void , void )
47 BOOST_MSM_EUML_FUNCTION(StableSort_ , std::stable_sort , stable_sort_ , void , void )
48 BOOST_MSM_EUML_FUNCTION(PartialSort_ , std::partial_sort , partial_sort_ , void , void )
49 BOOST_MSM_EUML_FUNCTION(PartialSortCopy_ , std::partial_sort_copy , partial_sort_copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
50 BOOST_MSM_EUML_FUNCTION(NthElement_ , std::nth_element , nth_element_ , void , void )
51 BOOST_MSM_EUML_FUNCTION(Merge_ , std::merge , merge_ , RESULT_TYPE_PARAM5 , RESULT_TYPE2_PARAM5 )
52 BOOST_MSM_EUML_FUNCTION(InplaceMerge_ , std::inplace_merge , inplace_merge_ , void , void )
53 BOOST_MSM_EUML_FUNCTION(SetUnion_ , std::set_union , set_union_ , RESULT_TYPE_PARAM5 , RESULT_TYPE2_PARAM5 )
54 BOOST_MSM_EUML_FUNCTION(PushHeap_ , std::push_heap , push_heap_ , void , void )
55 BOOST_MSM_EUML_FUNCTION(PopHeap_ , std::pop_heap , pop_heap_ , void , void )
56 BOOST_MSM_EUML_FUNCTION(MakeHeap_ , std::make_heap , make_heap_ , void , void )
57 BOOST_MSM_EUML_FUNCTION(SortHeap_ , std::sort_heap , sort_heap_ , void , void )
58 BOOST_MSM_EUML_FUNCTION(NextPermutation_ , std::next_permutation , next_permutation_ , bool , bool )
59 BOOST_MSM_EUML_FUNCTION(PrevPermutation_ , std::prev_permutation , prev_permutation_ , bool , bool )
60 BOOST_MSM_EUML_FUNCTION(InnerProduct_ , std::inner_product , inner_product_ , RESULT_TYPE_PARAM4 , RESULT_TYPE2_PARAM4 )
61 BOOST_MSM_EUML_FUNCTION(PartialSum_ , std::partial_sum , partial_sum_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
62 BOOST_MSM_EUML_FUNCTION(AdjacentDifference_ , std::adjacent_difference , adjacent_difference_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
63 BOOST_MSM_EUML_FUNCTION(Replace_ , std::replace , replace_ , void , void )
64 BOOST_MSM_EUML_FUNCTION(ReplaceIf_ , std::replace_if , replace_if_ , void , void )
65 BOOST_MSM_EUML_FUNCTION(ReplaceCopy_ , std::replace_copy , replace_copy_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
66 BOOST_MSM_EUML_FUNCTION(ReplaceCopyIf_ , std::replace_copy_if , replace_copy_if_ , RESULT_TYPE_PARAM3 , RESULT_TYPE2_PARAM3 )
67
68
69
70 template <class T>
71 struct BackInserter_ : euml_action<BackInserter_<T> >
72 {
73 template <class Event,class FSM,class STATE >
74 struct state_action_result
75 {
76 typedef std::back_insert_iterator<
77 typename ::boost::remove_reference<
78 typename get_result_type2<T,Event,FSM,STATE>::type>::type> type;
79 };
80 template <class EVT,class FSM,class SourceState,class TargetState>
81 struct transition_action_result
82 {
83 typedef std::back_insert_iterator<
84 typename ::boost::remove_reference<
85 typename get_result_type<T,EVT,FSM,SourceState,TargetState>::type>::type> type;
86 };
87 typedef ::boost::mpl::set<state_action_tag,action_tag> tag_type;
88
89 template <class EVT,class FSM,class SourceState,class TargetState>
90 typename ::boost::enable_if<
91 typename ::boost::mpl::has_key<
92 typename T::tag_type,action_tag>::type,
93 typename transition_action_result<EVT,FSM,SourceState,TargetState>::type >::type
94 operator()(EVT const& evt, FSM& fsm,SourceState& src,TargetState& tgt)const
95 {
96 return std::back_inserter(T()(evt,fsm,src,tgt));
97 }
98 template <class Event,class FSM,class STATE>
99 typename ::boost::enable_if<
100 typename ::boost::mpl::has_key<
101 typename T::tag_type,state_action_tag>::type,
102 typename state_action_result<Event,FSM,STATE>::type >::type
103 operator()(Event const& evt,FSM& fsm,STATE& state )const
104 {
105 return std::back_inserter(T()(evt,fsm,state));
106 }
107 };
108
109 struct back_inserter_tag {};
110 struct BackInserter_Helper: proto::extends< proto::terminal<back_inserter_tag>::type, BackInserter_Helper, boost::msm::sm_domain>
111 {
112 BackInserter_Helper(){}
113 template <class Arg1,class Arg2,class Arg3,class Arg4,class Arg5
114 #ifdef BOOST_MSVC
115 ,class Arg6
116 #endif
117 >
118 struct In
119 {
120 typedef BackInserter_<Arg1> type;
121 };
122 };
123 BackInserter_Helper const back_inserter_;
124
125 template <class T>
126 struct FrontInserter_ : euml_action<FrontInserter_<T> >
127 {
128 template <class Event,class FSM,class STATE >
129 struct state_action_result
130 {
131 typedef std::front_insert_iterator<
132 typename ::boost::remove_reference<
133 typename get_result_type2<T,Event,FSM,STATE>::type>::type> type;
134 };
135 template <class EVT,class FSM,class SourceState,class TargetState>
136 struct transition_action_result
137 {
138 typedef std::front_insert_iterator<
139 typename ::boost::remove_reference<
140 typename get_result_type<T,EVT,FSM,SourceState,TargetState>::type>::type> type;
141 };
142 typedef ::boost::mpl::set<state_action_tag,action_tag> tag_type;
143
144 template <class EVT,class FSM,class SourceState,class TargetState>
145 typename ::boost::enable_if<
146 typename ::boost::mpl::has_key<
147 typename T::tag_type,action_tag>::type,
148 typename transition_action_result<EVT,FSM,SourceState,TargetState>::type >::type
149 operator()(EVT const& evt, FSM& fsm,SourceState& src,TargetState& tgt)const
150 {
151 return std::front_inserter(T()(evt,fsm,src,tgt));
152 }
153 template <class Event,class FSM,class STATE>
154 typename ::boost::enable_if<
155 typename ::boost::mpl::has_key<
156 typename T::tag_type,state_action_tag>::type,
157 typename state_action_result<Event,FSM,STATE>::type >::type
158 operator()(Event const& evt,FSM& fsm,STATE& state )const
159 {
160 return std::front_inserter(T()(evt,fsm,state));
161 }
162 };
163
164 struct front_inserter_tag {};
165 struct FrontInserter_Helper: proto::extends< proto::terminal<front_inserter_tag>::type, FrontInserter_Helper, boost::msm::sm_domain>
166 {
167 FrontInserter_Helper(){}
168 template <class Arg1,class Arg2,class Arg3,class Arg4,class Arg5
169 #ifdef BOOST_MSVC
170 ,class Arg6
171 #endif
172 >
173 struct In
174 {
175 typedef FrontInserter_<Arg1> type;
176 };
177 };
178 FrontInserter_Helper const front_inserter_;
179
180 template <class T,class Pos>
181 struct Inserter_ : euml_action<Inserter_<T,Pos> >
182 {
183 template <class Event,class FSM,class STATE >
184 struct state_action_result
185 {
186 typedef std::insert_iterator<
187 typename ::boost::remove_reference<
188 typename get_result_type2<T,Event,FSM,STATE>::type>::type> type;
189 };
190 template <class EVT,class FSM,class SourceState,class TargetState>
191 struct transition_action_result
192 {
193 typedef std::insert_iterator<
194 typename ::boost::remove_reference<
195 typename get_result_type<T,EVT,FSM,SourceState,TargetState>::type>::type> type;
196 };
197 typedef ::boost::mpl::set<state_action_tag,action_tag> tag_type;
198
199 template <class EVT,class FSM,class SourceState,class TargetState>
200 typename ::boost::enable_if<
201 typename ::boost::mpl::has_key<
202 typename T::tag_type,action_tag>::type,
203 typename transition_action_result<EVT,FSM,SourceState,TargetState>::type >::type
204 operator()(EVT const& evt, FSM& fsm,SourceState& src,TargetState& tgt)const
205 {
206 return std::inserter(T()(evt,fsm,src,tgt),Pos()(evt,fsm,src,tgt));
207 }
208 template <class Event,class FSM,class STATE>
209 typename ::boost::enable_if<
210 typename ::boost::mpl::has_key<
211 typename T::tag_type,state_action_tag>::type,
212 typename state_action_result<Event,FSM,STATE>::type >::type
213 operator()(Event const& evt,FSM& fsm,STATE& state )const
214 {
215 return std::inserter(T()(evt,fsm,state),Pos()(evt,fsm,state));
216 }
217 };
218
219 struct inserter_tag {};
220 struct Inserter_Helper: proto::extends< proto::terminal<inserter_tag>::type, Inserter_Helper, boost::msm::sm_domain>
221 {
222 Inserter_Helper(){}
223 template <class Arg1,class Arg2,class Arg3,class Arg4,class Arg5
224 #ifdef BOOST_MSVC
225 ,class Arg6
226 #endif
227 >
228 struct In
229 {
230 typedef Inserter_<Arg1,Arg2> type;
231 };
232 };
233 Inserter_Helper const inserter_;
234
235 template <class Param1, class Param2, class Param3, class Param4, class Param5, class Enable=void >
236 struct Transform_ : euml_action<Transform_<Param1,Param2,Param3,Param4,Param5,Enable> >
237 {
238 };
239
240 template <class Param1, class Param2, class Param3, class Param4, class Param5>
241 struct Transform_<Param1,Param2,Param3,Param4,Param5,
242 typename ::boost::enable_if<typename ::boost::is_same<Param5,void>::type >::type>
243 : euml_action<Transform_<Param1,Param2,Param3,Param4,Param5> >
244 {
245 template <class Event,class FSM,class STATE >
246 struct state_action_result
247 {
248 typedef typename get_result_type2<Param3,Event,FSM,STATE>::type type;
249 };
250 template <class EVT,class FSM,class SourceState,class TargetState>
251 struct transition_action_result
252 {
253 typedef typename get_result_type<Param3,EVT,FSM,SourceState,TargetState>::type type;
254 };
255 typedef ::boost::mpl::set<state_action_tag,action_tag> tag_type;
256
257 template <class EVT,class FSM,class SourceState,class TargetState>
258 typename ::boost::enable_if<
259 typename ::boost::mpl::has_key<
260 typename Param1::tag_type,action_tag>::type,
261 typename transition_action_result<EVT,FSM,SourceState,TargetState>::type >::type
262 operator()(EVT const& evt, FSM& fsm,SourceState& src,TargetState& tgt)const
263 {
264 return std::transform(Param1()(evt,fsm,src,tgt),Param2()(evt,fsm,src,tgt),Param3()(evt,fsm,src,tgt),
265 Param4()(evt,fsm,src,tgt));
266 }
267 template <class Event,class FSM,class STATE>
268 typename ::boost::enable_if<
269 typename ::boost::mpl::has_key<
270 typename Param1::tag_type,state_action_tag>::type,
271 typename state_action_result<Event,FSM,STATE>::type >::type
272 operator()(Event const& evt,FSM& fsm,STATE& state )const
273 {
274 return std::transform(Param1()(evt,fsm,state),Param2()(evt,fsm,state),Param3()(evt,fsm,state),
275 Param4()(evt,fsm,state));
276 }
277 };
278
279 template <class Param1, class Param2, class Param3, class Param4, class Param5>
280 struct Transform_<Param1,Param2,Param3,Param4,Param5,
281 typename ::boost::disable_if<typename ::boost::is_same<Param5,void>::type >::type>
282 : euml_action<Transform_<Param1,Param2,Param3,Param4,Param5> >
283 {
284 template <class Event,class FSM,class STATE >
285 struct state_action_result
286 {
287 typedef typename get_result_type2<Param4,Event,FSM,STATE>::type type;
288 };
289 template <class EVT,class FSM,class SourceState,class TargetState>
290 struct transition_action_result
291 {
292 typedef typename get_result_type<Param4,EVT,FSM,SourceState,TargetState>::type type;
293 };
294 typedef ::boost::mpl::set<state_action_tag,action_tag> tag_type;
295
296 template <class EVT,class FSM,class SourceState,class TargetState>
297 typename ::boost::enable_if<
298 typename ::boost::mpl::has_key<
299 typename Param1::tag_type,action_tag>::type,
300 typename transition_action_result<EVT,FSM,SourceState,TargetState>::type >::type
301 operator()(EVT const& evt, FSM& fsm,SourceState& src,TargetState& tgt)const
302 {
303 return std::transform (Param1()(evt,fsm,src,tgt),Param2()(evt,fsm,src,tgt),Param3()(evt,fsm,src,tgt),
304 Param4()(evt,fsm,src,tgt),Param5()(evt,fsm,src,tgt));
305 }
306 template <class Event,class FSM,class STATE>
307 typename ::boost::enable_if<
308 typename ::boost::mpl::has_key<
309 typename Param1::tag_type,state_action_tag>::type,
310 typename state_action_result<Event,FSM,STATE>::type >::type
311 operator()(Event const& evt,FSM& fsm,STATE& state )const
312 {
313 return std::transform (Param1()(evt,fsm,state),Param2()(evt,fsm,state),Param3()(evt,fsm,state),
314 Param4()(evt,fsm,state),Param5()(evt,fsm,state));
315 }
316 };
317 struct transform_tag {};
318 struct Transform_Helper: proto::extends< proto::terminal<transform_tag>::type, Transform_Helper, boost::msm::sm_domain>
319 {
320 Transform_Helper(){}
321 template <class Arg1,class Arg2,class Arg3,class Arg4,class Arg5
322 #ifdef BOOST_MSVC
323 ,class Arg6
324 #endif
325 >
326 struct In
327 {
328 typedef Transform_<Arg1,Arg2,Arg3,Arg4,Arg5> type;
329 };
330 };
331 Transform_Helper const transform_;
332
333 }}}}
334
335 #endif //BOOST_MSM_FRONT_EUML_TRANSFORMATION_H