Exemple #1
0
 public void IncIterationCount()
 {
     IterationCount++;
     if (DataIterator != null)
     {
         DataIterator.FetchNextRowData(); // TODO : Replace this with another method?!
     }
 }
Exemple #2
0
 /// <summary>
 /// Removes all the data from the machine
 /// </summary>
 public void ClearData()
 {
     // get a new track root (not just unlinking a previous track because we might have used move/join semantics on it)
     Pos = new DataIterator()
     {
         Track = new Track(), Pos = 0
     };
     Pos.Track.Clear();
 }
Exemple #3
0
        public bool HasMoreData()
        {
            bool result = (IterationCount < MaxExecutions);

            if (ExeType == enForEachExecutionType.GhostService)
            {
                if (DataIterator != null && result)
                {
                    // check that there is still data to iterate across ;)
                    result = DataIterator.HasMoreRecords();
                }
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Applies a single rule to the machine. Returns true if a rule was successfully executed (failure implies end of execution)
        /// </summary>
        public bool Tick()
        {
            // get the rule to execute
            if (!Rules.TryGetValue(new Tuple <int, int>(State, Pos.Value), out var rule))
            {
                return(false);
            }

            // apply the rule
            Pos.Value = rule.Item1;
            State     = rule.Item2;
            Pos      += rule.Item3;

            return(true);
        }
Exemple #5
0
            public static DataIterator operator +(DataIterator iter, int offset)
            {
                // create new iterator
                DataIterator res = new DataIterator()
                {
                    Track = iter.Track, Pos = iter.Pos + offset
                };

                // do any collapsing we can
                while (res.Pos < 0 && res.Track.Prev != null)
                {
                    res.Track = res.Track.Prev;
                    res.Pos  += res.Track.Data.Length;
                }
                while (res.Pos >= res.Track.Data.Length && res.Track.Next != null)
                {
                    res.Pos  -= res.Track.Data.Length;
                    res.Track = res.Track.Next;
                }

                // return new iterator
                return(res);
            }
Exemple #6
0
        /// <summary>
        /// Attempts to load the turing object with a data file and sets the initial state of 0. Returns true on success.
        /// Upon failure, no action is taken (i.e. previous data and state are intact).
        /// </summary>
        /// <param name="path">path of file to load</param>
        public bool LoadData(string path)
        {
            StreamReader f = null;
            string       line;

            // get a new track
            Track root = new Track();

            Track current = root; // working track
            int   pos     = 0;    // position in working track

            try
            {
                // open the file
                f = new StreamReader(path);

                // read all the rule data
                while (true)
                {
                    // get a line
                    line = f.ReadLine();
                    // returns null on eof
                    if (line == null)
                    {
                        break;
                    }
                    // empty lines are ok
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    // if we're out of track range
                    if (pos == current.Data.Length)
                    {
                        // link in a new track
                        Track t = new Track()
                        {
                            Prev = current
                        };
                        current = current.Next = t;
                        pos     = 0;
                    }

                    // place the value
                    current.Data[pos++] = int.Parse(line);
                }

                // zero the rest of the current track
                for (; pos < current.Data.Length; ++pos)
                {
                    current.Data[pos] = ZeroValue;
                }

                // replace old data
                Pos = new DataIterator()
                {
                    Track = root, Pos = 0
                };
                // set initial state
                State = 0;

                // successful parse
                return(true);
            }
            // any errors will be reported as a simple failure
            catch (Exception) { return(false); }
            // make sure file is properly disposed
            finally { f?.Dispose(); }
        }