Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:51:51

0001 // Copyright 2008 Christophe Henry
0002 // henry UNDERSCORE christophe AT hotmail DOT com
0003 // This is an extended version of the state machine available in the boost::mpl library
0004 // Distributed under the same license as the original.
0005 // Copyright for the original version:
0006 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
0007 // under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_MSM_FRONT_STATES_H
0012 #define BOOST_MSM_FRONT_STATES_H
0013 
0014 #include <boost/mpl/bool.hpp>
0015 #include <boost/mpl/vector.hpp>
0016 #include <boost/mpl/transform.hpp>
0017 
0018 #include <boost/fusion/include/vector.hpp>
0019 #include <boost/fusion/include/make_vector.hpp>
0020 #include <boost/fusion/include/insert_range.hpp>
0021 
0022 #include <boost/msm/front/common_states.hpp>
0023 #include <boost/msm/row_tags.hpp>
0024 //#include <boost/msm/back/metafunctions.hpp>
0025 
0026 namespace boost { namespace msm { namespace front
0027 {
0028 
0029 // transformation metafunction to end interrupt flags
0030 template <class Event>
0031 struct transform_to_end_interrupt
0032 {
0033     typedef boost::msm::EndInterruptFlag<Event> type;
0034 };
0035 // transform a sequence of events into another one of EndInterruptFlag<Event>
0036 template <class Events>
0037 struct apply_end_interrupt_flag
0038 {
0039     typedef typename
0040         ::boost::mpl::transform<
0041         Events,transform_to_end_interrupt< ::boost::mpl::placeholders::_1> >::type type;
0042 };
0043 // returns a mpl vector containing all end interrupt events if sequence, otherwise the same event
0044 template <class Event>
0045 struct get_interrupt_events
0046 {
0047     typedef typename ::boost::mpl::eval_if<
0048         ::boost::mpl::is_sequence<Event>,
0049         boost::msm::front::apply_end_interrupt_flag<Event>,
0050         boost::fusion::result_of::make_vector<boost::msm::EndInterruptFlag<Event> > >::type type;
0051 };
0052 
0053 template <class Events>
0054 struct build_interrupt_state_flag_list
0055 {
0056     typedef ::boost::fusion::vector<boost::msm::InterruptedFlag> first_part;
0057     typedef typename ::boost::fusion::result_of::as_vector<
0058         typename ::boost::fusion::result_of::insert_range<
0059             first_part,
0060             typename ::boost::fusion::result_of::end< first_part >::type,
0061             Events
0062          >::type
0063     >::type type;
0064 };
0065 
0066 struct no_sm_ptr 
0067 {
0068     // tags
0069     typedef ::boost::mpl::bool_<false>   needs_sm;
0070 };
0071 struct sm_ptr 
0072 {
0073     // tags
0074     typedef ::boost::mpl::bool_<true>    needs_sm;
0075 };
0076 // kept for backward compatibility
0077 struct NoSMPtr 
0078 {
0079     // tags
0080     typedef ::boost::mpl::bool_<false>   needs_sm;
0081 };
0082 struct SMPtr 
0083 {
0084     // tags
0085     typedef ::boost::mpl::bool_<true>    needs_sm;
0086 };
0087 
0088 // provides the typedefs and interface. Concrete states derive from it.
0089 // template argument: pointer-to-fsm policy
0090 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0091 struct state :  public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0092 {
0093     // tags
0094     // default: no flag
0095     typedef ::boost::fusion::vector0<>       flag_list;
0096     typedef ::boost::fusion::vector0<>       internal_flag_list;
0097     //default: no deferred events
0098     typedef ::boost::fusion::vector0<>       deferred_events;
0099 };
0100 
0101 // terminate state simply defines the TerminateFlag flag
0102 // template argument: pointer-to-fsm policy
0103 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0104 struct terminate_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0105 {
0106     // tags
0107     typedef ::boost::fusion::vector0<>                               flag_list;
0108     typedef ::boost::fusion::vector< boost::msm::TerminateFlag>      internal_flag_list;
0109     //default: no deferred events
0110     typedef ::boost::fusion::vector0<>                               deferred_events;
0111 };
0112 
0113 // terminate state simply defines the InterruptedFlag and EndInterruptFlag<EndInterruptEvent> flags
0114 // template argument: event which ends the interrupt
0115 // template argument: pointer-to-fsm policy
0116 template <class EndInterruptEvent,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0117 struct interrupt_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0118 {
0119     // tags
0120     typedef ::boost::fusion::vector0<>                           flag_list;
0121     typedef typename boost::msm::front::build_interrupt_state_flag_list<
0122         typename boost::msm::front::get_interrupt_events<EndInterruptEvent>::type
0123     >::type internal_flag_list; 
0124 
0125     //default: no deferred events
0126     typedef ::boost::fusion::vector0<>                           deferred_events;
0127 };
0128 
0129 // not a state but a bunch of extra typedefs to handle direct entry into a composite state. To be derived from
0130 // template argument: zone index of this state
0131 template <int ZoneIndex=-1>
0132 struct explicit_entry 
0133 {
0134     typedef int explicit_entry_state;
0135     enum {zone_index=ZoneIndex};
0136 };
0137 
0138 // to be derived from. Makes a type an entry (pseudo) state. Actually an almost full-fledged state
0139 // template argument: containing composite
0140 // template argument: zone index of this state
0141 // template argument: pointer-to-fsm policy
0142 template<int ZoneIndex=-1,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0143 struct entry_pseudo_state
0144     :  public boost::msm::front::detail::state_base<BASE>,SMPtrPolicy
0145 {
0146     // tags
0147     typedef int                          pseudo_entry;
0148     enum {zone_index=ZoneIndex};
0149     typedef int explicit_entry_state;
0150     // default: no flag
0151     typedef ::boost::fusion::vector0<>       flag_list;
0152     typedef ::boost::fusion::vector0<>       internal_flag_list;
0153     //default: no deferred events
0154     typedef ::boost::fusion::vector0<>       deferred_events;
0155 };
0156 
0157 // to be derived from. Makes a state an exit (pseudo) state. Actually an almost full-fledged state
0158 // template argument: event to forward
0159 // template argument: pointer-to-fsm policy
0160 template<class Event,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0161 struct exit_pseudo_state : public boost::msm::front::detail::state_base<BASE> , SMPtrPolicy
0162 {
0163     typedef Event       event;
0164     typedef BASE        Base;
0165     typedef SMPtrPolicy PtrPolicy;
0166     typedef int         pseudo_exit;
0167 
0168     // default: no flag
0169     typedef ::boost::fusion::vector0<>  flag_list;
0170     typedef ::boost::fusion::vector0<>  internal_flag_list;
0171     //default: no deferred events
0172     typedef ::boost::fusion::vector0<>  deferred_events;
0173 };
0174 
0175 }}}
0176 
0177 #endif //BOOST_MSM_FRONT_STATES_H
0178