I’m hoping that someone can help me out with this problem, or at least point out the error of my ways…
As a simple illustration of my problem consider a part of an application where you can enter a “Functions Mode” state of operation. Four sub-modes are then available depending on which function key F1-F4 that the user presses. By default, F1 mode is entered. The state diagram starts off as follows:

The user can press F1-F4 at any time to switch to the corresponding mode. Adding these transitions to the inner states leads to the following:

Obviously this is (a) a mess, and (b) a lot of transitions to define. If at some point I want to add an F5Mode then… well, you get the picture. To avoid this I’d like to do the following:

Boost Statechart allows me to define transitions from FunctionMode to any of the inner states, but the result isn’t what I expected. The actual outcome is as follows:

I.e. pressing F1-F4 to switch modes causes the outer FunctionMode state to be exited and re-entered along with triggering the unwanted exit and entry actions.
Way back in 2006, this thread between the library author and a user seems to describe the same problem. I think that the author suggests doing the following as a work-around:
However, that work-around doesn’t seem very appealing to me: It has added an extra state level to be compiled, the code has become less readable, deep-history would have to be used to return to any of the function mode sub-states and the Intermediate state object is needlessly being destructed and constructed again.
So… where am I going wrong? Or what are the alternatives? I’ve had a brief look at Boost Meta State Machine (msm) but from what I’ve seen so far I much prefer the look of Statechart.
I’m surprised that more users haven’t faced the same problem… which makes me think that perhaps my approach is completely wrong!
Have you looked at the in-state reaction explained in the statechart tutorial? It seems to be doing what you are looking for.
Since you are asking for alternatives, in this period I am evaluating various C++ Harel statechart implementations. I looked at Boost statechart and Boost MSM. I wrote code with both. They hurt my feeble brain 🙂
Then I found Machine Objects (Macho), very simple and small, and I love it. It supports hierarchical state machines, entry/exit actions, history, state machine snapshots, guards, internal transitions, event deferring, state-local storage (with optional persistence), so to me it is a satisfying Harel statechart implementation.
This code implements the FunctionMode part of the statechart with Macho:
Running it, the output is:
that shows that the transitions are internal.
In my opinion, clean, easy and compact code 🙂
[EDIT1] The first version of the code didn’t perform the initial transition
FunctionMode->F1Mode. Now it does.