PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | Related Functions | List of all members
PIStateBase Class Reference

Base class for states in a hierarchical state machine. More...

#include <pistatemachine_state.h>

Inheritance diagram for PIStateBase:
Inheritance graph
[legend]

Public Member Functions

 PIStateBase (const PIString &n={})
 Creates a state with an optional diagnostic name.
 
virtual ~PIStateBase ()
 Destroys the state together with owned child states and transitions.
 
virtual void onEnter ()
 Called when the state becomes active.
 
virtual void onExit ()
 Called when the state becomes inactive.
 
virtual void onFinish ()
 Called when a final child finishes this state.
 
PIStateMachinemachine () const
 Returns the root state machine.
 
PIStateBaseparent () const
 Returns the parent state.
 
PIStateBaseactiveChild () const
 Returns the active child of a non-parallel compound state.
 
PIVector< PIStateBase * > activeChildren () const
 Returns active child states.
 
PIVector< PIStateBase * > activeAtomics () const
 Returns active atomic leaf states below this state.
 
void addState (PIStateBase *s)
 Adds a child state owned by this state.
 
void addStates (PIVector< PIStateBase * > s)
 Adds multiple child states owned by this state.
 
void setInitialState (PIStateBase *s)
 Sets the initial child state for a non-parallel compound state.
 
PITransitionBaseaddTransition (PIStateBase *target, int event_id)
 Adds an event-driven transition from this state to target.
 
PITransitionTimeoutaddTimeoutTransition (PIStateBase *target, PISystemTime timeout)
 Adds a timeout transition that fires while this state stays active.
 
void setParallel (bool yes)
 Enables or disables parallel activation of child states.
 
const PIStringgetName () const
 Returns the state name.
 
bool isStateMachine () const
 Returns true for the root machine object.
 
bool isActive () const
 Returns true if the state is currently active.
 
bool isParallel () const
 Returns true if child states are activated in parallel.
 
bool isFinal () const
 Returns true if the state is marked as final.
 
bool isAtomic () const
 Returns true if the state has no children.
 
bool isCompound () const
 Returns true if the state owns child states.
 
const PIVector< PIStateBase * > & getChildren () const
 Returns direct child states.
 
const PIVector< PITransitionBase * > & getTransitions () const
 Returns outgoing transitions owned by this state.
 
void print (PIString prefix={})
 Prints the state tree and active branches to piCout.
 
PIVector< PIStateBase * > gatherStates ()
 Returns this state and all descendant states.
 

Related Functions

(Note that these are not member functions.)

PICout operator<< (PICout c, PIStateBase *s)
 Writes a textual representation of a state to PICout.
 

Detailed Description

Base class for states in a hierarchical state machine.

A state can own child states and outgoing transitions. Compound states activate either their initial child state or all children when parallel mode is enabled.