Example #1
0
        internal State <TState, TEvent> ToState(TState state, ListSlot <Transition <TState, TEvent> > transitions, Dictionary <TState, int> statesMap)
        {
            Dictionary <TEvent, int> trans = new Dictionary <TEvent, int>();

            // TODO: Use deconstruction pattern when upload to .Net Standard 2.1
            foreach (KeyValuePair <TEvent, TransitionBuilder <TState, TEvent, TParameter> > kv in this.transitions)
            {
                int slot = transitions.Reserve();
                trans.Add(kv.Key, slot);
                if (kv.Value is null)
                {
                    transitions.Store(new Transition <TState, TEvent>(-1, null, (0, 0)), slot);
                }
                else
                {
                    transitions.Store(kv.Value.ToTransition(transitions, statesMap, State), slot);
                }
            }

            return(new State <TState, TEvent>(
                       state,
                       Helper.Combine(ref onEntry, ref onEntryWithParameter),
                       Helper.Combine(ref onExit, ref onExitWithParameter),
                       Helper.Combine(ref onUpdate, ref onUpdateWithParameter),
                       trans
                       ));
        }
Example #2
0
        internal override Transition <TState, TEvent> ToTransition(ListSlot <Transition <TState, TEvent> > transitions, Dictionary <TState, int> statesMap, TState currentState)
        {
            if (slaves == null)
            {
                return(new Transition <TState, TEvent>(GetGoto(statesMap, currentState), GetDo(), (0, 0), guard));
            }
            (int from, int to)range = transitions.Reserve(slaves.Count);

            int i = range.from;

            foreach (SlaveTransitionBuilder <TState, TEvent, TParameter, SlaveTransitionBuilder <TState, TEvent, TParameter, TParent> > slave in slaves)
            {
                transitions.Store(slave.ToTransition(transitions, statesMap, currentState), i);
                i++;
            }
            Debug.Assert(i == range.to);

            return(new Transition <TState, TEvent>(GetGoto(statesMap, currentState), GetDo(), range, guard));
        }