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