Final stuff to WatchList

Now fully use comparer class. That saves memory and offer extensibility
ItemCount property obsolete => Moved to Count property (which did the same thing)
Moved ConfigPersistAttribute.cs, IToolForm.cs, IToolFormAutoConfig.cs back to common
This commit is contained in:
Hathor86 2015-12-04 14:10:04 +01:00
parent 8a6ddfbf3f
commit 708bb4fa93
18 changed files with 451 additions and 235 deletions

View File

@ -59,10 +59,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Attributes\ConfigPersistAttribute.cs" />
<Compile Include="Interfaces\IToolFormAutoConfig.cs" />
<Compile Include="Interfaces\IExternalToolForm.cs" /> <Compile Include="Interfaces\IExternalToolForm.cs" />
<Compile Include="Interfaces\IToolForm.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -80,6 +77,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Attributes\" />
<Folder Include="Classes\" /> <Folder Include="Classes\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,12 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature"> <ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature">
<Class Name="BizHawk.Client.EmuHawk.ConfigPersistAttribute">
<Position X="11.5" Y="0.75" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Attributes\ConfigPersistAttribute.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="BizHawk.Client.Common.Watch"> <Class Name="BizHawk.Client.Common.Watch">
<Position X="17" Y="0.75" Width="8.75" /> <Position X="17" Y="0.75" Width="8.75" />
<Compartments> <Compartments>
@ -36,14 +29,13 @@
<Compartments> <Compartments>
<Compartment Name="Nested Types" Collapsed="false" /> <Compartment Name="Nested Types" Collapsed="false" />
</Compartments> </Compartments>
<NestedTypes>
<Enum Name="BizHawk.Client.Common.WatchList.WatchPrevDef">
<TypeIdentifier />
</Enum>
</NestedTypes>
<TypeIdentifier /> <TypeIdentifier />
<Lollipop Orientation="Right" Position="0.1" /> <Lollipop Orientation="Right" Position="0.1" />
</Class> </Class>
<Class Name="BizHawk.Client.EmuHawk.ConfigPersistAttribute">
<Position X="11.5" Y="0.75" Width="2" />
<TypeIdentifier />
</Class>
<Interface Name="BizHawk.Client.EmuHawk.IExternalToolForm"> <Interface Name="BizHawk.Client.EmuHawk.IExternalToolForm">
<Position X="4.5" Y="4.5" Width="2.75" /> <Position X="4.5" Y="4.5" Width="2.75" />
<TypeIdentifier> <TypeIdentifier>
@ -53,17 +45,11 @@
</Interface> </Interface>
<Interface Name="BizHawk.Client.EmuHawk.IToolForm"> <Interface Name="BizHawk.Client.EmuHawk.IToolForm">
<Position X="6" Y="0.75" Width="2.25" /> <Position X="6" Y="0.75" Width="2.25" />
<TypeIdentifier> <TypeIdentifier />
<HashCode>ECAAAAAAAABACAAgAAEAABAAAAAEAAAAAAAAAACAQAA=</HashCode>
<FileName>Interfaces\IToolForm.cs</FileName>
</TypeIdentifier>
</Interface> </Interface>
<Interface Name="BizHawk.Client.EmuHawk.IToolFormAutoConfig"> <Interface Name="BizHawk.Client.EmuHawk.IToolFormAutoConfig">
<Position X="8" Y="4.5" Width="1.75" /> <Position X="8" Y="4.5" Width="1.75" />
<TypeIdentifier> <TypeIdentifier />
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Interfaces\IToolFormAutoConfig.cs</FileName>
</TypeIdentifier>
</Interface> </Interface>
<Enum Name="BizHawk.Client.Common.WatchSize"> <Enum Name="BizHawk.Client.Common.WatchSize">
<Position X="26.5" Y="3.75" Width="1.5" /> <Position X="26.5" Y="3.75" Width="1.5" />

View File

