With boost::msm eUML, if I give attributes_ << to the state machine or state, how do I (re)set them?

StackOverflow https://stackoverflow.com/questions/12169544

  •  29-06-2021
  •  | 
  •  

Question

If I add attributes to an event, I know I can then use the event name like a function...

BOOST_MSM_EUML_EVENT_WITH_ATTRIBUTES(*someEvent*, *someAttributeList*)

someStateMachine.process_event(
   someEvent (
      valueOfSomeAttribute1, // sets the attribute value here
      valueOfSomeAttribute2))

and that inside an action I can this back by writing

evt.get_attribute(someAttribute1);  // retrieve the attribute value

Now, if I set an attribute for an entire machine, like so:

BOOST_MSM_EUML_DECLARE_STATE_MACHINE((transition_table,
                         init_ << initState,
                         Entry_Action, 
                         Exit_Action, 
                         attributes_ << someAttribute1 << someAttribute2,
                         configure_<< someConfigurationStuff ),
                         newStateMachineType)

How do I go about setting a value for someAttribute1?

Same question for states:

BOOST_MSM_EUML_STATE(
       (someEntryAction,
        someExitAction,
        attributes_ << someAttribute1,
        configure_<< someConfigurationStuff)
       ,newStateName)

How do I go about setting a value for someAttribute1?

Finally,

Is there a way to change the attributes after the object is created?

For instance, I'd like to have an attribute for the state machine, and in one of my states, remember some piece of information that I can store in the state machine. (In this case, I want to store a socket.)

Thanks.

Was it helpful?

Solution

How do I go about setting a value for someAttribute1? You can:

  • change the reference you just got (get_attribute returns a reference): ++evt.get_attribute(someAttribute1).
  • use the functors to write the attribute in your table directly. For example, following action is possible: /++fsm_(someAttribute1)

For states, you can do the same. And for state machines, well, ditto. Again, you can either use the Fsm template parameter in your actions, or the functors (fsm_, event_, etc.)

You can find good example of all in the examples or tests (for example test/CompositeEuml.cpp or test/AnonymousEuml.cpp).

HTH, Christophe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top