PageRenderTime 49ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/TuringMachine/StateAutomatModule/State.cs

#
C# | 123 lines | 65 code | 13 blank | 45 comment | 4 complexity | 4912cd7758edb84352ba313eb89a5179 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace TuringMachine.StateAutomat
  5. {
  6. public class State : IDisposable
  7. {
  8. #region Private members
  9. private String _name;
  10. private StateType _type;
  11. #endregion
  12. #region Properties
  13. public StateType Type
  14. {
  15. get { return _type; }
  16. set { _type = value; }
  17. }
  18. public String Name
  19. {
  20. get { return _name; }
  21. set { _name = value; }
  22. }
  23. #endregion
  24. #region Constructors
  25. public State()
  26. {
  27. _name = string.Empty;
  28. _type = StateType.UnknownState;
  29. }
  30. public State(String name)
  31. {
  32. _name = name;
  33. _type = StateType.UnknownState;
  34. }
  35. public State(String name, StateType type)
  36. {
  37. _name = name;
  38. _type = type;
  39. }
  40. #endregion
  41. #region Public methods
  42. public Boolean IsStart()
  43. {
  44. return (_type == StateType.StartState);
  45. }
  46. public Boolean IsHalt()
  47. {
  48. return (_type == StateType.HaltState);
  49. }
  50. public Boolean IsYes()
  51. {
  52. return _type == StateType.YesState;
  53. }
  54. public Boolean IsNo()
  55. {
  56. return _type == StateType.NoState;
  57. }
  58. /*public State GetNextState(char inputChar)
  59. {
  60. if (transactionTable.ContainsKey(inputChar))
  61. {
  62. return transactionTable[inputChar];
  63. }
  64. else
  65. {
  66. return null;
  67. }
  68. }
  69. public Char GetTapeAction(char inputChar)
  70. {
  71. if (tapeActionTable.ContainsKey(inputChar))
  72. {
  73. return tapeActionTable[inputChar];
  74. }
  75. else
  76. {
  77. return null;
  78. }
  79. }
  80. public void AddTransition(char inputChar, State nextState)
  81. {
  82. if (transactionTable.ContainsKey(inputChar))
  83. {
  84. throw new Exception("Already exist transaction from state '" + this.Name + "' with character '" + inputChar + "'");
  85. }
  86. else
  87. {
  88. transactionTable.Add(inputChar, nextState);
  89. }
  90. }
  91. public void AddTapeAction(char inputChar, char tapeAction)
  92. {
  93. if (tapeActionTable.ContainsKey(inputChar))
  94. {
  95. throw new Exception("Already exist tape action for state '" + this.Name + "' with character '" + inputChar + "'");
  96. }
  97. else
  98. {
  99. tapeActionTable.Add(inputChar, tapeAction);
  100. }
  101. } */
  102. #endregion
  103. #region IDispose method
  104. public void Dispose()
  105. {
  106. }
  107. #endregion
  108. }
  109. }