#include <iostream>
#include <boost/mpl/list.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/custom_reaction.hpp>
namespace sc = boost::statechart;
struct Event1 : sc::event<Event1> {};
struct Event11 : sc::event<Event11> {};
struct Meta;
struct Machine : sc::state_machine<Machine, Meta> {};
struct Meta2 : sc::simple_state<Meta2, Machine> {
Meta2() { std::cout << "Meta2\n"; }
};
struct Inner1;
struct Inner2;
struct Meta : sc::simple_state<Meta, Machine, boost::mpl::list<Inner1, Inner2>> {
Meta() { std::cout << "Meta\n"; }
typedef sc::transition<Event1, Meta2> reactions;
};
struct Inner11 : sc::simple_state<Inner11, Meta::orthogonal<0>> {
Inner11() { std::cout << "Inner11\n"; }
typedef sc::custom_reaction<Event1> reactions;
sc::result react(const Event1& ev) {
std::cout << "Inner1 reaction\n";
return forward_event();
}
};
struct Inner1 : sc::simple_state<Inner1, Meta::orthogonal<0>> {
Inner1() { std::cout << "Inner1\n"; }
typedef sc::transition<Event11, Inner11> reactions;
};
struct Inner2 : sc::simple_state<Inner2, Meta::orthogonal<1>> {
Inner2() { std::cout << "Inner2\n"; }
};
int main() {
Machine m;
m.initiate();
m.process_event(Event11());
m.process_event(Event1());
return 0;
}
////////////////////
That gives me output:
Meta
Inner1
Inner2
Inner11
Meta2
I can make it work in that way only if I put Event1 handling into Inner1 state.