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