Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] Get state name as string
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2013-01-20 16:27:30


Hi Stefan,

> Hello,
>
> For debugging purposes, I want to get the current state name as a string.
> For this purpose I found the class get_state_name in the tools section of
> the backend.
>
> Unfortunately there is no example on how to use this method in the
> documentation nor anywhere else; and the extensive use of templates makes
> it very difficult for me to infer this.
>
> I am especially confused about the argument boost::msm::wrap<StateType>
> const& of the call operator. What do I have to provide her? Could anybody
> please post a short example how to this?
>
> Kind regards,
>
> Stefan Wiehler

It is documented
(http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/re02.html), but it's
clearly insufficient.
Please allow me to correct it (and add to the doc). Admittedly, as a
metaprogramming debugging tool it's a bit hard to read (it's ok if you don't
get, it just has to fill the string name_of_open). I just tried this unsing
VC10 and boost 1.52.
I suppose you already have your state id (for ex. using current_state()) and
it has id 1:

// we need a fsm's table
typedef player::stt Stt;
typedef msm::back::generate_state_set<Stt>::type all_states; //all states
std::string name_of_open; // id of Open is 1
// fill name_of_open for state of id 1
boost::mpl::for_each<all_states,boost::msm::wrap<mpl::placeholders::_1> >
                (msm::back::get_state_name<Stt>(name_of_open,1));
std::cout << "typeid-generated name Open is: " << name_of_open <<
std::endl;

HTH,
Christophe


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