Chris@16
|
1 // Copyright 2008 Christophe Henry
|
Chris@16
|
2 // henry UNDERSCORE christophe AT hotmail DOT com
|
Chris@16
|
3 // This is an extended version of the state machine available in the boost::mpl library
|
Chris@16
|
4 // Distributed under the same license as the original.
|
Chris@16
|
5 // Copyright for the original version:
|
Chris@16
|
6 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
|
Chris@16
|
7 // under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_MSM_FRONT_STATES_H
|
Chris@16
|
12 #define BOOST_MSM_FRONT_STATES_H
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/mpl/bool.hpp>
|
Chris@16
|
15 #include <boost/mpl/vector.hpp>
|
Chris@16
|
16 #include <boost/msm/front/common_states.hpp>
|
Chris@16
|
17 #include <boost/msm/row_tags.hpp>
|
Chris@16
|
18 #include <boost/msm/back/metafunctions.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace msm { namespace front
|
Chris@16
|
21 {
|
Chris@16
|
22
|
Chris@16
|
23 struct no_sm_ptr
|
Chris@16
|
24 {
|
Chris@16
|
25 // tags
|
Chris@16
|
26 typedef ::boost::mpl::bool_<false> needs_sm;
|
Chris@16
|
27 };
|
Chris@16
|
28 struct sm_ptr
|
Chris@16
|
29 {
|
Chris@16
|
30 // tags
|
Chris@16
|
31 typedef ::boost::mpl::bool_<true> needs_sm;
|
Chris@16
|
32 };
|
Chris@16
|
33 // kept for backward compatibility
|
Chris@16
|
34 struct NoSMPtr
|
Chris@16
|
35 {
|
Chris@16
|
36 // tags
|
Chris@16
|
37 typedef ::boost::mpl::bool_<false> needs_sm;
|
Chris@16
|
38 };
|
Chris@16
|
39 struct SMPtr
|
Chris@16
|
40 {
|
Chris@16
|
41 // tags
|
Chris@16
|
42 typedef ::boost::mpl::bool_<true> needs_sm;
|
Chris@16
|
43 };
|
Chris@16
|
44
|
Chris@16
|
45 // provides the typedefs and interface. Concrete states derive from it.
|
Chris@16
|
46 // template argument: pointer-to-fsm policy
|
Chris@16
|
47 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
|
Chris@16
|
48 struct state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
|
Chris@16
|
49 {
|
Chris@16
|
50 // tags
|
Chris@16
|
51 // default: no flag
|
Chris@16
|
52 typedef ::boost::mpl::vector0<> flag_list;
|
Chris@16
|
53 typedef ::boost::mpl::vector0<> internal_flag_list;
|
Chris@16
|
54 //default: no deferred events
|
Chris@16
|
55 typedef ::boost::mpl::vector0<> deferred_events;
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 // terminate state simply defines the TerminateFlag flag
|
Chris@16
|
59 // template argument: pointer-to-fsm policy
|
Chris@16
|
60 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
|
Chris@16
|
61 struct terminate_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
|
Chris@16
|
62 {
|
Chris@16
|
63 // tags
|
Chris@16
|
64 typedef ::boost::mpl::vector0<> flag_list;
|
Chris@16
|
65 typedef ::boost::mpl::vector< boost::msm::TerminateFlag> internal_flag_list;
|
Chris@16
|
66 //default: no deferred events
|
Chris@16
|
67 typedef ::boost::mpl::vector0<> deferred_events;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 // terminate state simply defines the InterruptedFlag and EndInterruptFlag<EndInterruptEvent> flags
|
Chris@16
|
71 // template argument: event which ends the interrupt
|
Chris@16
|
72 // template argument: pointer-to-fsm policy
|
Chris@16
|
73 template <class EndInterruptEvent,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
|
Chris@16
|
74 struct interrupt_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
|
Chris@16
|
75 {
|
Chris@16
|
76 // tags
|
Chris@16
|
77 typedef ::boost::mpl::vector0<> flag_list;
|
Chris@16
|
78 typedef typename boost::msm::back::build_interrupt_state_flag_list<
|
Chris@16
|
79 typename boost::msm::back::get_interrupt_events<EndInterruptEvent>::type
|
Chris@16
|
80 >::type internal_flag_list;
|
Chris@16
|
81
|
Chris@16
|
82 //default: no deferred events
|
Chris@16
|
83 typedef ::boost::mpl::vector0<> deferred_events;
|
Chris@16
|
84 };
|
Chris@16
|
85
|
Chris@16
|
86 // not a state but a bunch of extra typedefs to handle direct entry into a composite state. To be derived from
|
Chris@16
|
87 // template argument: zone index of this state
|
Chris@16
|
88 template <int ZoneIndex=-1>
|
Chris@16
|
89 struct explicit_entry
|
Chris@16
|
90 {
|
Chris@16
|
91 typedef int explicit_entry_state;
|
Chris@16
|
92 enum {zone_index=ZoneIndex};
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95 // to be derived from. Makes a type an entry (pseudo) state. Actually an almost full-fledged state
|
Chris@16
|
96 // template argument: containing composite
|
Chris@16
|
97 // template argument: zone index of this state
|
Chris@16
|
98 // template argument: pointer-to-fsm policy
|
Chris@16
|
99 template<int ZoneIndex=-1,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
|
Chris@16
|
100 struct entry_pseudo_state
|
Chris@16
|
101 : public boost::msm::front::detail::state_base<BASE>,SMPtrPolicy
|
Chris@16
|
102 {
|
Chris@16
|
103 // tags
|
Chris@16
|
104 typedef int pseudo_entry;
|
Chris@16
|
105 enum {zone_index=ZoneIndex};
|
Chris@16
|
106 typedef int explicit_entry_state;
|
Chris@16
|
107 // default: no flag
|
Chris@16
|
108 typedef ::boost::mpl::vector0<> flag_list;
|
Chris@16
|
109 typedef ::boost::mpl::vector0<> internal_flag_list;
|
Chris@16
|
110 //default: no deferred events
|
Chris@16
|
111 typedef ::boost::mpl::vector0<> deferred_events;
|
Chris@16
|
112 };
|
Chris@16
|
113
|
Chris@16
|
114 // to be derived from. Makes a state an exit (pseudo) state. Actually an almost full-fledged state
|
Chris@16
|
115 // template argument: event to forward
|
Chris@16
|
116 // template argument: pointer-to-fsm policy
|
Chris@16
|
117 template<class Event,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
|
Chris@16
|
118 struct exit_pseudo_state : public boost::msm::front::detail::state_base<BASE> , SMPtrPolicy
|
Chris@16
|
119 {
|
Chris@16
|
120 typedef Event event;
|
Chris@16
|
121 typedef BASE Base;
|
Chris@16
|
122 typedef SMPtrPolicy PtrPolicy;
|
Chris@16
|
123 typedef int pseudo_exit;
|
Chris@16
|
124
|
Chris@16
|
125 // default: no flag
|
Chris@16
|
126 typedef ::boost::mpl::vector0<> flag_list;
|
Chris@16
|
127 typedef ::boost::mpl::vector0<> internal_flag_list;
|
Chris@16
|
128 //default: no deferred events
|
Chris@16
|
129 typedef ::boost::mpl::vector0<> deferred_events;
|
Chris@16
|
130 };
|
Chris@16
|
131
|
Chris@16
|
132 }}}
|
Chris@16
|
133
|
Chris@16
|
134 #endif //BOOST_MSM_FRONT_STATES_H
|
Chris@16
|
135
|