@ -105,6 +105,7 @@
<Compile Include="BitmapBufferVideoProvider.cs" /> <Compile Include="BitmapBufferVideoProvider.cs" />
<Compile Include="config\Binding.cs" /> <Compile Include="config\Binding.cs" />
<Compile Include="config\Config.cs" /> <Compile Include="config\Config.cs" />
<Compile Include="config\ConfigPersistAttribute.cs" />
<Compile Include="config\ConfigService.cs" /> <Compile Include="config\ConfigService.cs" />
<Compile Include="config\PathEntry.cs" /> <Compile Include="config\PathEntry.cs" />
<Compile Include="config\ToolDialogSettings.cs" /> <Compile Include="config\ToolDialogSettings.cs" />
@ -232,6 +233,8 @@
<Compile Include="SystemInfo.cs" /> <Compile Include="SystemInfo.cs" />
<Compile Include="tools\Cheat.cs" /> <Compile Include="tools\Cheat.cs" />
<Compile Include="tools\CheatList.cs" /> <Compile Include="tools\CheatList.cs" />
<Compile Include="tools\Interfaces\IToolForm.cs" />
<Compile Include="tools\Interfaces\IToolFormAutoConfig.cs" />
<Compile Include="tools\Watch\ByteWatch.cs" /> <Compile Include="tools\Watch\ByteWatch.cs" />
<Compile Include="tools\Watch\DisplayType.cs" /> <Compile Include="tools\Watch\DisplayType.cs" />
<Compile Include="tools\Watch\DWordWatch.cs" /> <Compile Include="tools\Watch\DWordWatch.cs" />
@ -239,9 +242,15 @@
<Compile Include="tools\RamSearchEngine.cs" /> <Compile Include="tools\RamSearchEngine.cs" />
<Compile Include="tools\Watch\SeparatorWatch.cs" /> <Compile Include="tools\Watch\SeparatorWatch.cs" />
<Compile Include="tools\Watch\Watch.cs" /> <Compile Include="tools\Watch\Watch.cs" />
<Compile Include="tools\Watch\WatchList\WatchChangeCountComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchEqualityComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchDomainComparer.cs" /> <Compile Include="tools\Watch\WatchList\WatchDomainComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchAddressComparer.cs" /> <Compile Include="tools\Watch\WatchList\WatchAddressComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchList.cs" /> <Compile Include="tools\Watch\WatchList\WatchList.cs" />
<Compile Include="tools\Watch\WatchList\WatchNoteComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchPreviousValueComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchValueComparer.cs" />
<Compile Include="tools\Watch\WatchList\WatchValueDifferenceComparer.cs" />
<Compile Include="tools\Watch\WatchSize.cs" /> <Compile Include="tools\Watch\WatchSize.cs" />
<Compile Include="tools\Watch\WordWatch.cs" /> <Compile Include="tools\Watch\WordWatch.cs" />
<Compile Include="XmlGame.cs" /> <Compile Include="XmlGame.cs" />

View File

@ -232,7 +232,18 @@ namespace BizHawk.Client.Common
/// <returns>True if they are equals; otherwise, false</returns> /// <returns>True if they are equals; otherwise, false</returns>
public static bool operator ==(Watch a, Cheat b) public static bool operator ==(Watch a, Cheat b)
{ {
return a.Equals(b); if (object.ReferenceEquals(a, null) || object.ReferenceEquals(b, null))
{
return false;
}
else if (object.ReferenceEquals(a, b))
{
return true;
}
else
{
return a.Equals(b);
}
} }
/// <summary> /// <summary>

View File

@ -12,83 +12,40 @@ namespace BizHawk.Client.Common
/// Netsed private class that define how to compare two <see cref="Watch"/> /// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on their address /// based on their address
/// </summary> /// </summary>
private struct WatchAddressComparer private sealed class WatchAddressComparer
: IEqualityComparer<Watch>, : WatchEqualityComparer,
IComparer<Watch> IComparer<Watch>
{ {
/// <summary> /// <summary>
/// Compare two <see cref="Watch"/> between them /// Compares two <see cref="Watch"/> between them
/// and determine wich one comes first. /// and determines wich one comes first.
/// If they are equals, comapraison will done one the domain and next on size /// If they are equals, comapraison will done one the domain and next on size
/// </summary> /// </summary>
/// <param name="x">First <see cref="Watch"/></param> /// <param name="x">First <see cref="Watch"/></param>
/// <returns>True if <see cref="Watch"/> are equal; otherwise, false</returns> /// <param name="y">Second <see cref="Watch"/></param>
/// <returns></returns> /// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y) public int Compare(Watch x, Watch y)
{
if (Equals(x, y))
{ {
return 0; if (Equals(x, y))
}
else if (x.Address.Equals(y.Address))
{
if (x.Domain.Name.Equals(y.Domain.Name))
{ {
return x.Size.CompareTo(y.Size); return 0;
}
else if (x.Address.Equals(y.Address))
{
if (x.Domain.Name.Equals(y.Domain.Name))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Domain.Name.CompareTo(y.Domain.Name);
}
} }
else else
{ {
return x.Domain.Name.CompareTo(y.Domain.Name); return x.Address.CompareTo(y.Address);
} }
} }
else
{
return x.Address.CompareTo(y.Address);
}
}
/// <summary>
/// Determine if two <see cref="Watch"/> are equals
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>True if <see cref="Watch"/> are equal; otherwise, false</returns>
public bool Equals(Watch x, Watch y)
{
if (object.ReferenceEquals(x, null))
{
if (object.ReferenceEquals(y, null))
{
return true;
}
else
{
return false;
}
}
else if (object.ReferenceEquals(y, null))
{
return false;
}
else if (object.ReferenceEquals(x, y))
{
return true;
}
else
{
return x.Address.Equals(y.Address);
}
}
/// <summary>
/// Get the hash value of specified <see cref="Watch"/>
/// </summary>
/// <param name="obj">Watch to get hash</param>
/// <returns>int that can serves as a unique representation of current Watch</returns>
public int GetHashCode(Watch obj)
{
return obj.GetHashCode();
} }
} }
} }
}

View File

@ -0,0 +1,51 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
/// <summary>
/// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on the number of changes
/// </summary>
private sealed class WatchChangeCountComparer
:WatchEqualityComparer
,IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y)
{
if (Equals(x, y))
{
return 0;
}
else if (x.ChangeCount.Equals(y.ChangeCount))
{
if (x.Address.Equals(y.Address))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Address.CompareTo(y.Address);
}
}
else
{
return x.ChangeCount.CompareTo(y.ChangeCount);
}
}
}
}
}

View File

@ -12,25 +12,25 @@ namespace BizHawk.Client.Common
/// Netsed private class that define how to compare two <see cref="Watch"/> /// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on their domain /// based on their domain
/// </summary> /// </summary>
private struct WatchDomainComparer private sealed class WatchDomainComparer
: IEqualityComparer<Watch>, : WatchEqualityComparer,
IComparer<Watch> IComparer<Watch>
{ {
/// <summary> /// <summary>
/// Compare two <see cref="Watch"/> between them /// Compares two <see cref="Watch"/> between them
/// and determine wich one comes first. /// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size /// If they are equals, comapraison will done one the address and next on size
/// </summary> /// </summary>
/// <param name="x">First <see cref="Watch"/></param> /// <param name="x">First <see cref="Watch"/></param>
/// <returns>True if <see cref="Watch"/> are equal; otherwise, false</returns> ///<param name="y">Second <see cref="Watch"/></param>
/// <returns></returns> /// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y) public int Compare(Watch x, Watch y)
{ {
if(Equals(x, y)) if (Equals(x, y))
{ {
return 0; return 0;
} }
else if(x.Domain.Name.Equals(y.Domain.Name)) else if (x.Domain.Name.Equals(y.Domain.Name))
{ {
if (x.Address.Equals(y.Address)) if (x.Address.Equals(y.Address))
{ {
@ -46,49 +46,6 @@ namespace BizHawk.Client.Common
return x.Domain.Name.CompareTo(y.Domain.Name); return x.Domain.Name.CompareTo(y.Domain.Name);
} }
} }
/// <summary>
/// Determine if two <see cref="Watch"/> are equals
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>True if <see cref="Watch"/> are equal; otherwise, false</returns>
public bool Equals(Watch x, Watch y)
{
if(object.ReferenceEquals(x, null))
{
if(object.ReferenceEquals(y, null))
{
return true;
}
else
{
return false;
}
}
else if(object.ReferenceEquals(y, null))
{
return false;
}
else if(object.ReferenceEquals(x,y))
{
return true;
}
else
{
return x.Domain.Name.Equals(y.Domain.Name);
}
}
/// <summary>
/// Get the hash value of specified <see cref="Watch"/>
/// </summary>
/// <param name="obj">Watch to get hash</param>
/// <returns>int that can serves as a unique representation of current Watch</returns>
public int GetHashCode(Watch obj)
{
return obj.GetHashCode();
}
} }
} }
} }

View File

