我的主 SM 中有两个子 SM。我希望能够从主 SM 跳到其中一个,也可以从一个子 SM 跳到另一个 SM。但我不能。我能够从主 SM 跳到子 SM,从一个子 SM 跳到另一个,但是当我在子 SM 之间添加“相互”转换时,编译失败,大约 10 个错误抱怨不同的事情。我想这是因为编译器进入了递归旋转。
我想我可以在主 SM 中添加一个虚拟状态,并匿名转换到目标子 SM。但随后我会放弃触发转换的真实事件,我不想要那个(它包含数据)。
这是一些测试代码,其中有问题的行被注释掉了
#include <iostream>
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/functor_row.hpp>
namespace {
using namespace boost::msm;
using namespace boost::msm::front;
namespace mpl = boost::mpl;
struct EvGotoSub1 {};
struct EvGotoSub2 {};
struct MainSM_;
using Main = back::state_machine<MainSM_>;
struct Sub1SM_;
using Sub1 = back::state_machine<Sub1SM_>;
struct Sub2SM_;
using Sub2 = back::state_machine<Sub2SM_>;
struct Sub1SM_ : state_machine_def<Sub1SM_> {
struct Started : state<> { };
using initial_state = mpl::vector<Started>;
struct transition_table:mpl::vector<
Row<Started, EvGotoSub2, Sub2, none, none>
> {};
};
struct Sub2SM_ : state_machine_def<Sub2SM_> {
struct Started : state<> { };
using initial_state = mpl::vector<Started>;
struct transition_table:mpl::vector<
// Uncomment line below to break things
//Row<Started, EvGotoSub1, Sub1, none, none>
> {};
};
struct MainSM_ : state_machine_def<MainSM_> {
struct Started : state<> { };
using initial_state = mpl::vector<Started>;
struct transition_table:mpl::vector<
Row<Started, EvGotoSub1, Sub1, none, none>,
Row<Started, EvGotoSub2, Sub2, none, none>
> {};
};
}
int main() {
Main main;
main.start();
main.process_event(EvGotoSub1());
main.process_event(EvGotoSub2());
main.process_event(EvGotoSub1());
}