/// <summary>
 /// Constructs the range given a start and an end location
 /// </summary>
 /// <param name="startOffset">The offset of the first value of the range.</param>
 /// <param name="firstValue">The first value of the range</param>
 /// <param name="lastOffset">The offset within the range of the last value.</param>
 /// <param name="endValue">The last value of the range.</param>
 public IndexRange(RangeFieldOffset startOffset, Field firstValue, RangeFieldOffset lastOffset, Field endValue)
     : this(false) {
     StartOffset = startOffset;
     StartValue  = firstValue;
     EndOffset   = lastOffset;
     EndValue    = endValue;
 }
Beispiel #2
0
 /// <summary>
 /// Constructs the range given a start and an end location
 /// </summary>
 /// <param name="startOffset">The offset of the first value of the range.</param>
 /// <param name="firstValue">The first value of the range</param>
 /// <param name="lastOffset">The offset within the range of the last value.</param>
 /// <param name="endValue">The last value of the range.</param>
 public IndexRange(RangeFieldOffset startOffset, DataObject firstValue, RangeFieldOffset lastOffset, DataObject endValue)
     : this(false)
 {
     StartOffset = startOffset;
     StartValue = firstValue;
     EndOffset = lastOffset;
     EndValue = endValue;
 }
        private int PositionOfRangePoint(RangeFieldOffset position, DataObject val)
        {
            int        p;
            DataObject cell;

            switch (position)
            {
            case RangeFieldOffset.FirstValue:
                if (val.Equals(IndexRange.FirstInSet))
                {
                    return(0);
                }
                if (val.Equals(IndexRange.LastInSet))
                {
                    // Get the last value and search for the first instance of it.
                    cell = Last;
                }
                else
                {
                    cell = val;
                }

                p = SearchFirst(cell);

                // (If value not found)
                if (p < 0)
                {
                    return(-(p + 1));
                }

                return(p);

            case RangeFieldOffset.LastValue:
                if (val.Equals(IndexRange.LastInSet))
                {
                    return(Count - 1);
                }

                if (val.Equals(IndexRange.FirstInSet))
                {
                    // Get the first value.
                    cell = First;
                }
                else
                {
                    cell = val;
                }

                p = SearchLast(cell);

                // (If value not found)
                if (p < 0)
                {
                    return(-(p + 1) - 1);
                }
                return(p);

            case RangeFieldOffset.BeforeFirstValue:
                if (val.Equals(IndexRange.FirstInSet))
                {
                    return(-1);
                }

                if (val.Equals(IndexRange.LastInSet))
                {
                    // Get the last value and search for the first instance of it.
                    cell = Last;
                }
                else
                {
                    cell = val;
                }

                p = SearchFirst(cell);
                // (If value not found)
                if (p < 0)
                {
                    return(-(p + 1) - 1);
                }
                return(p - 1);

            case RangeFieldOffset.AfterLastValue:
                if (val.Equals(IndexRange.LastInSet))
                {
                    return(Count);
                }
                if (val.Equals(IndexRange.FirstInSet))
                {
                    // Get the first value.
                    cell = First;
                }
                else
                {
                    cell = val;
                }
                p = SearchLast(cell);
                // (If value not found)
                if (p < 0)
                {
                    return(-(p + 1));
                }
                return(p + 1);

            default:
                throw new InvalidOperationException("Unrecognised position.");
            }
        }
        private int PositionOfRangePoint(RangeFieldOffset position, DataObject val)
        {
            int p;
            DataObject cell;

            switch (position) {

                case RangeFieldOffset.FirstValue:
                    if (val.Equals(IndexRange.FirstInSet)) {
                        return 0;
                    }
                    if (val.Equals(IndexRange.LastInSet)) {
                        // Get the last value and search for the first instance of it.
                        cell = Last;
                    } else {
                        cell = val;
                    }

                    p = SearchFirst(cell);

                    // (If value not found)
                    if (p < 0)
                        return -(p + 1);

                    return p;

                case RangeFieldOffset.LastValue:
                    if (val.Equals(IndexRange.LastInSet))
                        return Count - 1;

                    if (val.Equals(IndexRange.FirstInSet)) {
                        // Get the first value.
                        cell = First;
                    } else {
                        cell = val;
                    }

                    p = SearchLast(cell);

                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1) - 1;
                    }
                    return p;

                case RangeFieldOffset.BeforeFirstValue:
                    if (val.Equals(IndexRange.FirstInSet))
                        return -1;

                    if (val.Equals(IndexRange.LastInSet)) {
                        // Get the last value and search for the first instance of it.
                        cell = Last;
                    } else {
                        cell = val;
                    }

                    p = SearchFirst(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1) - 1;
                    }
                    return p - 1;

                case RangeFieldOffset.AfterLastValue:
                    if (val.Equals(IndexRange.LastInSet)) {
                        return Count;
                    }
                    if (val.Equals(IndexRange.FirstInSet)) {
                        // Get the first value.
                        cell = First;
                    } else {
                        cell = val;
                    }
                    p = SearchLast(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1);
                    }
                    return p + 1;

                default:
                    throw new InvalidOperationException("Unrecognised position.");
            }
        }