Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:48:14

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_STATEMACHINE_DEF_H
0012 #define BOOST_MSM_FRONT_STATEMACHINE_DEF_H
0013 
0014 #include <exception>
0015 #include <boost/assert.hpp>
0016 
0017 #include <boost/mpl/vector.hpp>
0018 
0019 #include <boost/msm/row_tags.hpp>
0020 #include <boost/msm/back/common_types.hpp>
0021 #include <boost/msm/front/states.hpp>
0022 #include <boost/msm/front/completion_event.hpp>
0023 #include <boost/msm/front/common_states.hpp>
0024 
0025 namespace boost { namespace msm { namespace front
0026 {
0027 
0028 template<class Derived,class BaseState = default_base_state>
0029 struct state_machine_def :  public boost::msm::front::detail::state_base<BaseState>
0030 {
0031     // tags
0032     // default: no flag
0033     typedef ::boost::mpl::vector0<>               flag_list;
0034     typedef ::boost::mpl::vector0<>               internal_flag_list;
0035     //default: no deferred events
0036     typedef ::boost::mpl::vector0<>               deferred_events;
0037     // customization (message queue, exceptions)
0038     typedef ::boost::mpl::vector0<>               configuration;
0039 
0040     typedef BaseState                             BaseAllStates;
0041     template<
0042         typename T1
0043         , class Event
0044         , typename T2
0045         , void (Derived::*action)(Event const&)
0046     >
0047     struct a_row
0048     {
0049         typedef a_row_tag row_type_tag;
0050         typedef T1 Source;
0051         typedef T2 Target;
0052         typedef Event Evt;
0053         template <class FSM,class SourceState,class TargetState,class AllStates>
0054         static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState&,TargetState&, AllStates&)
0055         {
0056             // in this front-end, we don't need to know source and target states
0057             (fsm.*action)(evt);
0058             return ::boost::msm::back::HANDLED_TRUE;
0059         }
0060     };
0061 
0062     template<
0063         typename T1
0064         , class Event
0065         , typename T2
0066     >
0067     struct _row
0068     {
0069         typedef _row_tag row_type_tag;
0070         typedef T1 Source;
0071         typedef T2 Target;
0072         typedef Event Evt;
0073     };
0074 
0075     template<
0076         typename T1
0077         , class Event
0078         , typename T2
0079         , void (Derived::*action)(Event const&)
0080         , bool (Derived::*guard)(Event const&) 
0081     >
0082     struct row
0083     {
0084         typedef row_tag row_type_tag;
0085         typedef T1 Source;
0086         typedef T2 Target;
0087         typedef Event Evt;
0088         template <class FSM,class SourceState,class TargetState, class AllStates>
0089         static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0090         {
0091             // in this front-end, we don't need to know source and target states
0092             (fsm.*action)(evt);
0093             return ::boost::msm::back::HANDLED_TRUE;
0094         }
0095         template <class FSM,class SourceState,class TargetState,class AllStates>
0096         static bool guard_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0097         {
0098             // in this front-end, we don't need to know source and target states
0099             return (fsm.*guard)(evt);
0100         }
0101     };
0102     template<
0103         typename T1
0104         , class Event
0105         , typename T2
0106         , bool (Derived::*guard)(Event const&) 
0107     >
0108     struct g_row
0109     {
0110         typedef g_row_tag row_type_tag;
0111         typedef T1 Source;
0112         typedef T2 Target;
0113         typedef Event Evt;
0114         template <class FSM,class SourceState,class TargetState,class AllStates>
0115         static bool guard_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0116         {
0117             // in this front-end, we don't need to know source and target states
0118             return (fsm.*guard)(evt);
0119         }
0120     };
0121     // internal transitions
0122     template<
0123         typename T1
0124         , class Event
0125         , void (Derived::*action)(Event const&)
0126     >
0127     struct a_irow
0128     {
0129         typedef a_irow_tag row_type_tag;
0130         typedef T1 Source;
0131         typedef T1 Target;
0132         typedef Event Evt;
0133         template <class FSM,class SourceState,class TargetState,class AllStates>
0134         static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0135         {
0136             // in this front-end, we don't need to know source and target states
0137             (fsm.*action)(evt);
0138             return ::boost::msm::back::HANDLED_TRUE;
0139         }
0140     };
0141 
0142     template<
0143         typename T1
0144         , class Event
0145         , void (Derived::*action)(Event const&)
0146         , bool (Derived::*guard)(Event const&) 
0147     >
0148     struct irow
0149     {
0150         typedef irow_tag row_type_tag;
0151         typedef T1 Source;
0152         typedef T1 Target;
0153         typedef Event Evt;
0154         template <class FSM,class SourceState,class TargetState,class AllStates>
0155         static ::boost::msm::back::HandledEnum action_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0156         {
0157             // in this front-end, we don't need to know source and target states
0158             (fsm.*action)(evt);
0159             return ::boost::msm::back::HANDLED_TRUE;
0160         }
0161         template <class FSM,class SourceState,class TargetState,class AllStates>
0162         static bool guard_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0163         {
0164             // in this front-end, we don't need to know source and target states
0165             return (fsm.*guard)(evt);
0166         }
0167     };
0168     template<
0169         typename T1
0170         , class Event
0171         , bool (Derived::*guard)(Event const&) 
0172     >
0173     struct g_irow
0174     {
0175         typedef g_irow_tag row_type_tag;
0176         typedef T1 Source;
0177         typedef T1 Target;
0178         typedef Event Evt;
0179         template <class FSM,class SourceState,class TargetState,class AllStates>
0180         static bool guard_call(FSM& fsm,Event const& evt,SourceState&,TargetState&,AllStates&)
0181         {
0182             // in this front-end, we don't need to know source and target states
0183             return (fsm.*guard)(evt);
0184         }
0185     };
0186     // internal row withou action or guard. Does nothing except forcing the event to be ignored.
0187     template<
0188         typename T1
0189         , class Event
0190     >
0191     struct _irow
0192     {
0193         typedef _irow_tag row_type_tag;
0194         typedef T1 Source;
0195         typedef T1 Target;
0196         typedef Event Evt;
0197     };
0198 protected:
0199     // Default no-transition handler. Can be replaced in the Derived SM class.
0200     template <class FSM,class Event>
0201     void no_transition(Event const& ,FSM&, int )
0202     {
0203         BOOST_ASSERT(false);
0204     }
0205     // default exception handler. Can be replaced in the Derived SM class.
0206     template <class FSM,class Event>
0207     void exception_caught (Event const&,FSM&,std::exception& )
0208     {
0209         BOOST_ASSERT(false);
0210     }
0211 };
0212 
0213 
0214 } } }// boost::msm::front
0215 #endif //BOOST_MSM_FRONT_STATEMACHINE_DEF_H
0216