我承认这不是很好,但是
#ifdef DEBUG
typedef AnotherState StartingState;
#else
typedef ClosedState StartingState;
#endif
struct BoostStateMachine : sc::state_machine<BoostStateMachine, StartingState > {...
编辑地址评论
#ifndef INITIAL_STATE
#define INITIAL_STATE ClosedState
#endif
struct BoostStateMachine : sc::state_machine<BoostStateMachine, INITIAL_STATE > {...
当然,这意味着您需要重新编译才能进行每个测试 =[
我们可以尝试以下方法:
typedef<class InitialState>
struct StateMachine : sc::state_machine< typename /*?*/ StateMachine<InitialState>, InitialState > {...}
typedef StateMachine<ClosedState> BoostStateMachine; //default case
#ifdef DO_TESTS
...
StateMachine<AnotherState> astate1;
...
StateMachine<AnotherState2> astate2;
...
StateMachine<AnotherState3> astate3;
...
#endif
当它是需要以不同状态开始的子状态时,这当然无济于事。但同样的事情也适用:
typedef <typename InitialChild>
struct ClosedState : sc::simple_state< ClosedState<InitialChild>, BoostStateMachine, InitialChild > {...};
或类似的东西。我以前做过模板化状态(这样我就可以有共同的子状态序列),它是一个皇家 PITA 来调试(更多的是状态图的其余部分)。