using System.Collections.Generic;
namespace BizHawk.Client.Common
{
///
/// This class hold a collection
/// Different memory domain can be mixed
///
public sealed partial class WatchList
{
///
/// Nested private class that define how to compare two
/// based on their values
///
private sealed class WatchValueComparer
: WatchEqualityComparer,
IComparer
{
///
/// Compares two between them
/// and determines which one comes first.
/// If they are equals, comparison will done one the address and next on size
///
/// First
/// Second
/// 0 for equality, 1 if x comes first; -1 if y comes first
public int Compare(Watch x, Watch y)
{
int xValue;
int yValue;
if (x.Type == DisplayType.Signed)
{
int.TryParse(x.ValueString, out xValue);
}
else
{
xValue = x.Value;
}
if (y.Type == DisplayType.Signed)
{
int.TryParse(y.ValueString, out yValue);
}
else
{
yValue = y.Value;
}
if (Equals(x, y))
{
return 0;
}
else if (xValue.Equals(yValue))
{
if (x.Address.Equals(y.Address))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Address.CompareTo(y.Address);
}
}
else
{
return xValue.CompareTo(yValue);
}
}
}
}
}