tools.hpp 2.0 KB

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