Beispiel #1
0
 StateDelegate baking(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             System.Console.WriteLine("    baking: entering state");
             return null;
         case Signal.Init:
             return null;
         case Signal.Exit:
             System.Console.WriteLine("    baking: exiting state");
             return null;
     }
     return heating;
 }
Beispiel #2
0
 /**
  * Send a signal to the state machine.
  *
  * @param e The event to send to the state machine
  *
  */
 public void SignalCurrentState(StateEvent e)
 {
     if (curState != null)
     {
         StateDelegate parentState = curState;
         do
         {
             parentState = parentState(e);
         }while (parentState != null);
     }
     else
     {
         System.Console.WriteLine("SignalCurrentState: ERROR - current state is invalid!\n");
     }
 }
Beispiel #3
0
 StateDelegate doorOpen(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             System.Console.WriteLine("  doorOpen: entering state");
             return null;
         case Signal.Init:
             return null;
         case Signal.Exit:
             System.Console.WriteLine("  doorOpen: exiting state");
             return null;
         case (Signal)OvenSignal.CloseDoor:
             System.Console.WriteLine("  doorOpen: CLOSE_DOOR signal!");
             TransitionState(heating, true);
             return null;
     }
     return oven;
 }
Beispiel #4
0
 StateDelegate operand2(StateEvent e)
 {
     switch (e.Signal)
     {
         case (Signal)CalcSignal.ClearEntry:
             Zero();
             TransitionState(opEntered);
             return null;
         case (Signal)CalcSignal.Operator:
             try
             {
                 _operand1 = Calc(_operand1, Convert.ToDouble(textBox.Text), _operator);
                 _operator = ((CalcEvent)e).Key;
                 textBox.Text = _operand1.ToString();
                 TransitionState(opEntered);
             }
             catch
             {
                 textBox.Text = "ERROR";
                 TransitionState(error);
             }
             return null;
         case (Signal)CalcSignal.Equals:
             try
             {
                 _operand1 = Calc(_operand1, Convert.ToDouble(textBox.Text), _operator);
                 textBox.Text = _operand1.ToString();
                 TransitionState(result);
             }
             catch
             {
                 textBox.Text = "ERROR";
                 TransitionState(error);
             }
             return null;
     }
     return on;
 }
Beispiel #5
0
 //
 // Oven State function implementations
 //
 StateDelegate oven(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             System.Console.WriteLine("oven: entering state");
             return null;
         case Signal.Init:
             InitTransitionState(heating);
             return null;
         case Signal.Exit:
             System.Console.WriteLine("oven: exiting state");
             return null;
     }
     return null;
 }
Beispiel #6
0
 StateDelegate int1(StateEvent e)
 {
     switch (e.Signal)
     {
         case (Signal)CalcSignal.Digit0:
             Append('0');
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac1);
             return null;
     }
     return operand1;
 }
Beispiel #7
0
 StateDelegate begin(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             Zero();
             _operand1 = 0;
             return null;
         case (Signal)CalcSignal.Operator:
             if (((CalcEvent)e).Key == '-')
             {
                 TransitionState(negated1);
                 return null;
             }
             break;
     }
     return ready;
 }
Beispiel #8
0
 /**
 * Send a signal to the state machine.
 *
 * @param e The event to send to the state machine
 *
 */
 public void SignalCurrentState(StateEvent e)
 {
     if (curState != null)
     {
         StateDelegate parentState = curState;
         do
             parentState = parentState(e);
         while (parentState != null);
     }
     else
         System.Console.WriteLine("SignalCurrentState: ERROR - current state is invalid!\n");
 }
Beispiel #9
0
 StateDelegate result(StateEvent e)
 {
     return ready;
 }
Beispiel #10
0
 StateDelegate zero2(StateEvent e)
 {
     switch (e.Signal)
     {
         case (Signal)CalcSignal.Digit0:
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             TransitionState(int2);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac2);
             return null;
     }
     return operand2;
 }
