如何将对象赋予 boost::statechart 中的状态?
我处于需要修改我没有编写的状态机的情况。此状态机是使用 Boost Statechart 编写的。不幸的是,我发现这段代码难以理解,而且编写这段代码的人正在度假。
我认为问题很简单:我有一个变量 thing
,我想在其中一些状态下使用它。它代表一个需要了解事物的单一应用程序控制器。我可以将 thing
赋予什么构造函数(或其他),使其可用于机器的状态?
各州是按照以下示例声明的:
struct Pumping : sc::state< Pumping, Purifier >
{
Pumping( my_context ctx ) : my_base( ctx )
{
post_event( EvPumpingStarted() );
}
// ...
};
PS 我希望这个问题有一个更好的标题;帮助表示赞赏。
I am in the situation where I need to modify a state machine that I did not write. This state machine is written using Boost Statechart. Unfortunately, I find this code impenetrable, and the guy who did write it is on vacation.
The problem is simple, I think: I have a variable, thing
, that I want to use in some of these states. It represents a singular application controller that needs to be informed of things. To what constructor (or whatever) can I give thing
, making it available to states of the machine?
The states are declared as per this example:
struct Pumping : sc::state< Pumping, Purifier >
{
Pumping( my_context ctx ) : my_base( ctx )
{
post_event( EvPumpingStarted() );
}
// ...
};
P.S. I would love a better title for this question; help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来应该将东西传递给机器构造函数?如果是这样,最好将其设为机器的数据成员。状态可以使用outermost_context()函数访问机器。因此,在一个状态中,您可以编写类似outermost_context().get_thing() 的内容。
It sounds like thing should be passed to the machine constructor? If so, it's probably best to make it a data member of the machine. States can access the machine with the outermost_context() function. So, inside a state you'd write something like outermost_context().get_thing().