I'm trying to learn boost::statechart.
I want to make a little app which loads a file.
// --------------------------------
// | |
// | O Project |
// | | |
// | v |
// | ---------------------------- |
// | | | |
// | | Unloaded | |
// | ---------------------------- |
// | | ^ |
// | | EvLoad | EvUnload |<-----O
// | v | |
// | ---------------------------- |
// | | | |
// | | Loaded | |
// | ---------------------------- |
// | | ^ |
// | | | EvLoad |
// | ----- |
// --------------------------------
But how do i transport arguments to the state, e.g. a filename? If i store the filename inside EvLoad i can access it easily for the in state reaction
struct Loaded : sc::simple_state< Loaded, Project>
{
typedef sc::custom_reaction< EvLoad > reactions;
sc::result react( const EvLoad & e )
{
//load file e.path()
...
return discard_event();
}
}
But when I'm in the Unloaded state then I'm invoking the constructor of Loaded and i can't pass arguments to it. The only workaround I came up with is reposting the event before doing the transition, but this looks a bit dirty to me.
struct Unloaded : sc::simple_state< Unloaded, Project >
{
typedef sc::custom_reaction< EvLoad > reactions;
sc::result react( const EvLoad & e )
{
post_event( e ); //workaround to pass the event to the loaded state
return transit<Loaded>();
}
};
Is there a better alternative?