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

Root object that owns and runs a hierarchical state machine. More...

#include <pistatemachine.h>

Inheritance diagram for PIStateMachine:
Inheritance graph
[legend]

Public Member Functions

 PIStateMachine (const PIString &n={})
 Creates a state machine with an optional name.
 
bool start ()
 Starts the machine from its initial active configuration.
 
bool isRunning () const
 Returns true while the machine is running.
 
void setOnFinish (std::function< void()> f)
 Sets a callback invoked when the machine finishes.
 
template<typename... Args>
bool postEvent (int event_id, Args... args)
 Posts an event to active states and triggers the first matching transition.
 
- Public Member Functions inherited from PIStateBase
 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.
 

Additional Inherited Members

Detailed Description

Root object that owns and runs a hierarchical state machine.