WSF
WsfScriptStateMachine Class Reference

#include <WsfScriptStateMachine.hpp>

Inheritance diagram for WsfScriptStateMachine:
Collaboration diagram for WsfScriptStateMachine:

Classes

class  Transition
class  State

Public Types

using TransitionList = std::vector<std::unique_ptr<Transition>>
 A list of transitions.
using StateList = std::vector<std::unique_ptr<State>>
 A collection of states.

Public Member Functions

 WsfScriptStateMachine ()=default
 WsfScriptStateMachine (WsfScriptContext &aContext, WsfScriptProcessor *aParentProcPtr=nullptr, WsfStringId aParentNameSpace=nullptr)
 WsfScriptStateMachine (const WsfScriptStateMachine &aSrc, WsfScriptContext &aContext, WsfScriptProcessor *aParentProcPtr=nullptr)
virtual ~WsfScriptStateMachine ()=default
const WsfScriptStateMachineoperator= (const WsfScriptStateMachine &aRhs)=delete
 WsfScriptStateMachine (const WsfScriptStateMachine &aSrc)=delete
const size_t Id () const
 Return the id for this state machine.
virtual void EnterStateNotify (int aStateIndex)
virtual void ExitStateNotify (int aStateIndex)
virtual int Evaluate (int aCurrentStateIndex)
virtual int EvaluateState (int aCurrentStateIndex, bool aDoNewStateEntry=true)
virtual void EnterState (int aStateIndex)
virtual void ExitState (int aStateIndex)
StateFindState (WsfStringId aStateName) const
int GetInitialStateIndex () const
StateGetState (int aStateIndex) const
int GetStateCount () const
 Return the number of states in the state machine.
int GetStateIndex (WsfStringId aStateName) const
WsfStringId GetStateName (int aStateIndex) const
 Return the name (ID) of a state given its state index.
virtual bool Initialize (double aSimTime)
virtual bool ProcessInput (UtInput &aInput)
void ShowStateEvaluations (bool aShowStateEvaluations)
bool ShowStateEvaluations () const
void ShowStateTransitions (bool aShowStateTransitions)
bool ShowStateTransitions () const
void SetProcessor (WsfScriptProcessor *aProcessor)
WsfScriptProcessorProcessor ()

Static Public Member Functions

static std::unique_ptr< UtScriptClass > CreateScriptClass (const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)

Protected Member Functions

virtual void EnterState (State *aStatePtr)
virtual void ExitState (State *aStatePtr)
virtual std::unique_ptr< StateCreateState (WsfStringId aStateName, WsfScriptContext &aContext)

Protected Attributes

WsfScriptContextmContextPtr {nullptr}
 The context used for compiling and executing scripts.
WsfStringId mParentNameSpace
StateList mStateList
 The list of states.
bool mShowStateEvaluations {false}
bool mShowStateTransitions {false}
WsfScriptProcessormParentProcessorPtr {nullptr}
size_t mId
 Unique integer id of this state machine.

Detailed Description

A finite state machine that can be controlled via the scripting language. A object of this class can be used to provide a scriptable finite state machine.

This class and the nested classes State and Transition can be extended. If you extend State then you must:

If you are going to extend Transition then you must also do the above AND

  • provide a Clone method in your extended Transition class.
  • provide a CreateTransition method in your extended State class.

Member Typedef Documentation

◆ StateList

using WsfScriptStateMachine::StateList = std::vector<std::unique_ptr<State>>

A collection of states.

◆ TransitionList

using WsfScriptStateMachine::TransitionList = std::vector<std::unique_ptr<Transition>>

A list of transitions.

Constructor & Destructor Documentation

◆ WsfScriptStateMachine() [1/4]

◆ WsfScriptStateMachine() [2/4]

WsfScriptStateMachine::WsfScriptStateMachine ( WsfScriptContext & aContext,
WsfScriptProcessor * aParentProcPtr = nullptr,
WsfStringId aParentNameSpace = nullptr )

Constructor.

