简体   繁体   English

我可以使用boost.statecharts自定义对不同正交区域中多个状态的事件的反应吗?

[英]Can I custom react to a event in multiple states in different orthogonal reigions using boost.statecharts?

My use case is similar to this SSCCE. 我的用例与此SSCCE类似。 The problem is that if no transition occurs I need to forward the events, which seems unnatural, for them to be processed by the other orthogonal regions. 问题是,如果没有发生过渡,我需要转发事件,这似乎是不自然的,以便其他正交区域对其进行处理。 More importantly though in the case I need to transition I can't find a way to allow the event to be reacted to in other regions. 更重要的是,尽管在我需要转换的情况下,我找不到找到让事件在​​其他区域反应的方法。 How should I restructure to work around this? 我应该如何重组以解决此问题?

I am using boost 1.53 in case this is important. 如果这很重要,我将使用Boost 1.53。

namespace sc = boost::statechart;
struct Active;
struct Keyboard : sc::state_machine< Keyboard, Active > {};

struct NumLockOff;
struct CapsLockOff;
struct ScrollLockOff;
struct Active: sc::simple_state< Active, Keyboard, boost::mpl::list< NumLockOff, CapsLockOff, ScrollLockOff > > {};

struct EvNumLockPressed : sc::event< EvNumLockPressed > {};
struct EvCapsLockPressed : sc::event< EvCapsLockPressed > {};
struct EvScrollLockPressed : sc::event< EvScrollLockPressed > {};
struct EvAllLocksOffPressed : sc::event< EvAllLocksOffPressed > {
    int i_;
    EvAllLocksOffPressed(int i):sc::event< EvAllLocksOffPressed >(),i_(i){}
};

struct NumLockOn : sc::simple_state< NumLockOn, Active::orthogonal< 0 > >
{
    typedef boost::mpl::list<sc::transition< EvNumLockPressed, NumLockOff >, sc::custom_reaction<EvAllLocksOffPressed>> reactions;
    sc::result react( const EvAllLocksOffPressed & e)
    {
        if(e.i_ == 42)
            return transit< NumLockOff >();
        return forward_event();
    }
};

struct NumLockOff : sc::simple_state< NumLockOff, Active::orthogonal< 0 > >
{
    typedef sc::transition< EvNumLockPressed, NumLockOn > reactions;
};

struct CapsLockOn : sc::simple_state< CapsLockOn, Active::orthogonal< 1 > >
{
    typedef boost::mpl::list<sc::transition< EvCapsLockPressed, CapsLockOff >, sc::custom_reaction<EvAllLocksOffPressed>> reactions;
    sc::result react( const EvAllLocksOffPressed & e)
    {
        if(e.i_ == 42)
            return transit< CapsLockOff >();
        return forward_event();
    }
};

struct CapsLockOff : sc::simple_state< CapsLockOff, Active::orthogonal< 1 > >
{
    typedef sc::transition< EvCapsLockPressed, CapsLockOn > reactions;
};

struct ScrollLockOn : sc::simple_state< ScrollLockOn, Active::orthogonal< 2 > >
{
    typedef boost::mpl::list<sc::transition< EvScrollLockPressed, ScrollLockOff >, sc::custom_reaction<EvAllLocksOffPressed>> reactions;
    sc::result react( const EvAllLocksOffPressed & e)
    {
        if(e.i_ == 42)
            return transit< ScrollLockOff >();
        return forward_event();
    }
};

struct ScrollLockOff : sc::simple_state< ScrollLockOff, Active::orthogonal< 2 > >
{
    typedef sc::transition< EvScrollLockPressed, ScrollLockOn > reactions; 
};

int main(){
    Keyboard k;
    k.initiate();
    k.process_event(EvNumLockPressed());
    k.process_event(EvCapsLockPressed());
    k.process_event(EvScrollLockPressed());
    k.process_event(EvAllLocksOffPressed(1));
    k.process_event(EvAllLocksOffPressed(42));
}

This question was answered by the library author. 图书馆作者回答了这个问题。 The reference he meant is Event dispatch to orthogonal regions . 他的意思是将事件调度到正交区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提升状态图并行执行正交状态 - boost statechart parallel execution of orthogonal states 对在 Boost.statechart 中完成的所有正交状态做出反应 - reacting to all orthogonal states having finished in Boost.statechart Boost StateCharts与Samek的“量子状态图”的比较 - Comparison of Boost StateCharts vs. Samek's “Quantum Statecharts” 对于具有不同状态的结构,我应该使用哪种设计模式? - What sort of design pattern should I be using for a structure that can have different states? 如何使用 boost 生成不同位的随机多精度整数? - How can I generate random multiprecision ints of different bits using boost? 如何使用Boost :: Spirit :: Qi跟踪多个输入的输入位置? - How can I track my input position with multiple inputs using Boost::Spirit::Qi? 如何并行使用boost? - How can I parallelize a for using boost? 使用 Boost,如何将自定义边缘属性作为结构放置/获取? - Using Boost, how can I put/get custom edge properties as a struct? 如何让我的QDial对不同于预定义的鼠标事件作出反应? - How can I make my QDial react to a different mouse event than the one predefined? 如何使用 boost beast 为 websocket 握手添加自定义标头 - How can I put a custom header for websocket handshake with boost beast
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM