| 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_DETAILS_COMMON_STATES_H |
| 12 | #define BOOST_MSM_FRONT_DETAILS_COMMON_STATES_H |
| 13 | |
| 14 | #include <boost/mpl/int.hpp> |
| 15 | |
| 16 | #include <boost/mpl/vector.hpp> |
| 17 | #include <boost/fusion/container/vector.hpp> |
| 18 | #include <boost/fusion/container/map.hpp> |
| 19 | #include <boost/fusion/include/at_key.hpp> |
| 20 | #include <boost/type_traits/add_const.hpp> |
| 21 | |
| 22 | namespace boost { namespace msm { namespace front {namespace detail |
| 23 | { |
| 24 | template <class Attributes= ::boost::fusion::map<> > |
| 25 | struct inherit_attributes |
| 26 | { |
| 27 | inherit_attributes():m_attributes(){} |
| 28 | inherit_attributes(Attributes const& the_attributes):m_attributes(the_attributes){} |
| 29 | // on the fly attribute creation capability |
| 30 | typedef Attributes attributes_type; |
| 31 | template <class Index> |
| 32 | typename ::boost::fusion::result_of::at_key<attributes_type, |
| 33 | Index>::type |
| 34 | get_attribute(Index const&) |
| 35 | { |
| 36 | return ::boost::fusion::at_key<Index>(m_attributes); |
| 37 | } |
| 38 | |
| 39 | template <class Index> |
| 40 | typename ::boost::add_const< |
| 41 | typename ::boost::fusion::result_of::at_key<attributes_type, |
| 42 | Index>::type>::type |
| 43 | get_attribute(Index const&)const |
| 44 | { |
| 45 | return const_cast< |
| 46 | typename ::boost::add_const< |
| 47 | typename ::boost::fusion::result_of::at_key< attributes_type, |
| 48 | Index >::type>::type> |
| 49 | (::boost::fusion::at_key<Index>(m_attributes)); |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | // attributes |
| 54 | Attributes m_attributes; |
| 55 | }; |
| 56 | |
| 57 | // the interface for all states. Defines entry and exit functions. Overwrite to implement for any state needing it. |
| 58 | template<class USERBASE,class Attributes= ::boost::fusion::map<> > |
| 59 | struct state_base : public inherit_attributes<Attributes>, USERBASE |
| 60 | { |
| 61 | typedef USERBASE user_state_base; |
| 62 | typedef Attributes attributes_type; |
| 63 | |
| 64 | // empty implementation for the states not wishing to define an entry condition |
| 65 | // will not be called polymorphic way |
| 66 | template <class Event,class FSM> |
| 67 | void on_entry(Event const& ,FSM&){} |
| 68 | template <class Event,class FSM> |
| 69 | void on_exit(Event const&,FSM& ){} |
| 70 | // default (empty) transition table; |
| 71 | typedef ::boost::mpl::vector<> internal_transition_table; |
| 72 | typedef ::boost::fusion::vector<> internal_transition_table11; |
| 73 | typedef ::boost::fusion::vector<> transition_table; |
| 74 | }; |
| 75 | |
| 76 | }}}} |
| 77 | |
| 78 | #endif //BOOST_MSM_FRONT_DETAILS_COMMON_STATES_H |
| 79 | |
| 80 | |