Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 08:20: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 
0021 #include <boost/msm/front/common_states.hpp>
0022 #include <boost/msm/row_tags.hpp>
0023 //#include <boost/msm/back/metafunctions.hpp>
0024 
0025 namespace boost { namespace msm { namespace front
0026 {
0027 
0028 // transformation metafunction to end interrupt flags
0029 template <class Event>
0030 struct transform_to_end_interrupt
0031 {
0032     typedef boost::msm::EndInterruptFlag<Event> type;
0033 };
0034 // transform a sequence of events into another one of EndInterruptFlag<Event>
0035 template <class Events>
0036 struct apply_end_interrupt_flag
0037 {
0038     typedef typename
0039         ::boost::mpl::transform<
0040         Events,transform_to_end_interrupt< ::boost::mpl::placeholders::_1> >::type type;
0041 };
0042 // returns a mpl vector containing all end interrupt events if sequence, otherwise the same event
0043 template <class Event>
0044 struct get_interrupt_events
0045 {
0046     typedef typename ::boost::mpl::eval_if<
0047         ::boost::mpl::is_sequence<Event>,
0048         boost::msm::front::apply_end_interrupt_flag<Event>,
0049         boost::fusion::result_of::make_vector<boost::msm::EndInterruptFlag<Event> > >::type type;
0050 };
0051 
0052 template <class Events>
0053 struct build_interrupt_state_flag_list
0054 {
0055     typedef ::boost::fusion::vector<boost::msm::InterruptedFlag> first_part;
0056     typedef typename ::boost::fusion::result_of::as_vector<
0057         typename ::boost::fusion::result_of::insert_range<
0058             first_part,
0059             typename ::boost::fusion::result_of::end< first_part >::type,
0060             Events
0061          >::type
0062     >::type type;
0063 };
0064 
0065 struct no_sm_ptr 
0066 {
0067     // tags
0068     typedef ::boost::mpl::bool_<false>   needs_sm;
0069 };
0070 struct sm_ptr 
0071 {
0072     // tags
0073     typedef ::boost::mpl::bool_<true>    needs_sm;
0074 };
0075 // kept for backward compatibility
0076 struct NoSMPtr 
0077 {
0078     // tags
0079     typedef ::boost::mpl::bool_<false>   needs_sm;
0080 };
0081 struct SMPtr 
0082 {
0083     // tags
0084     typedef ::boost::mpl::bool_<true>    needs_sm;
0085 };
0086 
0087 // provides the typedefs and interface. Concrete states derive from it.
0088 // template argument: pointer-to-fsm policy
0089 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0090 struct state :  public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0091 {
0092     // tags
0093     // default: no flag
0094     typedef ::boost::fusion::vector0<>       flag_list;
0095     typedef ::boost::fusion::vector0<>       internal_flag_list;
0096     //default: no deferred events
0097     typedef ::boost::fusion::vector0<>       deferred_events;
0098 };
0099 
0100 // terminate state simply defines the TerminateFlag flag
0101 // template argument: pointer-to-fsm policy
0102 template<class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0103 struct terminate_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0104 {
0105     // tags
0106     typedef ::boost::fusion::vector0<>                               flag_list;
0107     typedef ::boost::fusion::vector< boost::msm::TerminateFlag>      internal_flag_list;
0108     //default: no deferred events
0109     typedef ::boost::fusion::vector0<>                               deferred_events;
0110 };
0111 
0112 // terminate state simply defines the InterruptedFlag and EndInterruptFlag<EndInterruptEvent> flags
0113 // template argument: event which ends the interrupt
0114 // template argument: pointer-to-fsm policy
0115 template <class EndInterruptEvent,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0116 struct interrupt_state : public boost::msm::front::detail::state_base<BASE>, SMPtrPolicy
0117 {
0118     // tags
0119     typedef ::boost::fusion::vector0<>                           flag_list;
0120     typedef typename boost::msm::front::build_interrupt_state_flag_list<
0121         typename boost::msm::front::get_interrupt_events<EndInterruptEvent>::type
0122     >::type internal_flag_list; 
0123 
0124     //default: no deferred events
0125     typedef ::boost::fusion::vector0<>                           deferred_events;
0126 };
0127 
0128 // not a state but a bunch of extra typedefs to handle direct entry into a composite state. To be derived from
0129 // template argument: zone index of this state
0130 template <int ZoneIndex=-1>
0131 struct explicit_entry 
0132 {
0133     typedef int explicit_entry_state;
0134     enum {zone_index=ZoneIndex};
0135 };
0136 
0137 // to be derived from. Makes a type an entry (pseudo) state. Actually an almost full-fledged state
0138 // template argument: containing composite
0139 // template argument: zone index of this state
0140 // template argument: pointer-to-fsm policy
0141 template<int ZoneIndex=-1,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0142 struct entry_pseudo_state
0143     :  public boost::msm::front::detail::state_base<BASE>,SMPtrPolicy
0144 {
0145     // tags
0146     typedef int                          pseudo_entry;
0147     enum {zone_index=ZoneIndex};
0148     typedef int explicit_entry_state;
0149     // default: no flag
0150     typedef ::boost::fusion::vector0<>       flag_list;
0151     typedef ::boost::fusion::vector0<>       internal_flag_list;
0152     //default: no deferred events
0153     typedef ::boost::fusion::vector0<>       deferred_events;
0154 };
0155 
0156 // to be derived from. Makes a state an exit (pseudo) state. Actually an almost full-fledged state
0157 // template argument: event to forward
0158 // template argument: pointer-to-fsm policy
0159 template<class Event,class BASE = default_base_state,class SMPtrPolicy = no_sm_ptr>
0160 struct exit_pseudo_state : public boost::msm::front::detail::state_base<BASE> , SMPtrPolicy
0161 {
0162     typedef Event       event;
0163     typedef BASE        Base;
0164     typedef SMPtrPolicy PtrPolicy;
0165     typedef int         pseudo_exit;
0166 
0167     // default: no flag
0168     typedef ::boost::fusion::vector0<>  flag_list;
0169     typedef ::boost::fusion::vector0<>  internal_flag_list;
0170     //default: no deferred events
0171     typedef ::boost::fusion::vector0<>  deferred_events;
0172 };
0173 
0174 }}}
0175 
0176 #endif //BOOST_MSM_FRONT_STATES_H
0177