|
WSF
|
#include <WsfScriptStateMachine.hpp>


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 WsfScriptStateMachine & | operator= (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) |
| State * | FindState (WsfStringId aStateName) const |
| int | GetInitialStateIndex () const |
| State * | GetState (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) |
| WsfScriptProcessor * | Processor () |
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< State > | CreateState (WsfStringId aStateName, WsfScriptContext &aContext) |
Protected Attributes | |
| WsfScriptContext * | mContextPtr {nullptr} |
| The context used for compiling and executing scripts. | |
| WsfStringId | mParentNameSpace |
| StateList | mStateList |
| The list of states. | |
| bool | mShowStateEvaluations {false} |
| bool | mShowStateTransitions {false} |
| WsfScriptProcessor * | mParentProcessorPtr {nullptr} |
| size_t | mId |
| Unique integer id of this state machine. | |
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
| using WsfScriptStateMachine::StateList = std::vector<std::unique_ptr<State>> |
A collection of states.
| using WsfScriptStateMachine::TransitionList = std::vector<std::unique_ptr<Transition>> |
A list of transitions.
|
default |
References WsfScriptStateMachine().
Referenced by WsfScriptStateMachine::State::ChildStateMachine(), WsfScriptStateMachine::State::Initialize(), operator=(), WsfScriptStateMachine::State::ProcessInput(), WsfTrackStateController::TrackStateMachine::TrackStateMachine(), WsfTrackStateController::TrackStateMachine::TrackStateMachine(), WsfScriptStateMachine(), WsfScriptStateMachine(), and WsfScriptStateMachine().
| WsfScriptStateMachine::WsfScriptStateMachine | ( | WsfScriptContext & | aContext, |
| WsfScriptProcessor * | aParentProcPtr = nullptr, | ||
| WsfStringId | aParentNameSpace = nullptr ) |
Constructor.
| aContext | The script context in which scripts are to be compiled and executed. |
| aParentProcPtr | Pointer to the parent processor of the state machine |
| aParentNameSpace | The string name ID of the parent processor namespace |
References mContextPtr, mId, mParentNameSpace, mParentProcessorPtr, mShowStateEvaluations, mShowStateTransitions, and mStateList.
| WsfScriptStateMachine::WsfScriptStateMachine | ( | const WsfScriptStateMachine & | aSrc, |
| WsfScriptContext & | aContext, | ||
| WsfScriptProcessor * | aParentProcPtr = nullptr ) |
Copy constructor.
| aSrc | The source state machine. |
| aContext | The script context in which scripts are to be compiled and executed. |
| aParentProcPtr | Pointer to the parent processor of the state machine |
References mContextPtr, mId, mParentNameSpace, mParentProcessorPtr, mShowStateEvaluations, mShowStateTransitions, mStateList, and WsfScriptStateMachine().
|
virtualdefault |
|
delete |
References CreateScriptClass(), and WsfScriptStateMachine().
|
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().
|
protectedvirtual |
Create an empty State object. A derived class must override this method to create their specific type of State object.
Referenced by ProcessInput().
|
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.
| aStateIndex | The index of the state that is being entered. |
References EnterState(), and GetState().
Referenced by EnterState(), Evaluate(), EvaluateState(), and WsfScriptProcessor::SetStateAll().
|
protectedvirtual |
An internal method to perform the operations associated with entering a state.
| aStatePtr | The state that is being entered. |
References WsfScriptStateMachine::State::EnterState(), EnterStateNotify(), WsfScriptStateMachine::State::GetStateIndex(), WsfScriptStateMachine::State::GetStateName(), and mShowStateTransitions.
|
inlinevirtual |
This method is invoked by the base class whenever a state is about to be entered.
| aStateIndex | The index of the state [1..N] that is about to be entered. |
Reimplemented in WsfTrackStateController::TrackStateMachine.
Referenced by EnterState().
|
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:
| aCurrentStateIndex | The current state (index) within the machine. This should be zero on the initial call. |
References EnterState(), WsfScriptStateMachine::State::Evaluate(), ExitState(), GetInitialStateIndex(), GetState(), WsfScriptStateMachine::State::GetStateIndex(), mContextPtr, mShowStateEvaluations, mStateList, and WsfObserver::StateMachineState().
|
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.
| aCurrentStateIndex | The current state (index) within the machine. This should be zero on the initial call. |
| aDoNewStateEntry | This 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. |
References EnterState(), WsfScriptStateMachine::State::Evaluate(), ExitState(), GetInitialStateIndex(), GetState(), WsfScriptStateMachine::State::GetStateIndex(), mContextPtr, mShowStateEvaluations, mStateList, and WsfObserver::StateMachineState().
|
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.
| aStateIndex | The index of the state that is being left. |
References ExitState(), and GetState().
Referenced by Evaluate(), EvaluateState(), ExitState(), and WsfScriptProcessor::SetStateAll().
|
protectedvirtual |
An internal method to perform the operations associated with exiting a state.
| aStatePtr | The state that is being exited. |
References WsfScriptStateMachine::State::ExitState(), ExitStateNotify(), WsfScriptStateMachine::State::GetStateIndex(), WsfScriptStateMachine::State::GetStateName(), and mShowStateTransitions.
|
inlinevirtual |
This method is invoked by the base class whenever a state is about to be exited.
| aStateIndex | The index of the state [1..N] that is about to be exit. |
Reimplemented in WsfTrackStateController::TrackStateMachine.
Referenced by ExitState().
| WsfScriptStateMachine::State * WsfScriptStateMachine::FindState | ( | WsfStringId | aStateName | ) | const |
Find a State object given its state name (ID).
| aStateName | The desired state name (ID). |
References mStateList.
Referenced by GetStateIndex(), WsfScriptStateMachine::State::Initialize(), and ProcessInput().
| 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().
| WsfScriptStateMachine::State * WsfScriptStateMachine::GetState | ( | int | aStateIndex | ) | const |
Return a State object given its state index.
| aStateIndex | The desired state index. |
References mStateList.
Referenced by EnterState(), Evaluate(), EvaluateState(), ExitState(), GetStateName(), WsfScriptProcessor::SetStateAll(), WsfScriptProcessor::StateAll(), UT_DEFINE_SCRIPT_METHOD(), and UT_DEFINE_SCRIPT_METHOD().
|
inline |
Return the number of states in the state machine.
References mStateList.
| int WsfScriptStateMachine::GetStateIndex | ( | WsfStringId | aStateName | ) | const |
Return the index of the state with the specified name (ID).
| aStateName | The string ID of the state whose index is to be returned. |
References FindState(), and WsfScriptStateMachine::State::GetStateIndex().
Referenced by WsfScriptProcessor::SetStateAll(), and UT_DEFINE_SCRIPT_METHOD().
| 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().
|
inline |
Return the id for this state machine.
References mId.
|
virtual |
Initialize the state machine.
| aSimTime | The current simulation time. |
References mContextPtr, mStateList, ok, and WsfObserver::StateMachine().
|
delete |
References WsfScriptStateMachine().
|
virtual |
References CreateState(), FindState(), mContextPtr, mParentNameSpace, mShowStateEvaluations, mShowStateTransitions, and mStateList.
|
inline |
References mParentProcessorPtr.
Referenced by WsfScriptStateMachine::State::Initialize().
|
inline |
References mParentProcessorPtr.
|
inline |
References mShowStateEvaluations.
|
inline |
References mShowStateEvaluations.
|
inline |
References mShowStateTransitions.
|
inline |
References mShowStateTransitions.
|
protected |
The context used for compiling and executing scripts.
Referenced by Evaluate(), EvaluateState(), Initialize(), ProcessInput(), WsfScriptStateMachine(), and WsfScriptStateMachine().
|
protected |
Unique integer id of this state machine.
Referenced by Id(), WsfScriptStateMachine(), and WsfScriptStateMachine().
|
protected |
Referenced by ProcessInput(), WsfScriptStateMachine(), and WsfScriptStateMachine().
|
protected |
Referenced by Processor(), SetProcessor(), WsfScriptStateMachine(), and WsfScriptStateMachine().
|
protected |
|
protected |
|
protected |
The list of states.
Referenced by Evaluate(), EvaluateState(), FindState(), GetInitialStateIndex(), GetState(), GetStateCount(), Initialize(), ProcessInput(), WsfScriptStateMachine(), and WsfScriptStateMachine().