Re: [Boost-users] [MSM] Boost.MSM: statemachine to transition on templatized event-type
Hi,
having tested Boost.MSM, I'm pretty happy with it.
:)
It's interesting, in that it seems to handle all states in a static table. No "new" operator etc.
It's much faster without dynamic allocation.
<snip>
g_row
Unfortunately gcc gives this error: d.cpp:119:5: error: ‘g_row’ was not declared in this scope g_row
,
Short answer. Try:
typename Machine_<EventT>::template g_row
On Fri, May 29, 2015 at 4:00 PM, Christophe Henry < christophe.j.henry@gmail.com> wrote:
Hi,
having tested Boost.MSM, I'm pretty happy with it.
:)
It's interesting, in that it seems to handle all states in a static
table.
No "new" operator etc.
It's much faster without dynamic allocation.
<snip>
g_row
, Unfortunately gcc gives this error: d.cpp:119:5: error: ‘g_row’ was not declared in this scope g_row
, Short answer. Try:
typename Machine_<EventT>::template g_row
Thanks so much for taking the time to help out! This works perfectly!!!
Long answer: g_row is a type of state_machine_def and as your fsm is a template, it becomes a dependent type (=> typename) and a template one even (=> template).
C++ is sometimes really annoying :(
Longer answer. Give up this front-end, it's deprecated anyway. A better solution will be:
#include
using namespace boost::msm::front; struct GuardToOdd { template
bool operator()(EVT const& num,FSM& ,SourceState& ,TargetState& ) { const long long x = static_cast<long long>(num.getNum()); return ((x == num.getNum()) // is Integral type && ((x % 2) != 0)); } }; Row< StateFloat, EventT, StateOdd, none, GuardToOdd>
I've tried it! Nice, thanks.
HTH, Christophe
I have a question about optimization regarding guard conditions.
How can one optimize the states and guard-checking??
This is one way:
/// see full working code example at the bottom of this post
struct transition_table : mpl::vector<
Row
Hi,
I have a question about optimization regarding guard conditions. How can one optimize the states and guard-checking??
<snip>
Is it possible to use MSM to create a parentstate "StateEval" with substates "StateEven", "StateOdd", "StateFloat" ?, the idea being to make transition_table as short as possible.
Something like this maby (but it does not work
struct transition_table : mpl::vector< Row
, Row , Row {};
Basically: is it possible to create a parentstate, that listens to events (even when an inner substate is already active)?
Thanks.
nicesw123
I think what you want is a composite state / submachine (http://www.boost.org/doc/libs/1_58_0/libs/msm/doc/HTML/ch02s02.html#d0e151). You want a submachine named StateEval and 3 substates inside, called StateEven, StateOdd, and StateFloat. Then you want 3 direct entries (which I dislike as it is a fsm goto, please consider direct entry transitions, on the above page). Then you save some transitions by having in your current fsm transitions originate from StateEval instead of substates. Correct? Then yes, it works of course. See: http://www.boost.org/doc/libs/1_58_0/libs/msm/doc/HTML/ch03s02.html#d0e529. There is also an example (http://www.boost.org/doc/libs/1_58_0/libs/msm/doc/HTML/examples/CompositeTut...) which also supports the functor front end. About entries, you could look at: http://www.boost.org/doc/libs/1_58_0/libs/msm/doc/HTML/ch03s02.html#d0e875. HTH, Christophe
participants (3)
-
Christophe Henry
-
christophe.j.henry@gmail.com
-
nice sw123