PageRenderTime 75ms CodeModel.GetById 33ms app.highlight 2ms RepoModel.GetById 39ms app.codeStats 0ms

/TuringMachine/StateAutomatModule/State.cs

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