예제 #1
0
 internal InternalStateMachine(StateMachineFactory <Operand, State, Eventtype, Event
                                                    > _enclosing, OPERAND operand, STATE initialState)
 {
     this._enclosing   = _enclosing;
     this.operand      = operand;
     this.currentState = initialState;
     if (!this._enclosing.optimized)
     {
         this._enclosing.MaybeMakeStateMachineTable();
     }
 }
예제 #2
0
            public virtual void Apply(StateMachineFactory <OPERAND, STATE, EVENTTYPE, EVENT> subject
                                      )
            {
                IDictionary <EVENTTYPE, StateMachineFactory.Transition <OPERAND, STATE, EVENTTYPE,
                                                                        EVENT> > transitionMap = subject.stateMachineTable[preState];

                if (transitionMap == null)
                {
                    // I use HashMap here because I would expect most EVENTTYPE's to not
                    //  apply out of a particular state, so FSM sizes would be
                    //  quadratic if I use EnumMap's here as I do at the top level.
                    transitionMap = new Dictionary <EVENTTYPE, StateMachineFactory.Transition <OPERAND,
                                                                                               STATE, EVENTTYPE, EVENT> >();
                    subject.stateMachineTable[preState] = transitionMap;
                }
                transitionMap[eventType] = transition;
            }
예제 #3
0
        /// <returns>
        /// a NEW StateMachineFactory just like
        /// <c>this</c>
        /// with the current
        /// transition added as a new legal transition
        /// Note that the returned StateMachineFactory is a distinct
        /// object.
        /// This method is part of the API.
        /// </returns>
        /// <param name="preState">pre-transition state</param>
        /// <param name="postState">post-transition state</param>
        /// <param name="eventTypes">List of stimuli for the transitions</param>
        /// <param name="hook">transition hook</param>
        public StateMachineFactory <OPERAND, STATE, EVENTTYPE, EVENT> AddTransition(STATE
                                                                                    preState, STATE postState, ICollection <EVENTTYPE> eventTypes, SingleArcTransition
                                                                                    <OPERAND, EVENT> hook)
        {
            StateMachineFactory <OPERAND, STATE, EVENTTYPE, EVENT> factory = null;

            foreach (EVENTTYPE @event in eventTypes)
            {
                if (factory == null)
                {
                    factory = AddTransition(preState, postState, @event, hook);
                }
                else
                {
                    factory = factory.AddTransition(preState, postState, @event, hook);
                }
            }
            return(factory);
        }