在增强转移机中组合多个警卫

Combining Multiple Guards in Boost Metastate Machine

本文关键字:组合 增强 转移机      更新时间:2023-10-16

是否有一种方法可以在Boost Meta状态机的函数前端组合多个后卫?

我想做以下操作:

struct transition_table : mpl::vector<
//    Start     Event        Target      Action                      Guard 
//   +---------+------------+-----------+---------------------------+----------------------------+ 
Row  < Stopped , play       ,  Playing  , start_playback            , guard1 && guard2              >          
//   +---------+------------+-----------+---------------------------+----------------------------+ 
> {};

guard1guard2都是布尔表达式。但是,这不会编译。Boost SML可以轻松允许。

使用以下代码:

struct actions_guards {
  auto operator()() noexcept {
    using namespace sml;
    return make_transition_table(
       *"idle"_s + event<e1> = "s1"_s
      , "s1"_s + event<e2> [ guard1 && guard2 ] / action1 = X
    );
  }
#include <boost/msm/front/euml/euml.hpp>
using namespace euml;
struct transition_table : mpl::vector<
//    Start     Event        Target      Action                      Guard 
//   +---------+------------+-----------+---------------------------+----------------------------+ 
Row  < Stopped , play       ,  Playing  , start_playback            , And_<guard1, guard2>              >          
//   +---------+------------+-----------+---------------------------+----------------------------+ 
> {};