On Fri, Nov 9, 2012 at 2:10 AM, Andreas Huber
<ahd6974-spamboostorgtrap@yahoo.com> wrote:
Ilya Orlov <iorlov <at>
gmail.com> writes:
> I missed your advice in previous message. I changed transition code to A1
state and it worked perfectly. But ideally, I'd like to transit from B not to
A1 but to A state. How I can change this code to get it working with saving all
history for A-substates?
I guess you are missing the fact that the template argument passed to
deep_history is actually the *default* *state*. This is the state that is
entered when no history has ever been saved. If history has been saved (as is
the case in your example code) then transit< sc::deep_history < StateA1 > >()
will transit to whatever inner state of A was active before A was exited. This
is explained in more detail here:
<http://www.boost.org/doc/libs/1_52_0/libs/statechart/doc/tutorial.html#History>
In fact I did not missed this part of tutorial. But since documentation is almost non-existent in area of history types description, my first attempt was to set the same default state (A11) in every declaration of A substates. My idea here was that if I stated deep_history for A substates and for A itself, all history will be saved and we need default state only if there was not action inside A state before transition into it. So A should have only one default state. For me it makes sense. But it did not worked for me at all.
Next, I defined different default states for each direct A substate. I still dont understand why I should do it and how it could be that A have several default substates. At the same time I added transition from B to one of exact default states. For A1 default state was A11 and I put it into return transit < sc::deep_history < StateA11 > >(); My thought here was if I defined A11 as default state, all transactions to A should use exactly this state. This did not worked too, as I described in my first message.
And next, using your advice I changed transit from A11 to A1, but I still dont understand why I should do it this way.
As for me, most logical behavior should be like this - if A uses deep history (I take it as 'total history for all substates'), A should have single default state for cases like this C -> B -> A. But for cases A -> B -> A in B -> A transition user should use outermost state A in transition destination and do not care about how history is saved inside it or about its default state.
Thanks,
Ilya
HTH,
Andreas Huber
P.S. In your example you're also specifying sc::deep_history< StateA1 > as
InnerInitial of A. So you could even transit directly to A, as follows:
return transit < StateA >();
and get exactly the same behavior as when you write:
return transit< sc::deep_history < StateA1 > >();