/*
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 {
///
/// A position in a hex column
///
public readonly struct HexColumnPosition : IEquatable {
///
/// true if this is a default instance that hasn't been initialized
///
public bool IsDefault => ValuePosition.IsDefault;
///
/// Active column
///
public HexColumnType ActiveColumn { get; }
///
/// Position in the values column
///
public HexCellPosition ValuePosition { get; }
///
/// Position in the ASCII column
///
public HexCellPosition AsciiPosition { get; }
///
/// Gets the active position ( or )
///
public HexCellPosition ActivePosition {
get {
switch (ActiveColumn) {
case HexColumnType.Values: return ValuePosition;
case HexColumnType.Ascii: return AsciiPosition;
case HexColumnType.Offset:
default:
throw new InvalidOperationException();
}
}
}
///
/// Constructor
///
/// Active column
/// Position in the values column
/// Position in the ASCII column
public HexColumnPosition(HexColumnType activeColumn, HexCellPosition valuePosition, HexCellPosition asciiPosition) {
if (activeColumn != HexColumnType.Values && activeColumn != HexColumnType.Ascii)
throw new ArgumentOutOfRangeException(nameof(activeColumn));
if (valuePosition.IsDefault || valuePosition.Column != HexColumnType.Values)
throw new ArgumentException();
if (asciiPosition.IsDefault || asciiPosition.Column != HexColumnType.Ascii)
throw new ArgumentException();
ActiveColumn = activeColumn;
ValuePosition = valuePosition;
AsciiPosition = asciiPosition;
}
///
/// operator ==()
///
///
///
///
public static bool operator ==(HexColumnPosition a, HexColumnPosition b) => a.Equals(b);
///
/// operator !=()
///
///
///
///
public static bool operator !=(HexColumnPosition a, HexColumnPosition b) => !a.Equals(b);
///
/// Equals()
///
/// Other instance
///
public bool Equals(HexColumnPosition other) => ActiveColumn == other.ActiveColumn && ValuePosition.Equals(other.ValuePosition) && AsciiPosition.Equals(other.AsciiPosition);
///
/// Equals()
///
/// Object
///
public override bool Equals(object? obj) => obj is HexColumnPosition && Equals((HexColumnPosition)obj);
///
/// GetHashCode()
///
///
public override int GetHashCode() => (int)ActiveColumn ^ ValuePosition.GetHashCode() ^ AsciiPosition.GetHashCode();
///
/// ToString()
///
///
public override string ToString() => "[" + ActiveColumn.ToString() + ",V=" + ValuePosition.ToString() + ",A=" + AsciiPosition.ToString() + "]";
}
}