boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.1k stars 173 forks source link

Directed entry to specific sub-state of nested machine #587

Open aplotskin opened 10 months ago

aplotskin commented 10 months ago

Expected Behavior

I am looking to implement a directed transition into a nested submachine state, roughly matching the following diagram from this boost document:

image

I have tried to go directly to a substate in a nested state like the following (using the state names of the above picture):

state<State1> + event<GoToCompositeS2> = state<Composite::Sub2>

but that action does not trigger the on_entry<_> piece of the larger Composite state machine, so feels like I am breaking something and should be cautious.

Is there a recommended way to do this using SML? Thank you.

ekigwana commented 10 months ago

What you need is an arrow from State 1 -> Composite. If the desired initial state is Sub2 and it makes sense, then make that the initial state. State 1 -> Composite, region 1 kicks off its initial state, region 2 -> Sub1

See https://boost-ext.github.io/sml/examples.html#composite

aplotskin commented 10 months ago

What you need is an arrow from State 1 -> Composite. If the desired initial state is Sub2 and it makes sense, then make that the initial state. State 1 -> Composite, region 1 kicks off its initial state, region 2 -> Sub1

Thank you, appreciate the reply and I see how my grabbing of that particular picture caused confusion. I only used that picture to show a directed transition example. My system is more complex, with a default initial state in Composite that is different from the one I want a particular upper state and event to transition into.

ekigwana commented 10 months ago

What you need is an arrow from State 1 -> Composite. If the desired initial state is Sub2 and it makes sense, then make that the initial state. State 1 -> Composite, region 1 kicks off its initial state, region 2 -> Sub1

Thank you, appreciate the reply and I see how my grabbing of that particular picture caused confusion. I only used that picture to show a directed transition example. My system is more complex, with a default initial state in Composite that is different from the one I want a particular upper state and event to transition into.

Then what you need is a Sub0 state which auto transitions to Sub1 or Sub2 as you desire.

aplotskin commented 10 months ago

@ekigwana thank you again. My Composite is actually pretty complex and is a History state, so does not have a normal initial entry path. So I was hoping this part of the UML state machine language was supported in SML. Seems like not.

I may be able to refactor my Composite into two pieces where this directed-to state is the initial state of a piece of it.