Chris@16
|
1 // Copyright 2008 Christophe Henry
|
Chris@16
|
2 // henry UNDERSCORE christophe AT hotmail DOT com
|
Chris@16
|
3 // This is an extended version of the state machine available in the boost::mpl library
|
Chris@16
|
4 // Distributed under the same license as the original.
|
Chris@16
|
5 // Copyright for the original version:
|
Chris@16
|
6 // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
|
Chris@16
|
7 // under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_MSM_BACK_TOOLS_H
|
Chris@16
|
12 #define BOOST_MSM_BACK_TOOLS_H
|
Chris@16
|
13
|
Chris@16
|
14
|
Chris@16
|
15 #include <string>
|
Chris@16
|
16 #include <iostream>
|
Chris@16
|
17 #include <boost/msm/back/common_types.hpp>
|
Chris@16
|
18 #include <boost/msm/back/metafunctions.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace msm { namespace back
|
Chris@16
|
21 {
|
Chris@16
|
22
|
Chris@16
|
23 // fills the array passed in with the state names in the correct order
|
Chris@16
|
24 // the array must be big enough. To know the needed size, use mpl::size
|
Chris@16
|
25 // on fsm::generate_state_set
|
Chris@16
|
26 template <class stt>
|
Chris@16
|
27 struct fill_state_names
|
Chris@16
|
28 {
|
Chris@16
|
29 fill_state_names(char const** names):m_names(names){}
|
Chris@16
|
30 template <class StateType>
|
Chris@16
|
31 void operator()(boost::msm::wrap<StateType> const&)
|
Chris@16
|
32 {
|
Chris@16
|
33 m_names[get_state_id<stt,StateType>::value]= typeid(StateType).name();
|
Chris@16
|
34 }
|
Chris@16
|
35 private:
|
Chris@16
|
36 char const** m_names;
|
Chris@16
|
37 };
|
Chris@16
|
38
|
Chris@16
|
39 // fills the typeid-generated name of the given state in the string passed as argument
|
Chris@16
|
40 template <class stt>
|
Chris@16
|
41 struct get_state_name
|
Chris@16
|
42 {
|
Chris@16
|
43 get_state_name(std::string& name_to_fill, int state_id):m_name(name_to_fill),m_state_id(state_id){}
|
Chris@16
|
44 template <class StateType>
|
Chris@16
|
45 void operator()(boost::msm::wrap<StateType> const&)
|
Chris@16
|
46 {
|
Chris@16
|
47 if (get_state_id<stt,StateType>::value == m_state_id)
|
Chris@16
|
48 {
|
Chris@16
|
49 m_name = typeid(StateType).name();
|
Chris@16
|
50 }
|
Chris@16
|
51 }
|
Chris@16
|
52 private:
|
Chris@16
|
53 std::string& m_name;
|
Chris@16
|
54 int m_state_id;
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 // displays the typeid of the given Type
|
Chris@16
|
58 struct display_type
|
Chris@16
|
59 {
|
Chris@16
|
60 template <class Type>
|
Chris@16
|
61 void operator()(boost::msm::wrap<Type> const&)
|
Chris@16
|
62 {
|
Chris@16
|
63 std::cout << typeid(Type).name() << std::endl;
|
Chris@16
|
64 }
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 } } }//boost::msm::back
|
Chris@16
|
68 #endif //BOOST_MSM_BACK_TOOLS_H
|