• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //////////////////////////////////////////////////////////////////////////////
2 // Copyright 2010 Igor R (http://thread.gmane.org/gmane.comp.lib.boost.user/62985)
3 // Copyright 2010 Andreas Huber Doenni
4 // Distributed under the Boost Software License, Version 1.0. (See accompany-
5 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //////////////////////////////////////////////////////////////////////////////
7 
8 #include <boost/statechart/event.hpp>
9 #include <boost/statechart/state_machine.hpp>
10 #include <boost/statechart/simple_state.hpp>
11 #include <boost/statechart/transition.hpp>
12 #include <boost/statechart/deferral.hpp>
13 
14 #include <boost/mpl/list.hpp>
15 
16 #include <boost/test/test_tools.hpp>
17 
18 
19 
20 namespace sc = boost::statechart;
21 namespace mpl = boost::mpl;
22 
23 
24 
25 struct ev1to2 : sc::event< ev1to2 > {};
26 struct ev2to3 : sc::event< ev2to3 > {};
27 struct ev3to4_1 : sc::event< ev3to4_1 > {};
28 struct ev3to4_2 : sc::event< ev3to4_2 > {};
29 
30 struct s1;
31 struct fsm : sc::state_machine< fsm, s1 > {};
32 
33 struct s2;
34 struct s1 : sc::simple_state< s1, fsm >
35 {
36   typedef mpl::list<
37     sc::transition< ev1to2, s2 >,
38     sc::deferral< ev2to3 >,
39     sc::deferral< ev3to4_1 >,
40     sc::deferral< ev3to4_2 >
41   > reactions;
42 };
43 
44 struct s3;
45 struct s2 : sc::simple_state< s2, fsm >
46 {
47   typedef mpl::list<
48     sc::transition< ev2to3, s3 >,
49     sc::deferral< ev3to4_1 >,
50     sc::deferral< ev3to4_2 >
51   > reactions;
52 };
53 
54 struct s4_1;
55 struct s4_2;
56 struct s3 : sc::simple_state< s3, fsm >
57 {
58   typedef mpl::list<
59     sc::transition< ev3to4_1, s4_1 >,
60     sc::transition< ev3to4_2, s4_2 >
61   > reactions;
62 };
63 
64 struct s4_1 : sc::simple_state< s4_1, fsm > {};
65 struct s4_2 : sc::simple_state< s4_2, fsm > {};
66 
test_main(int,char * [])67 int test_main( int, char* [] )
68 {
69   fsm machine;
70   machine.initiate();
71   machine.process_event( ev3to4_1() );
72   machine.process_event( ev2to3() );
73   machine.process_event( ev3to4_2() );
74   machine.process_event( ev1to2() );
75   BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 );
76   machine.initiate();
77   machine.process_event( ev3to4_1() );
78   machine.process_event( ev3to4_2() );
79   machine.process_event( ev1to2() );
80   machine.process_event( ev2to3() );
81   BOOST_REQUIRE( machine.state_cast< const s4_1 * >() != 0 );
82 
83   return 0;
84 }
85