Boost logo

Boost :

From: Bohdan (gejrlaug_at_[hidden])
Date: 2003-06-03 19:05:00


"Andreas Huber" <ah2003_at_[hidden]> wrote in message
news:bbisn4$3qf$1_at_main.gmane.org...
> After posting I realized that the current interface already allows you to
> hide states. E.g. you often want to ensure that a machine is initiated
> during construction:
>
> *StopWatch.hpp*:
>
> struct Active; // the only visible forward
> struct StopWatch : fsm::state_machine< StopWatch, Active >
> {
> StopWatch();
> };
>
> *StopWatch.cpp*:
>
> struct Stopped;
> struct Active : fsm::simple_state< Active, StopWatch,
> fsm::transition< EvReset, Active >, Stopped > {};
> struct Running : fsm::simple_state< Running, Active,
> fsm::transition< EvStartStop, Stopped > > {};
> struct Stopped : fsm::simple_state< Stopped, Active,
> fsm::transition< EvStartStop, Running > > {};
>
> StopWatch::StopWatch()
> {
> initiate();
> }
>
> The trick is to place the initiate(); call in a location where all states
> are known.
>
> So, clients see only one forward declaration of the initial state while all
> the other states are hidden in the .cpp file. However, this approach still
> exposes the whole state_machine interface to the clients (StopWatch *must*
> derive publicly from state_machine), which is often not what you want. In
> real-world code you'd probably more often have the state_machine subclass as
> a data member, maybe even more hidden with a pimpl.
>
> I therefore think that it is not necessary to change the current interface
> for information hiding purposes. Granted, it's not perfect, but the
> alternative I've outlined in my previous post isn't either, as Reece has
> pointed out. I might support both interfaces if there are other use cases
> that don't work with the current interface.
>
> Regards,
>
> Andreas

I vote for both interfaces. If feature is easy to implement and
if it allows to avoid even forward state declaration than why
not ? I think you are right and initial state template parameter
will simpify code, but allowing default "InnerInitial = detail::empty_list"
as you did it for state template will allow complete removing of
initial state from interface.
  BTW what about run-time selection of initial states ? :

 StopWatch::StopWatch()
 {
    if( ... )
          initiate<MyInitialState1>();
    else
    {
          initiate<MyInitialState2>();
          initiate<MyOrthohonalInitialState2>();
    }
 }

...

regards,
bohdan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk