#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; struct Common { int addr; int configuration; Common() : addr(0), configuration(0) {} }; template struct UsbState: fsm::state, virtual Common { void on_process(fsm::event const&) { this->switch_to(); } void on_process(fsm::event const&) { this->switch_to(); } }; struct Attached: fsm::state, virtual Common { void on_process(fsm::event const&) { switch_to(); } }; struct Powered: UsbState { }; struct Default: UsbState { using UsbState::on_process; void on_process(fsm::event const& set_address) { addr = set_address.get<0>(); if (addr != 0) { switch_to
(); } } }; struct Address: UsbState
{ using UsbState
::on_process; void on_process(fsm::event const& set_address) { addr = set_address.get<0>(); if (addr == 0) { switch_to(); } } void on_process(fsm::event const& set_configuration) { configuration = set_configuration.get<0>(); if (configuration != 0) { switch_to(); } } }; struct Configured: UsbState { using UsbState::on_process; void on_process(fsm::event const& set_configuration) { configuration = set_configuration.get<0>(); if (configuration == 0) { switch_to
(); } } }; 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; }