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)
11 #ifndef BOOST_MSM_FRONT_DETAILS_COMMON_STATES_H
12 #define BOOST_MSM_FRONT_DETAILS_COMMON_STATES_H
14 #include <boost/mpl/int.hpp>
16 #include <boost/mpl/vector.hpp>
17 #include <boost/fusion/container/map.hpp>
18 #include <boost/fusion/include/at_key.hpp>
19 #include <boost/type_traits/add_const.hpp>
21 namespace boost { namespace msm { namespace front {namespace detail
23 template <class Attributes= ::boost::fusion::map<> >
24 struct inherit_attributes
26 inherit_attributes():m_attributes(){}
27 inherit_attributes(Attributes const& the_attributes):m_attributes(the_attributes){}
28 // on the fly attribute creation capability
29 typedef Attributes attributes_type;
30 template <class Index>
31 typename ::boost::fusion::result_of::at_key<attributes_type,
33 get_attribute(Index const&)
35 return ::boost::fusion::at_key<Index>(m_attributes);
38 template <class Index>
39 typename ::boost::add_const<
40 typename ::boost::fusion::result_of::at_key<attributes_type,
42 get_attribute(Index const&)const
45 typename ::boost::add_const<
46 typename ::boost::fusion::result_of::at_key< attributes_type,
48 (::boost::fusion::at_key<Index>(m_attributes));
53 Attributes m_attributes;
56 // the interface for all states. Defines entry and exit functions. Overwrite to implement for any state needing it.
57 template<class USERBASE,class Attributes= ::boost::fusion::map<> >
58 struct state_base : public inherit_attributes<Attributes>, USERBASE
60 typedef USERBASE user_state_base;
61 typedef Attributes attributes_type;
63 // empty implementation for the states not wishing to define an entry condition
64 // will not be called polymorphic way
65 template <class Event,class FSM>
66 void on_entry(Event const& ,FSM&){}
67 template <class Event,class FSM>
68 void on_exit(Event const&,FSM& ){}
69 // default (empty) transition table;
70 typedef ::boost::mpl::vector0<> internal_transition_table;
71 typedef ::boost::mpl::vector0<> transition_table;
76 #endif //BOOST_MSM_FRONT_DETAILS_COMMON_STATES_H