예제 #1
0
 public Transition(State srcState, State targetState, Condition condition,
     bool returnCharAfterTransition = false)
 {
     m_sourceState = srcState;
     m_targetState = targetState;
     m_returnCharAfterTransition = returnCharAfterTransition;
     m_condition = condition;
 }
예제 #2
0
 private void resetState()
 {
     m_curState = m_initState;
     m_context.Reset();
 }
예제 #3
0
        private bool onChar(char ch)
        {
            bool bTransit = false;

            for (int i = 0; i < m_curState.Transitions.Count; i++)
            {
                Transition t = m_curState.Transitions[i];
                if (t.CanTransitOnChar(this.m_context, ch))
                {
                    if (m_curState == t.TargetState)
                    {
                        m_context.StateToken.Append(ch);

                        // run actions of transition
                        if (t.TransitionAction != null) t.TransitionAction(m_context, ch);
                    }
                    else
                    {
                        // transit state
                        m_curState = t.TargetState;

                        // run actions of transition
                        if (t.TransitionAction != null) t.TransitionAction(m_context, ch);

                        if (t.ReturnCharAfterTransition) m_context.ReturnChar();

                        // clear token after state transition
                        m_context.StateToken.Clear();
                    }

                    bTransit = true;
                    break;
                }
            }
            return bTransit;
        }
예제 #4
0
 protected State createState(string name, bool initState = false)
 {
     State state = new State(name, m_context);
     if (initState) m_initState = state;
     return state;
 }
예제 #5
0
 public StateTransitionHelper(State source, State target, StateContext context)
 {
     m_source = source;
     m_target = target;
     m_context = context;
 }
예제 #6
0
 public StateTransitionHelper To(State target)
 {
     return new StateTransitionHelper(this, target, m_context);
 }