0

私は一般的にmsmとブーストをブーストする初心者です。私はどういうわけかすべてをカプセル化したいと思います:

  • イベント構造
  • 遷移テーブル構造と状態構造を含む stateMahine 構造

クラス内。

どうやってやるの?

// events
struct event1 {};



// front-end: define the FSM structure 
struct my_machine_ : public msm::front::state_machine_def<my_machine_>
{
    // The list of FSM states
    struct State1 : public msm::front::state<> 
    {
        // every (optional) entry/exit methods get the event passed.
        template <class Event,class FSM>
        void on_entry(Event const&,FSM& ) {std::cout << "entering: State1" << std::endl;}
        template <class Event,class FSM>
        void on_exit(Event const&,FSM& ) {std::cout << "leaving: State1" << std::endl;}
    };

    struct State2 : public msm::front::state<> 
    { 
        template <class Event,class FSM>
        void on_entry(Event const& ,FSM&) {std::cout << "entering: State3" << std::endl;}
        template <class Event,class FSM>
        void on_exit(Event const&,FSM& ) {std::cout << "leaving: State3" << std::endl;}


    };

    // the initial state of the player SM. Must be defined
    typedef State1 initial_state;

    typedef my_machine_ p; // makes transition table cleaner

    // Transition table
    struct transition_table : mpl::vector<
        //    Start     Event         Next      Action               Guard
        //  +---------+-------------+---------+---------------------+----------------------+
        Row < State1  , event1      , State2                                               >,
        Row < State2  , event1      , State1                                           >
    > {};

};
4

2 に答える 2

1

ネストされた使用のメンバーを実装するには:

// header file
struct Foo {
  struct Nested {
    void mem();
  };
};
// cpp file
void Foo::Nested::mem() {
  // implementation goes here
}
于 2012-06-05T15:11:49.630 に答える