Parameters
aContextThe script context in which scripts are to be compiled and executed.
aParentProcPtrPointer to the parent processor of the state machine
aParentNameSpaceThe string name ID of the parent processor namespace

References mContextPtr, mId, mParentNameSpace, mParentProcessorPtr, mShowStateEvaluations, mShowStateTransitions, and mStateList.

◆ WsfScriptStateMachine() [3/4]

WsfScriptStateMachine::WsfScriptStateMachine ( const WsfScriptStateMachine & aSrc,
WsfScriptContext & aContext,
WsfScriptProcessor * aParentProcPtr = nullptr )

Copy constructor.

Parameters
aSrcThe source state machine.
aContextThe script context in which scripts are to be compiled and executed.
aParentProcPtrPointer to the parent processor of the state machine

References mContextPtr, mId, mParentNameSpace, mParentProcessorPtr, mShowStateEvaluations, mShowStateTransitions, mStateList, and WsfScriptStateMachine().

◆ ~WsfScriptStateMachine()

virtual WsfScriptStateMachine::~WsfScriptStateMachine ( )
virtualdefault

◆ WsfScriptStateMachine() [4/4]

WsfScriptStateMachine::WsfScriptStateMachine ( const WsfScriptStateMachine & aSrc)
delete

Member Function Documentation

◆ CreateScriptClass()

std::unique_ptr< UtScriptClass > WsfScriptStateMachine::CreateScriptClass ( const std::string & aClassName,
UtScriptTypes * aScriptTypesPtr )
static

Create the 'class' object for the script system. This is invoked once by WsfScriptManager to create the 'class' object that defines the interface to instances of this class from the script system.

Referenced by WsfScriptManager::RegisterTypes(), and WsfScriptStateMachine().

◆ CreateState()

std::unique_ptr< WsfScriptStateMachine::State > WsfScriptStateMachine::CreateState ( WsfStringId aStateName,
WsfScriptContext & aContext )
protectedvirtual

Create an empty State object. A derived class must override this method to create their specific type of State object.

Referenced by ProcessInput().

◆ EnterState() [1/2]

void WsfScriptStateMachine::EnterState ( int aStateIndex)
virtual

An external method to perform the actions associated with entering a state. This method is provided to allow the caller to control state transitions explicitly.

Parameters
aStateIndexThe index of the state that is being entered.

References EnterState(), and GetState().

Referenced by EnterState(), Evaluate(), EvaluateState(), and WsfScriptProcessor::SetStateAll().

◆ EnterState() [2/2]

void WsfScriptStateMachine::EnterState ( State * aStatePtr)
protectedvirtual

An internal method to perform the operations associated with entering a state.

Parameters
aStatePtrThe state that is being entered.

References WsfScriptStateMachine::State::EnterState(), EnterStateNotify(), WsfScriptStateMachine::State::GetStateIndex(), WsfScriptStateMachine::State::GetStateName(), and mShowStateTransitions.

◆ EnterStateNotify()

virtual void WsfScriptStateMachine::EnterStateNotify ( int aStateIndex)
inlinevirtual

This method is invoked by the base class whenever a state is about to be entered.

Parameters
aStateIndexThe index of the state [1..N] that is about to be entered.

Reimplemented in WsfTrackStateController::TrackStateMachine.

Referenced by EnterState().

◆ Evaluate()

int WsfScriptStateMachine::Evaluate ( int aCurrentStateIndex)
virtual

Evaluate transition rules. This method applies the transition rules for the current state to determine if a state transition should occur. If a transition is to occur, the follow steps occur:

  • the 'on_exit' script for the current state (if defined) is executed.
  • the 'on_entry' script for the new state (if defined) is executed.
  • the transition rules for the new state are executed. If any transition rule in the new state then the exit/entry/evaluate process is repeated. This continues until no transition occurs.
    Parameters
    aCurrentStateIndexThe current state (index) within the machine. This should be zero on the initial call.
    Returns
    The resulting state within in the machine. This may be the same as aCurrentStateIndex if no transitions occur.

