PseudoState.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. using System;
  14. namespace Wayne.Lib.StateEngine
  15. {
  16. /// <summary>
  17. /// A pseudo state is a state that can be entered, but it must transition directly.
  18. /// The state machine can not stay in this state,but must continue directly. Therefore
  19. /// the Enter, and exit methods are sealed and can not be overriden. Insted, the abstract method CreatePseudoStateTransition method
  20. /// must be overriden. It receives the entry information and must return a transition direclty.
  21. /// The pseudo state can be used to implement choce states, and is the base class for initial states.
  22. /// </summary>
  23. abstract public class PseudoState : State
  24. {
  25. #region Sealed Methods
  26. /// <summary>
  27. /// The Exit method may not be used in a Pseudo state.
  28. /// It must transition directly after enter.
  29. /// </summary>
  30. protected sealed override void Enter(StateEntry stateEntry, ref Transition transition)
  31. {
  32. base.Enter(stateEntry, ref transition);
  33. transition = this.CreatePseudoStateTransition(stateEntry);
  34. }
  35. /// <summary>
  36. /// The Exit method may not be used in a Pseudo state.
  37. /// It must transition directly after enter.
  38. /// </summary>
  39. protected override sealed void Exit()
  40. {
  41. base.Exit();
  42. }
  43. #endregion
  44. #region Abstract Methods
  45. /// <summary>
  46. /// The CreatePseudoStateTransition method must be overriden. It receives the state
  47. /// entry, and must make a new transition directly.
  48. /// </summary>
  49. /// <param name="stateEntry"></param>
  50. /// <returns></returns>
  51. protected abstract Transition CreatePseudoStateTransition(StateEntry stateEntry);
  52. #endregion
  53. }
  54. /// <summary>
  55. /// Initial state is the first state to be entered in a state machine. There should only be one initial state, and
  56. /// the state engine automatically enters that state at startup. It is a pseudo state so it must direclty transition to
  57. /// another state.
  58. ///
  59. /// The class does not introduce any new behaviour from pseudostate, but marks that it is an intial state.
  60. /// </summary>
  61. abstract public class InitialState : PseudoState
  62. {
  63. }
  64. }