Beispiel #11
0
 StateDelegate heating(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             System.Console.WriteLine("  heating: entering state");
             return null;
         case Signal.Init:
             InitTransitionState(toasting);
             return null;
         case Signal.Exit:
             System.Console.WriteLine("  heating: exiting state");
             return null;
         case (Signal)OvenSignal.OpenDoor:
             System.Console.WriteLine("  heating: OPEN_DOOR signal!");
             TransitionState(doorOpen);
             return null;
         case (Signal)OvenSignal.Toasting:
             System.Console.WriteLine("  heating: TOASTING signal!");
             TransitionState(toasting);
             return null;
         case (Signal)OvenSignal.Baking:
             System.Console.WriteLine("  heating: BAKING signal!");
             TransitionState(baking);
             return null;
     }
     return oven;
 }
Beispiel #12
0
 StateDelegate frac2(StateEvent e)
 {
     switch (e.Signal)
     {
         case (Signal)CalcSignal.Digit0:
             Append('0');
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             return null;
     }
     return operand2;
 }
Beispiel #13
0
 StateDelegate operand1(StateEvent e)
 {
     switch (e.Signal)
     {
         case (Signal)CalcSignal.ClearEntry:
             TransitionState(ready);
             return null;
         case (Signal)CalcSignal.Operator:
             _operand1 = Convert.ToDouble(textBox.Text);
             _operator = ((CalcEvent)e).Key;
             TransitionState(opEntered);
             return null;
     }
     return on;
 }
Beispiel #14
0
 StateDelegate opEntered(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             clearOnNext = true;
             negative = false;
             return null;
         case (Signal)CalcSignal.Operator:
             if (((CalcEvent)e).Key == '-')
             {
                 TransitionState(negated2);
                 return null;
             }
             break;
         case (Signal)CalcSignal.Digit0:
             Append('0');
             clearOnNext = true;
             TransitionState(zero2);
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             TransitionState(int2);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac2);
             return null;
     }
     return on;
 }
Beispiel #15
0
 //
 // Calc state functions
 //
 StateDelegate on(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Init:
             InitTransitionState(ready);
             return null;
         case (Signal)CalcSignal.Clear:
             TransitionState(on);
             return null;
     }
     return null;
 }
Beispiel #16
0
 StateDelegate negated2(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             Negate();
             return null;
         case (Signal)CalcSignal.Digit0:
             TransitionState(zero2);
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             TransitionState(int2);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac2);
             return null;
         case (Signal)CalcSignal.ClearEntry:
             Zero();
             TransitionState(opEntered);
             return null;
     }
     return on;
 }
Beispiel #17
0
 StateDelegate negated1(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             Negate();
             return null;
         case (Signal)CalcSignal.Digit0:
             TransitionState(zero1);
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             TransitionState(int1);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac1);
             return null;
         case (Signal)CalcSignal.ClearEntry:
             TransitionState(begin);
             return null;
     }
     return on;
 }
Beispiel #18
0
 StateDelegate ready(StateEvent e)
 {
     switch (e.Signal)
     {
         case Signal.Entry:
             clearOnNext = true;
             negative = false;
             return null;
         case Signal.Init:
             InitTransitionState(begin);
             return null;
         case (Signal)CalcSignal.Operator:
             _operator = ((CalcEvent)e).Key;
             TransitionState(opEntered);
             return null;
         case (Signal)CalcSignal.Digit0:
             Append('0');
             clearOnNext = true;
             TransitionState(zero1);
             return null;
         case (Signal)CalcSignal.Digit1_9:
             Append(((CalcEvent)e).Key);
             TransitionState(int1);
             return null;
         case (Signal)CalcSignal.Point:
             Append('.');
             TransitionState(frac1);
             return null;
     }
     return on;
 }
Beispiel #19
0
 StateDelegate error(StateEvent e)
 {
     return on;
 }