/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
using VST = Microsoft.VisualStudio.Text;
namespace dnSpy.Contracts.Hex {
///
/// Cell information
///
public sealed class HexCell {
///
/// true if there's data in the cell even if there's no memory there; false if it's a blank cell
///
public bool HasData { get; }
///
/// Index in
///
public int Index { get; }
///
/// Group index
///
public int GroupIndex { get; }
///
/// Gets the buffer span. It's valid if is true
///
public HexBufferSpan BufferSpan { get; }
///
/// Gets the start position. It's valid if is true
///
public HexBufferPoint BufferStart => BufferSpan.Start;
///
/// Gets the end position. It's valid if is true
///
public HexBufferPoint BufferEnd => BufferSpan.End;
///
/// Span of the text
///
public VST.Span TextSpan { get; }
///
/// Span of the cell, some of the span could be whitespace
///
public VST.Span CellSpan { get; }
///
/// Span of the cell separator
///
public VST.Span SeparatorSpan { get; }
///
/// Includes the whole cell and separator span
///
public VST.Span FullSpan { get; }
///
/// Constructor
///
/// Cell index
/// Group index
/// Buffer span or the default value if there's no data
/// Span of the text. This span doesn't include any whitespace before and after the text.
/// Span of the cell, some of the span could be whitespace
/// Span of the cell separator
/// Includes the whole cell and separator span
public HexCell(int index, int groupIndex, HexBufferSpan bufferSpan, VST.Span textSpan, VST.Span cellSpan, VST.Span separatorSpan, VST.Span fullSpan) {
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
if (groupIndex < 0 || groupIndex > 1)
throw new ArgumentOutOfRangeException(nameof(groupIndex));
if (cellSpan.Length == 0)
throw new ArgumentOutOfRangeException(nameof(cellSpan));
if (!fullSpan.Contains(cellSpan))
throw new ArgumentOutOfRangeException(nameof(cellSpan));
HasData = !bufferSpan.IsDefault;
Index = index;
GroupIndex = groupIndex;
BufferSpan = bufferSpan;
TextSpan = textSpan;
CellSpan = cellSpan;
SeparatorSpan = separatorSpan;
FullSpan = fullSpan;
}
///
/// Gets a text span
///
/// Flags, only and
/// are checked
///
public VST.Span GetSpan(HexSpanSelectionFlags flags) {
if ((flags & HexSpanSelectionFlags.Cell) == 0) {
if ((flags & HexSpanSelectionFlags.Separator) != 0)
throw new ArgumentOutOfRangeException(nameof(flags));
return TextSpan;
}
if ((flags & HexSpanSelectionFlags.Separator) != 0)
return FullSpan;
return CellSpan;
}
}
}