@ -0,0 +1,58 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
private class WatchEqualityComparer
: IEqualityComparer<Watch>
{
/// <summary>
/// Determines if two <see cref="Watch"/> are equals
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>True if <see cref="Watch"/> are equal; otherwise, false</returns>
public bool Equals(Watch x, Watch y)
{
if (ReferenceEquals(x, null))
{
if (ReferenceEquals(y, null))
{
return true;
}
else
{
return false;
}
}
else if (ReferenceEquals(y, null))
{
return false;
}
else if (ReferenceEquals(x, y))
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// Gets the hash value of specified <see cref="Watch"/>
/// </summary>
/// <param name="obj">Watch to get hash</param>
/// <returns>int that can serves as a unique representation of current Watch</returns>
public int GetHashCode(Watch obj)
{
return obj.GetHashCode();
}
}
}
}

View File

@ -33,6 +33,11 @@ namespace BizHawk.Client.Common
private static readonly WatchDomainComparer domainComparer = new WatchDomainComparer(); private static readonly WatchDomainComparer domainComparer = new WatchDomainComparer();
private static readonly WatchAddressComparer addressComparer = new WatchAddressComparer(); private static readonly WatchAddressComparer addressComparer = new WatchAddressComparer();
private static readonly WatchValueComparer valueComparer = new WatchValueComparer();
private static readonly WatchPreviousValueComparer previousValueComparer = new WatchPreviousValueComparer();
private static readonly WatchValueDifferenceComparer valueDifferenceComparer = new WatchValueDifferenceComparer();
private static readonly WatchChangeCountComparer changeCountComparer = new WatchChangeCountComparer();
private static readonly WatchNoteComparer noteComparer = new WatchNoteComparer();
private static IMemoryDomains _memoryDomains; private static IMemoryDomains _memoryDomains;
@ -256,92 +261,58 @@ namespace BizHawk.Client.Common
} }
break; break;
case VALUE: case VALUE:
if (reverse) if (reverse)
{ {
_watchList = _watchList _watchList.Sort(valueComparer);
.OrderByDescending(x => x.Value) _watchList.Reverse();
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ThenBy(x => x.BigEndian)
.ToList();
} }
else else
{ {
_watchList = _watchList _watchList.Sort(valueComparer);
.OrderBy(x => x.Value)
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ThenBy(x => x.BigEndian)
.ToList();
} }
break; break;
case PREV: // Note: these only work if all entries are detailed objects!
case PREV:
if (reverse) if (reverse)
{ {
_watchList = _watchList _watchList.Sort(previousValueComparer);
.OrderByDescending(x => x.PreviousStr) _watchList.Reverse();
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
else else
{ {
_watchList = _watchList _watchList.Sort(previousValueComparer);
.OrderBy(x => x.PreviousStr)
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
break; break;
case DIFF: case DIFF:
if (reverse) if (reverse)
{ {
_watchList = _watchList _watchList.Sort(valueDifferenceComparer);
.OrderByDescending(x => x.Diff) _watchList.Reverse();
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
else else
{ {
_watchList = _watchList _watchList.Sort(valueDifferenceComparer);
.OrderBy(x => x.Diff)
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
break; break;
case CHANGES: case CHANGES:
if (reverse) if (reverse)
{ {
_watchList = _watchList _watchList.Sort(changeCountComparer);
.OrderByDescending(x => x.ChangeCount) _watchList.Reverse();
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
else else
{ {
_watchList = _watchList _watchList.Sort(changeCountComparer);
.OrderBy(x => x.ChangeCount)
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
break; break;
case DOMAIN: case DOMAIN:
if (reverse) if (reverse)
{ {
@ -354,24 +325,16 @@ namespace BizHawk.Client.Common
} }
break; break;
case NOTES: case NOTES:
if (reverse) if (reverse)
{ {
_watchList = _watchList _watchList.Sort(noteComparer);
.OrderByDescending(x => x.Notes) _watchList.Reverse();
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
else else
{ {
_watchList = _watchList _watchList.Sort(noteComparer);
.OrderBy(x => x.Notes)
.ThenBy(x => x.Address)
.ThenBy(x => x.Size)
.ThenBy(x => x.Type)
.ToList();
} }
break; break;
@ -521,7 +484,14 @@ namespace BizHawk.Client.Common
}); });
} }
[Obsolete("Use count property instead")] [Obsolete("Use domain from individual watch instead")]
public MemoryDomain Domain
{
get { return _domain; }
set { _domain = value; }
}
[Obsolete("Use count property instead", true)]
public int ItemCount public int ItemCount
{ {
get get
@ -530,13 +500,6 @@ namespace BizHawk.Client.Common
} }
} }
[Obsolete("Use domain from individual watch instead")]
public MemoryDomain Domain
{
get { return _domain; }
set { _domain = value; }
}
#region File handling logic - probably needs to be its own class #region File handling logic - probably needs to be its own class
public bool Load(string path, bool append) public bool Load(string path, bool append)

View File

@ -0,0 +1,51 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
/// <summary>
/// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on their note
/// </summary>
private sealed class WatchNoteComparer
:WatchEqualityComparer,
IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y)
{
if (Equals(x, y))
{
return 0;
}
else if (string.Compare(x.Notes, y.Notes, true) == 0)
{
if (x.Address.Equals(y.Address))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Address.CompareTo(y.Address);
}
}
else
{
return string.Compare(x.Notes, y.Notes, true);
}
}
}
}
}

View File

@ -0,0 +1,51 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
/// <summary>
/// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on their previous value
/// </summary>
private sealed class WatchPreviousValueComparer
: WatchEqualityComparer,
IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y)
{
if (Equals(x, y))
{
return 0;
}
else if (x.Previous.Equals(y.Previous))
{
if (x.Address.Equals(y.Address))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Address.CompareTo(y.Address);
}
}
else
{
return x.Previous.CompareTo(y.Previous);
}
}
}
}
}

