1 | #include <iostream>
|
---|
2 | #include <boost/msm/back/state_machine.hpp>
|
---|
3 |
|
---|
4 | #include <boost/msm/front/state_machine_def.hpp>
|
---|
5 | #include <boost/msm/front/functor_row.hpp>
|
---|
6 | #include <boost/static_assert.hpp>
|
---|
7 |
|
---|
8 | namespace msm = boost::msm;
|
---|
9 | namespace msmf = boost::msm::front;
|
---|
10 | namespace mpl = boost::mpl;
|
---|
11 |
|
---|
12 |
|
---|
13 | namespace {
|
---|
14 |
|
---|
15 | // ----- Events
|
---|
16 | struct Event1 {};
|
---|
17 |
|
---|
18 | // ----- State machine
|
---|
19 | struct OuterSm_:msmf::state_machine_def<OuterSm_>
|
---|
20 | {
|
---|
21 | struct StateSub_:msmf::state_machine_def<StateSub_>
|
---|
22 | {
|
---|
23 | template <class Event,class Fsm>
|
---|
24 | void on_entry(Event const&, Fsm&) const {
|
---|
25 | std::cout << "StateSub_::on_entry()" << std::endl;
|
---|
26 | }
|
---|
27 |
|
---|
28 | template <class Event,class Fsm>
|
---|
29 | void on_exit(Event const&, Fsm&) const {
|
---|
30 | std::cout << "StateSub_::on_exit()" << std::endl;
|
---|
31 | }
|
---|
32 |
|
---|
33 | struct SubState1:msmf::state<>
|
---|
34 | {
|
---|
35 | template <class Event,class Fsm>
|
---|
36 | void on_entry(Event const&, Fsm&) const {
|
---|
37 | std::cout << "SubState1::on_entry()" << std::endl;
|
---|
38 | }
|
---|
39 |
|
---|
40 | template <class Event,class Fsm>
|
---|
41 | void on_exit(Event const&, Fsm&) const {
|
---|
42 | std::cout << "SubState1::on_exit()" << std::endl;
|
---|
43 | }
|
---|
44 | };
|
---|
45 |
|
---|
46 | struct Exit1:msmf::exit_pseudo_state<msmf::none> {};
|
---|
47 |
|
---|
48 | // Set initial state
|
---|
49 | typedef SubState1 initial_state;
|
---|
50 | // Transition table
|
---|
51 | struct transition_table:mpl::vector<
|
---|
52 | // Start Event Next Action Guard
|
---|
53 | msmf::Row < SubState1, Event1, Exit1, msmf::none, msmf::none >
|
---|
54 | > {};
|
---|
55 | };
|
---|
56 | typedef msm::back::state_machine<StateSub_> StateSub;
|
---|
57 |
|
---|
58 | struct End: msmf::terminate_state<> {};
|
---|
59 |
|
---|
60 | // Set initial state
|
---|
61 | typedef StateSub initial_state;
|
---|
62 | // Transition table
|
---|
63 | struct transition_table:mpl::vector<
|
---|
64 | // Start Event Next Action Guard
|
---|
65 | msmf::Row < StateSub::exit_pt
|
---|
66 | <StateSub_::Exit1>, msmf::none, End, msmf::none, msmf::none >
|
---|
67 | > {};
|
---|
68 | };
|
---|
69 |
|
---|
70 | // Pick a back-end
|
---|
71 | typedef msm::back::state_machine<OuterSm_> Osm;
|
---|
72 |
|
---|
73 | void test()
|
---|
74 | {
|
---|
75 | Osm osm;
|
---|
76 | osm.start();
|
---|
77 |
|
---|
78 | std::cout << "> Send Event1()" << std::endl;
|
---|
79 | osm.process_event(Event1());
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | int main()
|
---|
84 | {
|
---|
85 | test();
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 |
|
---|