PseudoState.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*===============================================================================
  2. * PseudoState
  3. *
  4. * Change history
  5. * When Who Comment
  6. * ---------- ------ ------------------------------------
  7. * 2006-07-18 RMa Changed transition handling.
  8. * 2006-02-03 RMa FXCop updates: protected methods.
  9. * 2006-01-27 RMa Removed interface Event. Use Event class instead.
  10. * 2005-12-05 RMa This header added.
  11. *
  12. ---------------------------------------------------------------------------------*/
  13. namespace Wayne.Lib.StateEngine
  14. {
  15. /// <summary>
  16. /// A pseudo state is a state that can be entered, but it must transition directly.
  17. /// The state machine can not stay in this state,but must continue directly. Therefore
  18. /// the Enter, and exit methods are sealed and can not be overriden. Insted, the abstract method CreatePseudoStateTransition method
  19. /// must be overriden. It receives the entry information and must return a transition direclty.
  20. /// The pseudo state can be used to implement choce states, and is the base class for initial states.
  21. /// </summary>
  22. abstract public class PseudoState : State
  23. {
  24. #region Sealed Methods
  25. /// <summary>
  26. /// The Exit method may not be used in a Pseudo state.
  27. /// It must transition directly after enter.
  28. /// </summary>
  29. protected sealed override void Enter(StateEntry stateEntry, ref Transition transition)
  30. {
  31. base.Enter(stateEntry, ref transition);
  32. transition = this.CreatePseudoStateTransition(stateEntry);
  33. }
  34. /// <summary>
  35. /// The Exit method may not be used in a Pseudo state.
  36. /// It must transition directly after enter.
  37. /// </summary>
  38. protected override sealed void Exit()
  39. {
  40. base.Exit();
  41. }
  42. #endregion
  43. #region Abstract Methods
  44. /// <summary>
  45. /// The CreatePseudoStateTransition method must be overriden. It receives the state
  46. /// entry, and must make a new transition directly.
  47. /// </summary>
  48. /// <param name="stateEntry"></param>
  49. /// <returns></returns>
  50. protected abstract Transition CreatePseudoStateTransition(StateEntry stateEntry);
  51. #endregion
  52. }
  53. /// <summary>
  54. /// Initial state is the first state to be entered in a state machine. There should only be one initial state, and
  55. /// the state engine automatically enters that state at startup. It is a pseudo state so it must direclty transition to
  56. /// another state.
  57. ///
  58. /// The class does not introduce any new behaviour from pseudostate, but marks that it is an intial state.
  59. /// </summary>
  60. abstract public class InitialState : PseudoState
  61. {
  62. }
  63. }