References EnterState(), WsfScriptStateMachine::State::Evaluate(), ExitState(), GetInitialStateIndex(), GetState(), WsfScriptStateMachine::State::GetStateIndex(), mContextPtr, mShowStateEvaluations, mStateList, and WsfObserver::StateMachineState().

◆ EvaluateState()

int WsfScriptStateMachine::EvaluateState ( int aCurrentStateIndex,
bool aDoNewStateEntry = true )
virtual

Evaluate the transition rules for the current state only. This is like Evaluate() except that it will not cascade through multiple states. This method allows the caller to detect each and every state change and maintain any information they deem necessary.

If evaluating the rules for the current state causes a transition then the 'on_exit' for the current state will be executed (if it is defined). If 'aDoNewStateEntry' is true and the 'on_entry' for the new state is defined, it will be executed but no transition rules will be executed in the new state.

Parameters
aCurrentStateIndexThe current state (index) within the machine. This should be zero on the initial call.
aDoNewStateEntryThis is used only if the evaluation indicates a transition should occur. If 'true', the OnEntry method will be executed for the new state. If 'false' it will be the responsibility of the caller to invoke the OnEntry method at the appropriate time.
Returns
The resulting state within in the machine. This may be the same as aCurrentStateIndex if a transition does not occur.

References EnterState(), WsfScriptStateMachine::State::Evaluate(), ExitState(), GetInitialStateIndex(), GetState(), WsfScriptStateMachine::State::GetStateIndex(), mContextPtr, mShowStateEvaluations, mStateList, and WsfObserver::StateMachineState().

◆ ExitState() [1/2]

void WsfScriptStateMachine::ExitState ( int aStateIndex)
virtual

An external method to perform the actions associated with exiting a state. This method is provided to allow the caller to control state transitions explicitly.

Parameters
aStateIndexThe index of the state that is being left.

References ExitState(), and GetState().

Referenced by Evaluate(), EvaluateState(), ExitState(), and WsfScriptProcessor::SetStateAll().

◆ ExitState() [2/2]

void WsfScriptStateMachine::ExitState ( State * aStatePtr)
protectedvirtual

An internal method to perform the operations associated with exiting a state.

Parameters
aStatePtrThe state that is being exited.

References WsfScriptStateMachine::State::ExitState(), ExitStateNotify(), WsfScriptStateMachine::State::GetStateIndex(), WsfScriptStateMachine::State::GetStateName(), and mShowStateTransitions.

◆ ExitStateNotify()

virtual void WsfScriptStateMachine::ExitStateNotify ( int aStateIndex)
inlinevirtual

This method is invoked by the base class whenever a state is about to be exited.

Parameters
aStateIndexThe index of the state [1..N] that is about to be exit.

Reimplemented in WsfTrackStateController::TrackStateMachine.

Referenced by ExitState().

◆ FindState()

WsfScriptStateMachine::State * WsfScriptStateMachine::FindState ( WsfStringId aStateName) const

Find a State object given its state name (ID).

Parameters
aStateNameThe desired state name (ID).
Returns
A pointer to the State object or 0 if the requested state does not exist.

References mStateList.

Referenced by GetStateIndex(), WsfScriptStateMachine::State::Initialize(), and ProcessInput().

◆ GetInitialStateIndex()

int WsfScriptStateMachine::GetInitialStateIndex ( ) const

Get the state index of the first state in the machine. For now the return value will be 1, but this allows the provision to define a machine where the initial state is something other than the first state.

References mStateList.

Referenced by Evaluate(), EvaluateState(), and UT_DEFINE_SCRIPT_METHOD().

◆ GetState()

WsfScriptStateMachine::State * WsfScriptStateMachine::GetState ( int aStateIndex) const

Return a State object given its state index.

Parameters
aStateIndexThe desired state index.
Returns
A pointer to the State object or nullptr if the requested state does not exist.

References mStateList.

Referenced by EnterState(), Evaluate(), EvaluateState(), ExitState(), GetStateName(), WsfScriptProcessor::SetStateAll(), WsfScriptProcessor::StateAll(), UT_DEFINE_SCRIPT_METHOD(), and UT_DEFINE_SCRIPT_METHOD().

◆ GetStateCount()

int WsfScriptStateMachine::GetStateCount ( ) const
inline

Return the number of states in the state machine.

References mStateList.

◆ GetStateIndex()

int WsfScriptStateMachine::GetStateIndex ( WsfStringId aStateName) const

Return the index of the state with the specified name (ID).

Parameters
aStateNameThe string ID of the state whose index is to be returned.
Returns
The index of the state with the specified name or 0 if the name does not represent a valid state.

References FindState(), and WsfScriptStateMachine::State::GetStateIndex().

Referenced by WsfScriptProcessor::SetStateAll(), and UT_DEFINE_SCRIPT_METHOD().

◆ GetStateName()

WsfStringId WsfScriptStateMachine::GetStateName ( int aStateIndex) const

Return the name (ID) of a state given its state index.

References GetState(), and WsfScriptStateMachine::State::GetStateName().

Referenced by WsfScriptStateMachine::State::Evaluate(), and WsfScriptProcessor::StateAll().

◆ Id()

const size_t WsfScriptStateMachine::Id ( ) const
inline

Return the id for this state machine.

References mId.

◆ Initialize()

bool WsfScriptStateMachine::Initialize ( double aSimTime)
virtual

Initialize the state machine.

Parameters
aSimTimeThe current simulation time.
Returns
'true' if successful or 'false' if the state machine could not be initialized.

References mContextPtr, mStateList, ok, and WsfObserver::StateMachine().

◆ operator=()

const WsfScriptStateMachine & WsfScriptStateMachine::operator= ( const WsfScriptStateMachine & aRhs)
delete

◆ ProcessInput()

bool WsfScriptStateMachine::ProcessInput ( UtInput & aInput)
virtual

◆ Processor()

WsfScriptProcessor * WsfScriptStateMachine::Processor ( )
inline

◆ SetProcessor()

void WsfScriptStateMachine::SetProcessor ( WsfScriptProcessor * aProcessor)
inline

References mParentProcessorPtr.

◆ ShowStateEvaluations() [1/2]

bool WsfScriptStateMachine::ShowStateEvaluations ( ) const
inline

References mShowStateEvaluations.

◆ ShowStateEvaluations() [2/2]

void WsfScriptStateMachine::ShowStateEvaluations ( bool aShowStateEvaluations)
inline

References mShowStateEvaluations.

◆ ShowStateTransitions() [1/2]

bool WsfScriptStateMachine::ShowStateTransitions ( ) const
inline

References mShowStateTransitions.

◆ ShowStateTransitions() [2/2]

void WsfScriptStateMachine::ShowStateTransitions ( bool aShowStateTransitions)
inline

References mShowStateTransitions.

Member Data Documentation

◆ mContextPtr

WsfScriptContext* WsfScriptStateMachine::mContextPtr {nullptr}
protected

The context used for compiling and executing scripts.

Referenced by Evaluate(), EvaluateState(), Initialize(), ProcessInput(), WsfScriptStateMachine(), and WsfScriptStateMachine().

◆ mId

size_t WsfScriptStateMachine::mId
protected

Unique integer id of this state machine.

Referenced by Id(), WsfScriptStateMachine(), and WsfScriptStateMachine().

◆ mParentNameSpace

WsfStringId WsfScriptStateMachine::mParentNameSpace
protected

◆ mParentProcessorPtr

WsfScriptProcessor* WsfScriptStateMachine::mParentProcessorPtr {nullptr}
protected

◆ mShowStateEvaluations

bool WsfScriptStateMachine::mShowStateEvaluations {false}
protected

◆ mShowStateTransitions

bool WsfScriptStateMachine::mShowStateTransitions {false}
protected

◆ mStateList


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved