CHSM
4.4.1
|
A state is the simplest kind of state in a machine: it has no child states. More...
#include <chsm.h>
Public Types | |
typedef void(machine::* | action )(state const &s, event const &trigger) |
An action is a function (machine member function) that is optionally called upon enter/exit of a state. More... | |
typedef int | id |
The identification number of a state. More... | |
Public Member Functions | |
bool | active () const |
Returns whether this state is active. More... | |
virtual void | deep_clear () |
Clears the history for all child clusters of a cluster, recursively. More... | |
char const * | name () const |
Return the name of the state. More... | |
parent * | parent_of () const |
Return the parent cluster or set. More... | |
state (CHSM_STATE_ARGS) | |
Construct a state. More... | |
~state () | |
Destroy a state. More... | |
Protected Member Functions | |
virtual bool | enter (event const &trigger, state *from_child=0) |
Enter a state. More... | |
virtual bool | exit (event const &trigger, state *to=0) |
Exit a state. More... | |
A state is the simplest kind of state in a machine: it has no child states.
A state can either be active (in the state) or inactive (not in the state); a state may have a parent, and enter/exit actions.
The state class can be extended either to add additional data members and member functions, or to alter its behavior upon being entered or exited.
An action is a function (machine member function) that is optionally called upon enter/exit of a state.
s | The state that is being entered or exited. |
trigger | The event that triggered the transition. |
typedef int CHSM::state::id |
The identification number of a state.
CHSM::state::state | ( | CHSM_STATE_ARGS | ) |
Construct a state.
When deriving a class from state
, the macros CHSM_STATE_ARGS
and CHSM_STATE_INIT
can be used to avoid having to deal with the many constructor arguments, e.g.:
CHSM::state::~state | ( | ) |
Destroy a state.
|
inline |
Returns whether this state is active.
true
only if the state is active. Referenced by CHSM::machine::active(), CHSM::machine::dump_state(), enter(), exit(), and CHSM::cluster::exit().
|
virtual |
Clears the history for all child clusters of a cluster, recursively.
Plain states have neither children nor a history. Placing this function here is a wart on the design; by having it here, however, run-time type-identification can be avoided.
Reimplemented in CHSM::cluster, and CHSM::parent.
Enter a state.
If this state's parent state (if any) isn't active, enter it first. The event $enter(
state)
is broadcast and the state's enter-action block is executed, if any.
When overriding in a derived class, the form must be:
trigger | The event that triggered the transition. |
from_child | Not used here. |
true
only if the state was actually entered, i.e., it wasn't already active. Reimplemented in CHSM::set, and CHSM::cluster.
References active(), CHSM::machine::D_enex, CHSM::machine::debug(), enter(), name(), and parent_of().
Referenced by enter(), and CHSM::cluster::enter().
Exit a state.
If the "to" state doesn't have this state's parent state (if any) as an ancestor, exit this state's parent state first. The event $exit(
state)
is broadcast and the state's exit-action block is executed, if any.
When overriding in a derived class, the form must be:
trigger | The event that triggered the transition. |
to | If not null , the state to transition to. |
true
only if the state was actually exited, i.e., it wasn't already active. Reimplemented in CHSM::set, and CHSM::cluster.
References active(), CHSM::machine::D_enex, CHSM::machine::debug(), exit(), name(), and parent_of().
Referenced by exit(), and CHSM::cluster::exit().
|
inline |
Return the name of the state.
Referenced by CHSM::machine::dump_state(), enter(), and exit().
|
inline |
Return the parent cluster or set.
null
if none. Referenced by enter(), exit(), and CHSM::transition::is_legal().