char_event_dispatcher.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2010 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_CHAR_EVENT_DISPATCHER_HPP
  11. #define BOOST_MSM_CHAR_EVENT_DISPATCHER_HPP
  12. #include <boost/msm/back/common_types.hpp>
  13. struct digit {};
  14. struct char_0 : public digit {};
  15. struct char_1 : public digit {};
  16. struct char_2 : public digit {};
  17. struct char_3 : public digit {};
  18. struct char_4 : public digit {};
  19. struct char_5 : public digit {};
  20. struct char_6 : public digit {};
  21. struct char_7 : public digit {};
  22. struct char_8 : public digit {};
  23. struct char_9 : public digit {};
  24. struct minus_char {};
  25. template <char c>
  26. struct event_char{};
  27. template <>
  28. struct event_char<'0'> : public digit{};
  29. template <>
  30. struct event_char<'1'> : public digit{};
  31. template <>
  32. struct event_char<'2'> : public digit{};
  33. template <>
  34. struct event_char<'3'> : public digit{};
  35. template <>
  36. struct event_char<'4'> : public digit{};
  37. template <>
  38. struct event_char<'5'> : public digit{};
  39. template <>
  40. struct event_char<'6'> : public digit{};
  41. template <>
  42. struct event_char<'7'> : public digit{};
  43. template <>
  44. struct event_char<'8'> : public digit{};
  45. template <>
  46. struct event_char<'9'> : public digit{};
  47. namespace boost { namespace msm { namespace back {
  48. template <class Fsm>
  49. struct char_event_dispatcher
  50. {
  51. template <char c>
  52. struct dispatch_event_helper
  53. {
  54. static execute_return apply(Fsm& fsm)
  55. {
  56. return fsm.process_event(event_char<c>());
  57. }
  58. };
  59. char_event_dispatcher()
  60. {
  61. entries[0x30]=&dispatch_event_helper<'0'>::apply;
  62. entries[0x31]=&dispatch_event_helper<'1'>::apply;
  63. entries[0x32]=&dispatch_event_helper<'2'>::apply;
  64. entries[0x33]=&dispatch_event_helper<'3'>::apply;
  65. entries[0x34]=&dispatch_event_helper<'4'>::apply;
  66. entries[0x35]=&dispatch_event_helper<'5'>::apply;
  67. entries[0x36]=&dispatch_event_helper<'6'>::apply;
  68. entries[0x37]=&dispatch_event_helper<'7'>::apply;
  69. entries[0x38]=&dispatch_event_helper<'8'>::apply;
  70. entries[0x39]=&dispatch_event_helper<'9'>::apply;
  71. entries[0x2D]=&dispatch_event_helper<'-'>::apply;
  72. entries[0x2B]=&dispatch_event_helper<'+'>::apply;
  73. }
  74. execute_return process_event(Fsm& fsm,char c) const
  75. {
  76. return entries[c](fsm);
  77. }
  78. // The singleton instance.
  79. static const char_event_dispatcher instance;
  80. typedef execute_return (*cell)(Fsm&);
  81. cell entries[255];
  82. };
  83. }}} // boost::msm::back
  84. #endif //BOOST_MSM_CHAR_EVENT_DISPATCHER_HPP