代码之家  ›  专栏  ›  技术社区  ›  Edward Strange

Boost.Statechart-问题与选择点的文档化方法

  •  1
  • Edward Strange  · 技术社区  · 14 年前

    如图中所示 documentation 我编写的以下代码未能编译,因为自定义\u反应<&燃气轮机;似乎与作为state的第三个模板参数预期的概念不匹配<>。我怎样才能真正做出选择呢(我还问了这个问题(在提升列表上)

    #include <boost/statechart/state_machine.hpp>
    #include <boost/statechart/simple_state.hpp>
    #include <boost/statechart/state.hpp>
    #include <boost/statechart/custom_reaction.hpp>
    #include <boost/statechart/event.hpp>
    #include <boost/statechart/transition.hpp>
    #include <boost/mpl/list.hpp>
    
    #include <iostream>
    
    namespace sc = boost::statechart;
    
    struct make_choice : sc::event< make_choice > {};
    
    // universal choice point base class template
    template< class MostDerived, class Context >
    struct choice_point : sc::state< MostDerived, Context, 
      sc::custom_reaction< make_choice > >
    {
      typedef sc::state< MostDerived, Context, 
        sc::custom_reaction< make_choice > > base_type;
      typedef typename base_type::my_context my_context;
      typedef choice_point my_base;
    
      choice_point( my_context ctx ) : base_type( ctx )
      {
        this->post_event( boost::intrusive_ptr< make_choice >(
          new make_choice() ) );
      }
    };
    
    // ...
    
    struct MyChoicePoint;
    struct Machine : sc::state_machine< Machine, MyChoicePoint > {};
    
    struct Dest1 : sc::simple_state< Dest1, Machine > {};
    struct Dest2 : sc::simple_state< Dest2, Machine > 
    {
      Dest2() { std::cout << "Dest2\n"; }
    };
    struct Dest3 : sc::simple_state< Dest3, Machine > {};
    
    struct MyChoicePoint : choice_point< MyChoicePoint, Machine >
    {
      MyChoicePoint( my_context ctx ) : my_base( ctx ) {}
    
      sc::result react( const make_choice & )
      {
        if ( 0 )
        {
          return transit< Dest1 >();
        }
        else if ( 1 )
        {
          return transit< Dest2 >();
        }
        else
        {
          return transit< Dest3 >();
        }
      }
    };
    
    int main()
    {
      Machine machine;
      machine.initiate();
    
      std::cin.get();
    }
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Edward Strange    14 年前

    我想我可能已经找到了答案。我将等待来自boost列表的验证,但看起来文档只是错误的,如果您按照相机示例中的说明进行定制反应,它就可以正常工作。即选择点模板需要更改为:

    // universal choice point base class template
    template< class MostDerived, class Context >
    struct choice_point : sc::state< MostDerived, Context >
    {
      typedef sc::state< MostDerived, Context > base_type;
      typedef typename base_type::my_context my_context;
      typedef choice_point my_base;
    
      typedef sc::custom_reaction<make_choice> reactions;
    
      choice_point( my_context ctx ) : base_type( ctx )
      {
        this->post_event( boost::intrusive_ptr< make_choice >(
          new make_choice() ) );
      }
    };
    

    推荐文章