###

# The Boost Statechart Library

## UML to Boost.Statechart mapping summary

## Contents

State machine
States
  Normal state
  Initial pseudostate
  Final pseudostate
  Shallow history pseudostate
  Deep history pseudostate
  Junction point
  Dynamic choice point
  Join and fork bars
Events
  Call event
  Signal event
  Time event
  Change event
Reactions
  Guard
  Transition
  Deferral
  Internal transition (in-state reaction)
Actions
  Entry action
  Exit action
  Transition action
  Do activity

## State machine

- A state machine is defined by deriving a class from either the `state_machine` or the `asynchronous_state_machine` class templates; example

## States

### Normal state

- A state is defined by deriving a class from either the `simple_state` or `state` class templates; example
- The position of a state in the state hierarchy is defined by what is passed as the `Context` template parameter. Outermost states pass the `state_machine<>` or `asynchronous_state_machine<>` subtype they belong to, inner states pass their direct outer state; example
- A state can be made a member of a particular orthogonal region by passing an instantiation of the `orthogonal` class template nested in its outer state; example

### Initial pseudostate

- The state that is initially entered is identified by template parameters rather than by a default transition from the initial pseudostate (there is no such thing in Boost.Statechart)
- For `state_machine<>` and `asynchronous_state_machine<>` the state that is initially entered needs to be specified with the `InitialState` template parameter; example
- For `simple_state<>` and `state<>` the inner state(s) that is/are initially entered can be specified with the `InnerInitial` template parameter; example

### Final pseudostate

- There is no such thing as a final pseudostate in Boost.Statechart
- This functionality is implemented with a special reaction (`termination<>`) and special reaction function (`simple_state<>::terminate()`); example

### Shallow history pseudostate

- A shallow history transition target or shallow history inner initial state can be specified with `shallow_history<>`

### Deep history pseudostate

- A deep history transition target or deep history inner initial state can be specified with `deep_history<>`; example

### Junction point

- Does not exist in Boost.Statechart; rationale

### Dynamic choice point

- Does not (yet?) exist in Boost.Statechart; rationale

### Join and fork bars

- Do not exist in Boost.Statechart; rationale

## Events

- A event is defined by deriving a class from the `event` class template; example
- There is no distinction between signal and call events, see below

### Call event

- All events passed to `state_machine<>::process_event()` are implicitly call events

### Signal event

- All events passed to either `simple_state<>::post_event()` or `fifo_scheduler<>::queue_event()` are implicitly signal events

### Time event

- Does not exist in Boost.Statechart
- A time event can be simulated with an external timer that is started in the entry action and stopped in the exit action of a particular state. When starting the timer, it is instructed to call `fifo_scheduler<>::queue_event()` when the due time elapses

### Change event

- Does not exist in Boost.Statechart
- A change event can be simulated by packing to be monitored variables into an external wrapper with `get` and `set` methods. Whenever `set` is called the wrapper posts an appropriate event

## Reactions

### Guard

- A guard can be implemented with a selection statement in a `custom_reaction<>`; example

### Transition

- A transition can be defined with either a `transition<>` or a call to `simple_state<>::transit<>` in a `custom_reaction<>`; example

### Deferral

- A deferral reaction can be defined with either a `deferral<>` or a call to `simple_state<>::defer_event()` in a `custom_reaction<>`; example

### Internal transition (in-state reaction)

- An in-state reaction can be defined with either a `in_state_reaction<>` or a call to `simple_state<>::discard_event()` in a `custom_reaction<>`

## Actions

### Entry action

- A state entry action can be defined by adding a constructor to a state class; example

### Exit action

- A state exit action can be defined by adding a destructor to a state class; example

### Transition action

- A transition action can be defined by passing a function pointer referencing the action to either `transition<>` or `simple_state<>::transit<>()`; example

### Do activity

- Not supported in Boost.Statechart
- A do activity can be simulated with a separate thread that is started in the entry action and cancelled (!) in the exit action of a particular state

Revised 03 December, 2006

Copyright © 2003-2006 Andreas Huber Dönni

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)