Chris@16: // Copyright 2008 Christophe Henry Chris@16: // henry UNDERSCORE christophe AT hotmail DOT com Chris@16: // This is an extended version of the state machine available in the boost::mpl library Chris@16: // Distributed under the same license as the original. Chris@16: // Copyright for the original version: Chris@16: // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed Chris@16: // under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_MSM_BACK_TOOLS_H Chris@16: #define BOOST_MSM_BACK_TOOLS_H Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace msm { namespace back Chris@16: { Chris@16: Chris@16: // fills the array passed in with the state names in the correct order Chris@16: // the array must be big enough. To know the needed size, use mpl::size Chris@16: // on fsm::generate_state_set Chris@16: template Chris@16: struct fill_state_names Chris@16: { Chris@16: fill_state_names(char const** names):m_names(names){} Chris@16: template Chris@16: void operator()(boost::msm::wrap const&) Chris@16: { Chris@16: m_names[get_state_id::value]= typeid(StateType).name(); Chris@16: } Chris@16: private: Chris@16: char const** m_names; Chris@16: }; Chris@16: Chris@16: // fills the typeid-generated name of the given state in the string passed as argument Chris@16: template Chris@16: struct get_state_name Chris@16: { Chris@16: get_state_name(std::string& name_to_fill, int state_id):m_name(name_to_fill),m_state_id(state_id){} Chris@16: template Chris@16: void operator()(boost::msm::wrap const&) Chris@16: { Chris@16: if (get_state_id::value == m_state_id) Chris@16: { Chris@16: m_name = typeid(StateType).name(); Chris@16: } Chris@16: } Chris@16: private: Chris@16: std::string& m_name; Chris@16: int m_state_id; Chris@16: }; Chris@16: Chris@16: // displays the typeid of the given Type Chris@16: struct display_type Chris@16: { Chris@16: template Chris@16: void operator()(boost::msm::wrap const&) Chris@16: { Chris@16: std::cout << typeid(Type).name() << std::endl; Chris@16: } Chris@16: }; Chris@16: Chris@16: } } }//boost::msm::back Chris@16: #endif //BOOST_MSM_BACK_TOOLS_H