Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] How to access event-attributes through a"kleene"-event?
From: Deniz Bahadir (deniz.bahadir_at_[hidden])
Date: 2013-02-21 15:40:17


Hi again,

>
[snip]
>
> // An action which returns the event's number.
> BOOST_MSM_EUML_ACTION(GetEventNumber_)
> {
> template <class Fsm, class Evt,
> class SourceState, class TargetState>
> int operator()(Evt const& evt, Fsm&,
> SourceState&, TargetState&)
> {
> return evt.getNumber();
> }
> };
>
>
> // The attribute:
> BOOST_MSM_EUML_DECLARE_ATTRIBUTE(int, EventNo)
> BOOST_MSM_EUML_ATTRIBUTES((attributes_ << EventNo), EventNoAttr)
> // All events that contain this attribute:
> MY_BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES_AND_MEMBERS(event1,
> EventNoAttr,
> (int getEventNumber() const {
> return get_attribute(EventNo);
> }) // <-- members_list
> )
> /* ... more events with same scheme ... */
>
> // Creating an instance of the new "kleene"-event which has
> // a "getNumber" member-function.
> any_number_event number_event;
>
> // The transitions table
> BOOST_MSM_EUML_TRANSITION_TABLE((
> State1 + number_event
> [IsEventNumberGT_<7>()] == State2,
> State1 + event1
> / (fsm_(lastEventNo) = event_(EventNo)) == State3
> State2 + kleene
> / (fsm_(lastEventNo) = GetEventNumber_)) == State3
> ), stt)
>

Of course, I had some more typos. (I did not test, what I extracted from
my code into the email... :-/)

However, I realized, that for my case I do not really need the
"IsEventNumberGT_<VAL>" action.
I could as well have used the "GetEventNumber_" action in the transition
table which is even clearer for a C++ developer:

// The transitions table
BOOST_MSM_EUML_TRANSITION_TABLE((
    State1 + number_event
             [GetEventNumber_ > Int_<7>()] == State2,
), stt)

Ciao,
Deniz

PS: I found a possible bug in MSM when accessing state-attributes from
actions. But maybe I am doing something wrong. I'll open a new
email-thread for that with subject "[MSM] Unable to retrieve correct
value of attribute of a state from within actions. (Possible Bug?)".
Maybe you could have a look at it.


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