Skip to content

feltech/msm-lite

 
 

Repository files navigation

Boost Licence Version Build Status Build Status Coveralls Github Issues


#Experimental Boost.MSM-lite

Your scalable C++14 header only eUML-like Meta State Machine library with no dependencies (Try it online!)

#include <boost/msm-lite.hpp>
namespace msm = boost::msm::lite;

auto guard = [] { return true; };
auto action = [] { std::cout << "action" << std::endl; };

struct hello_world {
  auto configure() const noexcept {
    using namespace msm;

    // Postfix Notation
    return make_transition_table(
       *"idle"_s + "e1"_t = "s1"_s
      , "s1"_s   + "e2"_t [ guard ] / action = "s2"_s
      , "s2"_s   + "e3"_t / [] { std::cout << "action" << std::endl; } = X
    );

    // Prefix Notation
    return make_transition_table(
       "s1"_s <= *"idle"_s + "e1"_t
     , "s2"_s <=  "s1"_s   + "e2"_t [ guard ] / action
     , X      <=  "s2"_s   + "e3"_t / [] { std::cout << "action" << std::endl; }
    );
  }
};

int main() {
  msm::sm<hello_world> sm;
  using namespace msm;
  assert(sm.is("idle"_s));
  assert(sm.process_event("e1"_t));
  assert(sm.is("s1"_s));
  assert(sm.process_event("e2"_t));
  assert(sm.is("s2"_s));
  assert(sm.process_event("e3"_t));
  assert(sm.is(X));
}


Disclaimer Boost.MSM-lite is not an official Boost library.

About

Boost.MSM-lite: C++14 Meta State Machine Library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 98.7%
  • Makefile 1.3%