Boost logo

Boost :

From: Marc Jacobs (marcja_at_[hidden])
Date: 2002-10-30 15:45:05


"Terje Slettebø" <tslettebo_at_[hidden]> wrote in message
news:088a01c2804f$f3fa3cf0$60fb5dd5_at_pc...
> >From: "Marc Jacobs" <marcja_at_[hidden]>
> >
> > A common strategy for using this kind of state machine is raise an event
> > before doing some work to see if the work is allowed in the current
state.
> > Example:
> >
> > void BusinessObject::turnPowerOn() {
> > try {
> > context::raise( fsmtl::event< fsm::poweron >() );
> > // do work for turn the power on
> > }
> > catch( fsmtl::exception & e )
> > { ... }
> >
> > If the transition is not permitted given the current state and event, an
> > exception is thrown and no work is performed. Whether the exception is
> > rethrown, not caught, or translated into a different kind of exception
is
> up
> > to the library user.
>
> Exception handling may be expensive. Perhaps it could be good to provide a
> query, to determine if an operation may be performed.

Good suggestion. I will add it. Requires a little slight of hand given that
the state objects have no intrinsic value, just type, but entirely doable.
Usage would probably be something like:

if( context::equals( fsmtl::state< on >() ) ) {
    // ...
}

Marc


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