View File

@ -0,0 +1,72 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
/// <summary>
/// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on their values
/// </summary>
private sealed class WatchValueComparer
: WatchEqualityComparer,
IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
///<param name="y">Second <see cref="Watch"/></param>
/// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
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);
}
}
}
}
}

View File

@ -0,0 +1,52 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <summary>
/// This class hold a collection <see cref="Watch"/>
/// Different memory domain can be mixed
/// </summary>
public sealed partial class WatchList
{
/// <summary>
/// Netsed private class that define how to compare two <see cref="Watch"/>
/// based on the diffence between current and previous value
/// </summary>
private sealed class WatchValueDifferenceComparer
: WatchEqualityComparer
, IComparer<Watch>
{
/// <summary>
/// Compares two <see cref="Watch"/> between them
/// and determines wich one comes first.
/// If they are equals, comapraison will done one the address and next on size
/// </summary>
/// <param name="x">First <see cref="Watch"/></param>
/// <param name="y">Second <see cref="Watch"/></param>
/// <returns>0 for equality, 1 if x comes first; -1 if y comes first</returns>
public int Compare(Watch x, Watch y)
{
if (Equals(x, y))
{
return 0;
}
else if (x.Diff.Equals(y.Diff))
{
if (x.Address.Equals(y.Address))
{
return x.Size.CompareTo(y.Size);
}
else
{
return x.Address.CompareTo(y.Address);
}
}
else
{
return x.Diff.CompareTo(y.Diff);
}
}
}
}
}

View File

