#include #include #include #include #include namespace mpl = boost::mpl; namespace fsm = boost::fsm; struct Attached; struct Powered; struct Default; struct Address; struct Configured; typedef mpl::vector::type StateList; struct PowerOn; struct PowerOff; struct Reset; struct SetAddress; struct SetConfiguration; template class PredT, typename TargetT> struct SetAddressTrans: fsm::transition, TargetT> { static void transit(SourceT& state, fsm::event const& evt) { PredT pred; if (pred(evt.get<0>(), 0)) state.template switch_to(); } }; template class PredT, typename TargetT> struct SetConfigurationTrans: fsm::transition, TargetT> { static void transit(SourceT& state, fsm::event const& evt) { PredT pred; if (pred(evt.get<0>(), 0)) state.template switch_to(); } }; typedef mpl::vector< fsm::transition, Powered>, SetAddressTrans, SetAddressTrans, SetConfigurationTrans, SetConfigurationTrans, fsm::transition, Default>, fsm::transition, Attached> >::type Transitions; struct Common { int addr; int configuration; Common() : addr(0), configuration(0) {} }; template struct UsbState: fsm::state, virtual Common { void on_process(fsm::event const& evt) { state.addr = evt.get<0>(); } void on_process(fsm::event const& evt) { state.configuration = evt.get<0>(); } template void on_process(T const&) { } }; struct Attached: UsbState { }; struct Powered: UsbState { }; struct Default: UsbState { }; struct Address: UsbState
{ }; struct Configured: UsbState { }; int main(int, char*[]) { fsm::state_machine machine; machine.process(fsm::make_event()); machine.process(fsm::make_event()); machine.process(fsm::make_event(5)); machine.process(fsm::make_event(10)); return 0; }