]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_BACK_TOOLS_H | |
12 | #define BOOST_MSM_BACK_TOOLS_H | |
13 | ||
14 | ||
15 | #include <string> | |
16 | #include <iostream> | |
17 | #include <boost/msm/back/common_types.hpp> | |
18 | #include <boost/msm/back/metafunctions.hpp> | |
19 | ||
20 | namespace boost { namespace msm { namespace back | |
21 | { | |
22 | ||
23 | // fills the array passed in with the state names in the correct order | |
24 | // the array must be big enough. To know the needed size, use mpl::size | |
25 | // on fsm::generate_state_set | |
26 | template <class stt> | |
27 | struct fill_state_names | |
28 | { | |
29 | fill_state_names(char const** names):m_names(names){} | |
30 | template <class StateType> | |
31 | void operator()(boost::msm::wrap<StateType> const&) | |
32 | { | |
33 | m_names[get_state_id<stt,StateType>::value]= typeid(StateType).name(); | |
34 | } | |
35 | private: | |
36 | char const** m_names; | |
37 | }; | |
38 | ||
39 | // fills the typeid-generated name of the given state in the string passed as argument | |
40 | template <class stt> | |
41 | struct get_state_name | |
42 | { | |
43 | get_state_name(std::string& name_to_fill, int state_id):m_name(name_to_fill),m_state_id(state_id){} | |
44 | template <class StateType> | |
45 | void operator()(boost::msm::wrap<StateType> const&) | |
46 | { | |
47 | if (get_state_id<stt,StateType>::value == m_state_id) | |
48 | { | |
49 | m_name = typeid(StateType).name(); | |
50 | } | |
51 | } | |
52 | private: | |
53 | std::string& m_name; | |
54 | int m_state_id; | |
55 | }; | |
56 | ||
57 | // displays the typeid of the given Type | |
58 | struct display_type | |
59 | { | |
60 | template <class Type> | |
61 | void operator()(boost::msm::wrap<Type> const&) | |
62 | { | |
63 | std::cout << typeid(Type).name() << std::endl; | |
64 | } | |
65 | }; | |
66 | ||
67 | } } }//boost::msm::back | |
68 | #endif //BOOST_MSM_BACK_TOOLS_H |