Пример #1
0
 /// <summary>
 /// Returns true if <paramref name="point"/> lies within this span
 /// </summary>
 /// <param name="point">Point</param>
 /// <returns></returns>
 public bool Contains(HexBufferPoint point)
 {
     if (point.Buffer != Buffer)
     {
         throw new ArgumentException();
     }
     return(Span.Contains(point));
 }
Пример #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="position">Position</param>
 /// <param name="data">Data</param>
 public PositionAndData(HexBufferPoint position, byte[] data)
 {
     if (position.IsDefault)
     {
         throw new ArgumentException();
     }
     Position = position;
     Data     = data ?? throw new ArgumentNullException(nameof(data));
 }
Пример #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="start">Start point</param>
 /// <param name="length">Length</param>
 public HexBufferSpan(HexBufferPoint start, ulong length)
 {
     if (start.Buffer == null)
     {
         throw new ArgumentException();
     }
     Buffer = start.Buffer;
     Span   = new HexSpan(start, length);
 }
Пример #4
0
        /// <summary>
        /// Gets the cell that contains <paramref name="point"/>
        /// </summary>
        /// <param name="point">Point</param>
        /// <returns></returns>
        public HexCell GetCell(HexBufferPoint point)
        {
            int index = GetStartIndex(point);

            if (validStart <= index && index < validEnd)
            {
                return(cells[index]);
            }
            return(null);
        }
Пример #5
0
 /// <summary>
 /// Returns true if <paramref name="position"/> is a valid position that can be passed to
 /// methods expecting a (physical) position.
 /// </summary>
 /// <param name="position">Position</param>
 /// <returns></returns>
 public bool IsValidPosition(HexBufferPoint position)
 {
     if (position.Buffer != Buffer)
     {
         return(false);
     }
     // Allow the last position since it's so easy to accidentally pass in the end position.
     // The text editor API also allows this so to make everything easier, also allow it here,
     // but treat it as Max(StartPosition, EndPosition - 1) (treating them as signed integers)
     return(BufferStart <= position && position <= BufferEnd);
 }
Пример #6
0
 /// <summary>
 /// Filters the position so it's less than <see cref="EndPosition"/> if it equals <see cref="EndPosition"/>.
 /// It will throw if <see cref="IsValidPosition(HexBufferPoint)"/> returns false.
 /// </summary>
 /// <param name="position">Position</param>
 /// <returns></returns>
 public HexBufferPoint FilterAndVerify(HexBufferPoint position)
 {
     if (!IsValidPosition(position))
     {
         throw new ArgumentOutOfRangeException(nameof(position));
     }
     if (position != BufferEnd)
     {
         return(position);
     }
     return(BufferStart == BufferEnd ? position : position - 1);
 }
Пример #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="start">Start position</param>
 /// <param name="end">End position</param>
 public HexBufferSpan(HexBufferPoint start, HexBufferPoint end)
 {
     if (start.Buffer != end.Buffer || start.Buffer == null)
     {
         throw new ArgumentException();
     }
     if (end.Position < start.Position)
     {
         throw new ArgumentOutOfRangeException(nameof(end));
     }
     Buffer = start.Buffer;
     Span   = HexSpan.FromBounds(start, end);
 }
Пример #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="column">Column</param>
 /// <param name="bufferPosition">Buffer position</param>
 /// <param name="cellPosition">Position within the cell</param>
 public HexCellPosition(HexColumnType column, HexBufferPoint bufferPosition, int cellPosition)
 {
     if (column != HexColumnType.Values && column != HexColumnType.Ascii)
     {
         throw new ArgumentOutOfRangeException(nameof(column));
     }
     if (bufferPosition.IsDefault)
     {
         throw new ArgumentException();
     }
     if (cellPosition < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(cellPosition));
     }
     Column         = column;
     BufferPosition = bufferPosition;
     CellPosition   = cellPosition;
 }
Пример #9
0
        int GetStartIndex(HexBufferPoint position)
        {
            var cellsLocal = cells;
            int lo = validStart, hi = validEnd;

            if (lo >= hi)
            {
                return(-1);
            }
            var cellFirst = cellsLocal[lo];
            var cellLast  = cellsLocal[hi - 1];

            if (position < cellFirst.BufferStart || position >= cellLast.BufferEnd)
            {
                return(-1);
            }
            return(lo + (int)((position - cellFirst.BufferStart).ToUInt64() / cellFirst.BufferSpan.Length.ToUInt64()));
        }
Пример #10
0
 /// <summary>
 /// Creates a new <see cref="HexBufferSpan"/> instance
 /// </summary>
 /// <param name="start">Start point</param>
 /// <param name="end">End point</param>
 public static HexBufferSpan FromBounds(HexBufferPoint start, HexBufferPoint end) => new HexBufferSpan(start, end);
Пример #11
0
 /// <summary>
 /// Gets the line number
 /// </summary>
 /// <param name="position">Position</param>
 /// <returns></returns>
 public abstract HexPosition GetLineNumberFromPosition(HexBufferPoint position);
Пример #12
0
 /// <summary>
 /// Creates a line
 /// </summary>
 /// <param name="position">Position</param>
 /// <returns></returns>
 public abstract HexBufferLine GetLineFromPosition(HexBufferPoint position);