BGC Tools
Public Member Functions | Data Fields | Protected Attributes | Private Attributes
BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum > Class Template Reference

This defines a transition between two states with the required transition conditions for the transition to occur More...

Collaboration diagram for BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >:
Collaboration graph
[legend]

Public Member Functions

 Transition (State targetState, params TransitionCondition< TBoolEnum, TTriggerEnum >[] transitionConditions)
 Construct abstract transtion to define path More...
 
void SetStateDataRetrievers (ITransitionDataRetriever< TBoolEnum, TTriggerEnum > stateMachine)
 Add state machine data which is required for checking info More...
 
bool ShouldTransition ()
 Test whether or not this transition should occur More...
 
void OnTransition ()
 Right before a transition this function is called so the transition and clean anything it has done up. For example: deactivating any triggers it has used is required More...
 

Data Fields

readonly State TargetState
 Get name of the state this transition goes to More...
 

Protected Attributes

ITransitionDataRetriever< TBoolEnum, TTriggerEnum > stateMachine
 

Private Attributes

readonly TransitionCondition< TBoolEnum, TTriggerEnum > [] transitionConditions
 

Detailed Description

This defines a transition between two states with the required transition conditions for the transition to occur

Type Constraints
TBoolEnum :Enum 
TTriggerEnum :Enum 

Definition at line 9 of file Transition.cs.

Constructor & Destructor Documentation

◆ Transition()

BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.Transition ( State  targetState,
params TransitionCondition< TBoolEnum, TTriggerEnum > []  transitionConditions 
)
inline

Construct abstract transtion to define path

Definition at line 25 of file Transition.cs.

28  {
29  TargetState = targetState ?? throw new ArgumentNullException(
30  paramName: nameof(targetState),
31  message: "Transition target state cannot be null.");
32 
33  this.transitionConditions = transitionConditions ?? throw new ArgumentNullException(
34  paramName: nameof(transitionConditions),
35  message: "Transition conditions cannot be null.");
36 
37  for (int i = 0; i < transitionConditions.Length; ++i)
38  {
39  if (transitionConditions[i] == null)
40  {
41  throw new ArgumentNullException(
42  paramName: nameof(transitionConditions),
43  message: $"Transition conditions element {i} is null and should not be.");
44  }
45  }
46  }
readonly TransitionCondition< TBoolEnum, TTriggerEnum > [] transitionConditions
Definition: Transition.cs:13
readonly State TargetState
Get name of the state this transition goes to
Definition: Transition.cs:20

Member Function Documentation

◆ OnTransition()

void BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.OnTransition ( )
inline

Right before a transition this function is called so the transition and clean anything it has done up. For example: deactivating any triggers it has used is required

Definition at line 88 of file Transition.cs.

Referenced by BGC.StateMachine.StateMachine< TBoolEnum, TTriggerEnum >.ExecuteTransitions().

89  {
90  for (int i = 0; i < transitionConditions.Length; ++i)
91  {
92  transitionConditions[i].OnTransition();
93  }
94  }
readonly TransitionCondition< TBoolEnum, TTriggerEnum > [] transitionConditions
Definition: Transition.cs:13
Here is the caller graph for this function:

◆ SetStateDataRetrievers()

void BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.SetStateDataRetrievers ( ITransitionDataRetriever< TBoolEnum, TTriggerEnum >  stateMachine)
inline

Add state machine data which is required for checking info

Definition at line 51 of file Transition.cs.

Referenced by BGC.StateMachine.StateMachine< TBoolEnum, TTriggerEnum >.AddAnyStateTransition(), and BGC.StateMachine.StateMachine< TBoolEnum, TTriggerEnum >.AddTransition().

52  {
53  this.stateMachine = stateMachine ?? throw new ArgumentNullException(
54  paramName: nameof(stateMachine),
55  message: "stateMachine argument cannot be null.");
56 
57  for (int i = 0; i < transitionConditions.Length; ++i)
58  {
59  transitionConditions[i].SetStateMachineFunctions(stateMachine);
60  }
61  }
readonly TransitionCondition< TBoolEnum, TTriggerEnum > [] transitionConditions
Definition: Transition.cs:13
ITransitionDataRetriever< TBoolEnum, TTriggerEnum > stateMachine
Definition: Transition.cs:15
Here is the caller graph for this function:

◆ ShouldTransition()

bool BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.ShouldTransition ( )
inline

Test whether or not this transition should occur

Returns
True if a transition should occur

Definition at line 67 of file Transition.cs.

68  {
69  bool shouldTransfer = true;
70  for (int i = 0; i < transitionConditions.Length; ++i)
71  {
72  shouldTransfer &= transitionConditions[i].ShouldTransition();
73 
74  if (shouldTransfer == false)
75  {
76  break;
77  }
78  }
79 
80  return shouldTransfer;
81  }
readonly TransitionCondition< TBoolEnum, TTriggerEnum > [] transitionConditions
Definition: Transition.cs:13

Field Documentation

◆ stateMachine

ITransitionDataRetriever<TBoolEnum, TTriggerEnum> BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.stateMachine
protected

Definition at line 15 of file Transition.cs.

◆ TargetState

readonly State BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.TargetState

Get name of the state this transition goes to

Definition at line 20 of file Transition.cs.

Referenced by BGC.StateMachine.StateMachine< TBoolEnum, TTriggerEnum >.ExecuteTransitions().

◆ transitionConditions

readonly TransitionCondition<TBoolEnum, TTriggerEnum> [] BGC.StateMachine.Transition< TBoolEnum, TTriggerEnum >.transitionConditions
private

Definition at line 13 of file Transition.cs.


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