CHSM  4.4.1
Public Types | Public Member Functions | Protected Member Functions | List of all members
CHSM::state Class Reference

A state is the simplest kind of state in a machine: it has no child states. More...

#include <chsm.h>

Inheritance diagram for CHSM::state:
CHSM::parent CHSM::cluster CHSM::set

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...
 
parentparent_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...
 

Detailed Description

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.

Author
Paul J. Lucas

Member Typedef Documentation

typedef void(machine::* CHSM::state::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.

Parameters
sThe state that is being entered or exited.
triggerThe event that triggered the transition.
typedef int CHSM::state::id

The identification number of a state.

Constructor & Destructor Documentation

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.:

class place : public CHSM::state {
public:
place( CHSM_STATE_ARGS ) : CHSM::state( CHSM_STATE_INIT ) {
// ...
}
// ...
};
CHSM::state::~state ( )

Destroy a state.

Member Function Documentation

bool CHSM::state::active ( ) const
inline

Returns whether this state is active.

Returns
Returns true only if the state is active.

Referenced by CHSM::machine::active(), CHSM::machine::dump_state(), enter(), exit(), and CHSM::cluster::exit().

void CHSM::state::deep_clear ( )
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.

bool CHSM::state::enter ( event const &  trigger,
state from_child = 0 
)
protectedvirtual

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:

bool enter( CHSM::event const &amp;trigger, CHSM::state *from_child ) {
if ( !CHSM::state::enter( trigger, from_child ) )
return false;
// ... new functionality here ...
return true;
}
Parameters
triggerThe event that triggered the transition.
from_childNot used here.
Returns
Returns 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().

bool CHSM::state::exit ( event const &  trigger,
state to = 0 
)
protectedvirtual

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:

boolean exit( CHSM::event const &amp;trigger, CHSM::state *to ) {
if ( !CHSM::state::exit( trigger, to ) )
return false;
// ... new functionality here ...
return true;
}
Parameters
triggerThe event that triggered the transition.
toIf not null, the state to transition to.
Returns
Returns 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().

char const* CHSM::state::name ( ) const
inline

Return the name of the state.

Returns
Returns said name.

Referenced by CHSM::machine::dump_state(), enter(), and exit().

parent* CHSM::state::parent_of ( ) const
inline

Return the parent cluster or set.

Returns
Returns the parent or null if none.

Referenced by enter(), exit(), and CHSM::transition::is_legal().


The documentation for this class was generated from the following files: