gpt4 book ai didi

c++ - 我可以使用 boost.statecarts 自定义对不同正交区域中多个状态的事件使用react吗?

转载 作者:行者123 更新时间:2023-11-28 07:43:48 26 4
gpt4 key购买 nike

我的用例与这个 SSCCE 类似。问题是,如果没有发生转换,我需要转发事件,这看起来不自然,以便它们由其他正交区域处理。更重要的是,在我需要转换的情况下,我无法找到一种方法让其他地区对事件使用react。我应该如何重组来解决这个问题?

如果这很重要,我正在使用 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));
}

最佳答案

这个问题是 answered由图书馆作者。他指的引用是Event dispatch to orthogonal regions .

关于c++ - 我可以使用 boost.statecarts 自定义对不同正交区域中多个状态的事件使用react吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com