Finite state machine, BOOST::MSM

Source: Internet
Author: User
Tags fsm

A simple finite state machine:

This state machine has two, State1 states, and an end state.
The following code can describe this state machine:

#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{namespaceMSM = BOOST::MSM;namespaceMSMF = Boost::msm::front;namespaceMPL = Boost::mpl;//-----Events    structEvent1 {};//----- State Machine    structsm1_:msmf::state_machine_def<sm1_> {//States        structstate1:msmf::state<> {//Entry action            Template<classEvent,classFsm>voidOn_entry (EventConst&, fsm&)Const{STD::cout<<"State1::on_entry ()"<<STD:: Endl; }//Exit action            Template<classEvent,classFsm>voidOn_exit (EventConst&, fsm&)Const{STD::cout<<"State1::on_exit ()"<<STD:: Endl; }        };structend:msmf::terminate_state<> {};//Set initial state        typedefState1 initial_state;//Transition table        structTransition_table:mpl:: Vector<//Start Event Next Action Guard Msmf::row < State1, Event1, End, Msmf::none, Msmf::none >> {}; };//Pick a back-end    typedefMsm::back::state_machine<sm1_> Sm1;voidTest () {Sm1 sm1; Sm1.start ();STD::cout<<"> Send Event1"<<STD:: Endl;    Sm1.process_event (Event1 ()); }}intMain () {test ();return 0;}
// Output://// State1::on_entry()// > Send Event1// State1::on_exit()// Set initial statetypedef State1 initial_state;

typedef XXX INITIAL_STATE Represents the state machine sm1_ starting from the state State1.

Respect original, original link, Mark Spare

Finite state machine, BOOST::MSM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.