Boost logo

Boost :

From: Andreas Huber (ah2003_at_[hidden])
Date: 2003-05-31 08:52:10


Hi,

Whenever I had to develop an FSM in the past, I chose either of the
following paths:
- For small and simple machines I often resorted to the IMHO ugly nested
switch-case approach.
- For bigger and more complex machines, I often used a code-generation
approach because I failed to find a satisfactory library.

No matter what solution I chose, I have always been missing
code-expressiveness, ease-of-use and good maintainability.

An attempt at an easy-to-use FSM library that supports well-maintainable and
code-expressive machines of almost any size and does not require a code
generator can be found in the fsm directories in the boost-sandbox and here:

http://groups.yahoo.com/group/boost/files/FSM/

There is comprehensive tutorial and rationale documentation. All code has
been tested with MSVC7.1 and boost 1.30.0

Features include:

- Straightforward transformation from UML state chart to executable C++ code
and vice versa
- Comprehensive UML semantics support:
   - Hierarchical (composite, nested) states
   - Orthogonal (concurrent) states
   - Entry-, exit- and transition-actions
   - Guards
   - Event deferral
- Error handling support
- Full type-safety
- State-local storage
- Customizable resource management

Any feedback is most welcome.

Thanks,

Andreas

P.S. For people who are not yet using the boost library and would like to
run
the examples, FSM.zip contains a 4-step quick start guide.

P.P.S. Developer summary ;-), copy-paste into your code editor:

////////////////////////////////////////////////////////////////////////////
// The following code implements the state-machine:
// --------------------------------
// | |
// | O Active |
// | | |<----
// | v | | EvReset
// | ---------------------------- | |
// | | | |-----
// | | Stopped | |
// | ---------------------------- |
// | | ^ |
// | | EvStartStop | EvStartStop |<-----O
// | v | |
// | ---------------------------- |
// | | | |
// | | Running | |
// | ---------------------------- |
// --------------------------------
#include <boost/fsm/event.hpp>
#include <boost/fsm/state_machine.hpp>
#include <boost/fsm/simple_state.hpp>
#include <boost/fsm/transition.hpp>

namespace fsm = boost::fsm;

class EvStartStop : public fsm::event< EvStartStop > {};
class EvReset : public fsm::event< EvReset > {};

struct Active;
struct StopWatch : public fsm::state_machine< StopWatch, Active > {};

struct Stopped;
struct Active : public fsm::simple_state< Active, StopWatch,
  fsm::transition< EvReset, Active >, Stopped > {};

struct Running : public fsm::simple_state< Running, Active,
  fsm::transition< EvStartStop, Stopped > > {};

struct Stopped : public fsm::simple_state< Stopped, Active,
  fsm::transition< EvStartStop, Running > > {};

int main( int argc, char * argv[] )
{
  StopWatch myWatch;
  myWatch.initiate();
  myWatch.process_event( EvStartStop() );
  myWatch.process_event( EvStartStop() );
  myWatch.process_event( EvStartStop() );
  myWatch.process_event( EvReset() );
  return 0;
}


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