2

I'm developing a state machine using boost MSM framework. Their tutorial states that boost::any can be used as a "Kleene event", allowing transition on any event being fired, if the current state is the source state. This doesn't work for me, however. I just receive "no_transition". Here is my sample code:


#include <iostream>
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/msm/front/functor_row.hpp>
#include <boost/any.hpp>

using namespace std;
namespace msm = boost::msm;
using namespace msm::front;
namespace mpl = boost::mpl;

namespace
{
    struct event1 {};
    struct some_event{};

    struct some_sm_ : public msm::front::state_machine_def<some_sm_>
    {
        struct State1 : public msm::front::state<>
        {
            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: State2" << std::endl;}
            template <class Event,class FSM>
            void on_exit(Event const&,FSM& ) {std::cout << "leaving: State2" << std::endl;}
        };

        typedef State1 initial_state;

        struct transition_table : mpl::vector<
            //    Start     Event         Next      
            //  +---------+-------------+---------+
            Row < State1  , boost::any  , State2  >,
            Row < State1  , event1      , State2  >
            //  +---------+-------------+---------+
        > {};

        template <class FSM,class Event>
        void no_transition(Event const& e, FSM&,int state)
        {
            std::cout << "no transition from state " << state
                << " on event " << typeid(e).name() << std::endl;
        }
    };

    typedef msm::back::state_machine<some_sm_> some_sm;


    void test()
    {
        some_sm p;
        p.start();
        p.process_event(some_event());
        p.process_event(event1());
    }
}

int main()
{
    test();
    return 0;
}

When executed, it produces the following output:

entering: State1

no transition from state 0 on event N12_GLOBAL__N_110some_eventE

leaving: State1

entering: State2

I would expect a transition from "State1" to "State2" to occur upon "some_event", but that, apparently, does not happen.

I must be missing something, but I can't realize what is it.

Justin
  • 24,288
  • 12
  • 92
  • 142
Kikosha
  • 343
  • 6
  • 16
  • 1
    I think I found the answer: I'm using boost version 1.49, which was released on February 24th, 2012. Now, according to this changeset: [link](https://svn.boost.org/trac/boost/changeset/78785), support of boost::any as a universal event was added on 05/31/12. I'll check this with a newer version... – Kikosha Jul 03 '13 at 14:34

1 Answers1

2

I compiled my example with boost version 1.53 and the boost::any worked as explained in the tutorial.

Kikosha
  • 343
  • 6
  • 16