|
Boost Users : |
Subject: Re: [Boost-users] [MSM] looking for a recursive get_state_name
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2011-08-28 16:13:15
> Hello,
>
> i'am looking for a way to get the names(s) of the innermost active
> state(s) of a MSM with composite states, e.g. for debugging purposes.
>
> In my application i use state machines with orthogonal regions and
> submachines. Currently i use code based on the example given for
> fill_state_names, see
> http://www.boost.org/doc/libs/1_47_0/libs/msm/doc/HTML/re02.html#d0e5385
> It works well for for orthogonal regions. For for submachines only the
> name of the active submachine is returned. Instead i want the name of
> the innermost active state in each submachine.
>
> I already found 'recursive_get_transition_table', this seems to be a
> first step. But i don't know how to get the state id's on the path to
> innermost active state.
>
> Unfortunately i don't know much about boost::mpl, thus i'am a bit lost
> at the moment.
> Any suggestions on how to get the state id's on the path to the
> innermost active state? Or on a different approach to get the name of
> the innermost active state?
>
> Best regards,
> Jan
Hi Jan,
what you're trying is going to be hard. Pure metaprogramming will not help
you, because when you have the currently active state, you're in the runtime
world and there is no way back.
You could get the id of the currently active submachine, then get a pointer
to the base state with get_state_by_id then use some virtual function doing
what you are doing now for the main fsm.
But frankly, it's a lot of not fun work.
MSM provides a visitor concept for this
(http://www.boost.org/doc/libs/1_47_0/libs/msm/doc/HTML/ch03s05.html#d0e2423).
It goes recursively, on any number of regions, without anything virtual,
with several arguments, and you can decide if all states are visited or not.
Attached is an example which I will also add to the doc. It does what you
want. I also added a second argument for the fun.
HTH,
Christophe
PS: sorry for my late answer, vacation time ;-)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net