/*
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;
namespace dnSpy.Contracts.Hex {
///
/// Options passed to
///
public sealed class HexBufferLineFormatterOptions : IEquatable {
///
/// Number of visible characters per line
///
public int CharsPerLine { get; set; }
///
/// Number of bytes per line or 0 to fit to width
///
public int BytesPerLine { get; set; }
///
/// Size of a group in bytes or 0 to use the default value
///
public int GroupSizeInBytes { get; set; }
///
/// true to show the offset
///
public bool ShowOffset { get; set; }
///
/// true to use lower case hex
///
public bool OffsetLowerCaseHex { get; set; }
///
/// Offset format
///
public HexOffsetFormat OffsetFormat { get; set; }
///
/// First position to show
///
public HexPosition StartPosition { get; set; }
///
/// End position
///
public HexPosition EndPosition { get; set; }
///
/// Base position. The real position is added to this value which is then
/// shown in the offset column.
///
public HexPosition BasePosition { get; set; }
///
/// true if all visible positions are relative to
///
public bool UseRelativePositions { get; set; }
///
/// true to show the values
///
public bool ShowValues { get; set; }
///
/// true to use lower case hex
///
public bool ValuesLowerCaseHex { get; set; }
///
/// Number of bits of the offset to show. Must be a multiple of 4. If it's 0, the default
/// value is used.
///
public int OffsetBitSize { get; set; }
///
/// Values format
///
public HexValuesDisplayFormat ValuesFormat { get; set; }
///
/// true to show ASCII chars
///
public bool ShowAscii { get; set; }
///
/// Column order or null to use the default order
///
public HexColumnType[]? ColumnOrder { get; set; }
///
/// Minimum value
///
public static readonly int MinOffsetBitSize = 0;
///
/// Maximum value
///
public static readonly int MaxOffsetBitSize = 64;
///
/// Min bytes per line
///
public static readonly int MinBytesPerLine = 0;
///
/// Max bytes per line
///
public static readonly int MaxBytesPerLine = 1024;
///
/// First valid value
///
public const HexValuesDisplayFormat HexValuesDisplayFormat_First = HexValuesDisplayFormat.HexByte;
///
/// Last valid value
///
public const HexValuesDisplayFormat HexValuesDisplayFormat_Last = HexValuesDisplayFormat.DoubleBigEndian;
///
/// First valid value
///
public const HexOffsetFormat HexOffsetFormat_First = HexOffsetFormat.Hex;
///
/// Last valid value
///
public const HexOffsetFormat HexOffsetFormat_Last = HexOffsetFormat.HexAssembly;
///
/// Equals()
///
/// Other instance
///
public bool Equals(HexBufferLineFormatterOptions? other) =>
other is not null &&
CharsPerLine == other.CharsPerLine &&
BytesPerLine == other.BytesPerLine &&
GroupSizeInBytes == other.GroupSizeInBytes &&
ShowOffset == other.ShowOffset &&
OffsetLowerCaseHex == other.OffsetLowerCaseHex &&
OffsetFormat == other.OffsetFormat &&
StartPosition == other.StartPosition &&
EndPosition == other.EndPosition &&
BasePosition == other.BasePosition &&
UseRelativePositions == other.UseRelativePositions &&
ShowValues == other.ShowValues &&
ValuesLowerCaseHex == other.ValuesLowerCaseHex &&
OffsetBitSize == other.OffsetBitSize &&
ValuesFormat == other.ValuesFormat &&
ShowAscii == other.ShowAscii &&
HexColumnTypeArraysEquals(ColumnOrder, other.ColumnOrder);
static bool HexColumnTypeArraysEquals(HexColumnType[]? a, HexColumnType[]? b) {
if (a == b)
return true;
if (a is null || b is null)
return false;
if (a.Length != b.Length)
return false;
for (int i = 0; i < a.Length; i++) {
if (a[i] != b[i])
return false;
}
return true;
}
///
/// Equals()
///
/// Other object
///
public override bool Equals(object? obj) => obj is HexBufferLineFormatterOptions && Equals((HexBufferLineFormatterOptions)obj);
///
/// GetHashCode()
///
///
public override int GetHashCode() =>
CharsPerLine.GetHashCode() ^
BytesPerLine.GetHashCode() ^
GroupSizeInBytes.GetHashCode() ^
ShowOffset.GetHashCode() ^
OffsetLowerCaseHex.GetHashCode() ^
(int)OffsetFormat ^
StartPosition.GetHashCode() ^
EndPosition.GetHashCode() ^
BasePosition.GetHashCode() ^
UseRelativePositions.GetHashCode() ^
ShowValues.GetHashCode() ^
ValuesLowerCaseHex.GetHashCode() ^
OffsetBitSize.GetHashCode() ^
(int)ValuesFormat ^
ShowAscii.GetHashCode() ^
GetHexColumnTypeArrayHashCode(ColumnOrder);
int GetHexColumnTypeArrayHashCode(HexColumnType[]? a) {
if (a is null)
return 0;
int hc = 0;
foreach (var t in a)
hc ^= (int)t;
return hc;
}
}
}