@ -119,7 +119,7 @@ namespace BizHawk.Client.EmuHawk
public void AddWatch(Watch watch) public void AddWatch(Watch watch)
{ {
_watches.Add(watch); _watches.Add(watch);
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateValues(); UpdateValues();
UpdateWatchCount(); UpdateWatchCount();
Changes(); Changes();
@ -176,7 +176,7 @@ namespace BizHawk.Client.EmuHawk
else else
{ {
Global.Config.RecentWatches.Add(path); Global.Config.RecentWatches.Add(path);
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateWatchCount(); UpdateWatchCount();
UpdateStatusBar(); UpdateStatusBar();
_watches.Changes = false; _watches.Changes = false;
@ -197,7 +197,7 @@ namespace BizHawk.Client.EmuHawk
if (result) if (result)
{ {
_watches.Load(file.FullName, append); _watches.Load(file.FullName, append);
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateWatchCount(); UpdateWatchCount();
Global.Config.RecentWatches.Add(_watches.CurrentFileName); Global.Config.RecentWatches.Add(_watches.CurrentFileName);
SetMemoryDomain(_watches.Domain.ToString()); SetMemoryDomain(_watches.Domain.ToString());
@ -386,7 +386,7 @@ namespace BizHawk.Client.EmuHawk
private void FullyUpdateWatchList() private void FullyUpdateWatchList()
{ {
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateWatchCount(); UpdateWatchCount();
UpdateStatusBar(); UpdateStatusBar();
UpdateValues(); UpdateValues();
@ -417,7 +417,7 @@ namespace BizHawk.Client.EmuHawk
if (duplicate) if (duplicate)
{ {
_watches.AddRange(we.Watches); _watches.AddRange(we.Watches);
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
} }
else else
{ {
@ -499,7 +499,7 @@ namespace BizHawk.Client.EmuHawk
if (result || suppressAsk) if (result || suppressAsk)
{ {
_watches.Clear(); _watches.Clear();
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateWatchCount(); UpdateWatchCount();
UpdateStatusBar(); UpdateStatusBar();
_sortReverse = false; _sortReverse = false;
@ -598,7 +598,7 @@ namespace BizHawk.Client.EmuHawk
private void WatchListView_QueryItemBkColor(int index, int column, ref Color color) private void WatchListView_QueryItemBkColor(int index, int column, ref Color color)
{ {
if (index >= _watches.ItemCount) if (index >= _watches.Count)
{ {
return; return;
} }
@ -624,7 +624,7 @@ namespace BizHawk.Client.EmuHawk
{ {
text = string.Empty; text = string.Empty;
if (index >= _watches.ItemCount || _watches[index].IsSeparator) if (index >= _watches.Count || _watches[index].IsSeparator)
{ {
return; return;
} }
@ -764,7 +764,7 @@ namespace BizHawk.Client.EmuHawk
_watches.Add(we.Watches[0]); _watches.Add(we.Watches[0]);
Changes(); Changes();
UpdateWatchCount(); UpdateWatchCount();
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateValues(); UpdateValues();
} }
} }
@ -784,7 +784,7 @@ namespace BizHawk.Client.EmuHawk
_watches.Remove(item); _watches.Remove(item);
} }
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateValues(); UpdateValues();
UpdateWatchCount(); UpdateWatchCount();
} }
@ -838,7 +838,7 @@ namespace BizHawk.Client.EmuHawk
_watches.Add(SeparatorWatch.Instance); _watches.Add(SeparatorWatch.Instance);
} }
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
Changes(); Changes();
UpdateWatchCount(); UpdateWatchCount();
} }
@ -873,7 +873,7 @@ namespace BizHawk.Client.EmuHawk
WatchListView.SelectItem(t, true); WatchListView.SelectItem(t, true);
} }
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
} }
private void MoveDownMenuItem_Click(object sender, EventArgs e) private void MoveDownMenuItem_Click(object sender, EventArgs e)
@ -900,7 +900,7 @@ namespace BizHawk.Client.EmuHawk
} }
Changes(); Changes();
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
} }
private void SelectAllMenuItem_Click(object sender, EventArgs e) private void SelectAllMenuItem_Click(object sender, EventArgs e)
@ -1037,8 +1037,8 @@ namespace BizHawk.Client.EmuHawk
{ {
_watches.Load(filePaths[0], append: false); _watches.Load(filePaths[0], append: false);
Global.Config.RecentWatches.Add(_watches.CurrentFileName); Global.Config.RecentWatches.Add(_watches.CurrentFileName);
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
} }
} }
private void NewRamWatch_Enter(object sender, EventArgs e) private void NewRamWatch_Enter(object sender, EventArgs e)
@ -1205,7 +1205,7 @@ namespace BizHawk.Client.EmuHawk
_watches.Remove(item); _watches.Remove(item);
} }
WatchListView.ItemCount = _watches.ItemCount; WatchListView.ItemCount = _watches.Count;
UpdateValues(); UpdateValues();
UpdateWatchCount(); UpdateWatchCount();
UpdateStatusBar(); UpdateStatusBar();

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.23107.0 VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Version", "Version\Version.csproj", "{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Version", "Version\Version.csproj", "{0CE8B337-08E3-4602-BF10-C4D4C75D2F13}"
EndProject EndProject
@ -250,18 +250,18 @@ Global
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Win32.ActiveCfg = Debug|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Win32.ActiveCfg = Debug|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Win32.Build.0 = Debug|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|Win32.Build.0 = Debug|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|x86.ActiveCfg = Debug|x86 {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|x86.ActiveCfg = Debug|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|x86.Build.0 = Debug|x86 {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Debug|x86.Build.0 = Debug|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Any CPU.Build.0 = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Any CPU.Build.0 = Release|Any CPU
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Mixed Platforms.ActiveCfg = Release|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Mixed Platforms.Build.0 = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Mixed Platforms.Build.0 = Release|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Win32.ActiveCfg = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Win32.ActiveCfg = Release|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Win32.Build.0 = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|Win32.Build.0 = Release|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|x86.ActiveCfg = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|x86.ActiveCfg = Release|x86
{8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|x86.Build.0 = Release|Any CPU {8E2F11F2-3955-4382-8C3A-CEBA1276CAEA}.Release|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE