//---------------------------------------------------------------------

		public bool MoveNext()
		{
			if (atEnd)
				return false;

			if (moveNextNotCalled) {
				InitializeCurrentSite();
				moveNextNotCalled = false;
				return true;
			}

			Location nextLocation = RowMajor.Next(currentSite.Location, landscape.Columns);
			if (nextLocation.Row > landscape.Rows) {
				atEnd = true;
				return false;
			}

			if (currentSite.IsActive) {
				//	current site is the active site etor's Current property
				//  so advance etor to next active site.
				if (activeSiteEtor.MoveNext()) {
					//	There is one or more active sites remaining.
					nextActiveSite = activeSiteEtor.Current;
					if (nextLocation == nextActiveSite.Location) {
						//	Leave current site pointing to active site etor
					}
					else {
						//	Next site is inactive.
						currentSite = inactiveSite;
						inactiveSite.SetLocation(nextLocation);
					}
				}
				else {
					//	No more active sites left to visit, so next site is
					//	inactive.
					nextActiveSite = null;
					currentSite = inactiveSite;
					inactiveSite.SetLocation(nextLocation);
				}
			}
			else {
				//	Current site is inactive
				if (nextActiveSite != null && nextLocation == nextActiveSite.Location)
					currentSite = nextActiveSite;
				else {
					//	Leave current site pointing to the local inactive site
					//	instance, and just change its location.
					inactiveSite.SetLocation(nextLocation);
				}
			}
			return true;
		}
        //---------------------------------------------------------------------

        public T ReadValue()
        {
            if (disposed)
            {
                throw new System.InvalidOperationException("Object has been disposed.");
            }
            currentLocation = RowMajor.Next(currentLocation, Columns);
            if (currentLocation.Row > Rows)
            {
                throw new System.IO.EndOfStreamException();
            }
            return(data[currentLocation]);
        }
Exemple #3
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Gets the next active site in row-major order.
        /// </summary>
        /// <param name="site">
        /// Current site's location and data index.
        /// </param>
        /// <returns>
        /// true if the next active site's location and data index have been
        /// assigned to the site parameter.  false if there are no more active
        /// sites.
        /// </returns>
        public bool GetNextActive(ref LocationAndIndex site)
        {
            Location nextLoc = RowMajor.Next(site.Location, columns);

            while (nextLoc.Row <= rows)
            {
                uint index = indexes[nextLoc.Row - 1, nextLoc.Column - 1];
                if (index != InactiveSiteDataIndex)
                {
                    site.Location = nextLoc;
                    site.Index    = index;
                    return(true);
                }
                nextLoc = RowMajor.Next(nextLoc, columns);
            }
            return(false);
        }