RamSearchEngine - simplify watchList creation with extension methods
This commit is contained in:
parent
35ab6762a2
commit
d6e56f8aa8
|
@ -1,4 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common.RamSearchEngine
|
||||
{
|
||||
|
@ -9,5 +12,38 @@ namespace BizHawk.Client.Common.RamSearchEngine
|
|||
var bytes = BitConverter.GetBytes((int)val);
|
||||
return BitConverter.ToSingle(bytes, 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<IMiniWatch> ToBytes(this IEnumerable<long> addresses, SearchEngineSettings settings)
|
||||
=> settings.IsDetailed()
|
||||
? addresses.ToBytes(settings.Domain)
|
||||
: addresses.ToDetailedBytes(settings.Domain);
|
||||
|
||||
public static IEnumerable<IMiniWatch> ToWords(this IEnumerable<long> addresses, SearchEngineSettings settings)
|
||||
=> settings.IsDetailed()
|
||||
? addresses.ToWords(settings.Domain, settings.BigEndian)
|
||||
: addresses.ToDetailedWords(settings.Domain, settings.BigEndian);
|
||||
|
||||
public static IEnumerable<IMiniWatch> ToDWords(this IEnumerable<long> addresses, SearchEngineSettings settings)
|
||||
=> settings.IsDetailed()
|
||||
? addresses.ToDWords(settings.Domain, settings.BigEndian)
|
||||
: addresses.ToDetailedDWords(settings.Domain, settings.BigEndian);
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToBytes(this IEnumerable<long> addresses, MemoryDomain domain)
|
||||
=> addresses.Select(a => new MiniByteWatch(domain, a));
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToDetailedBytes(this IEnumerable<long> addresses, MemoryDomain domain)
|
||||
=> addresses.Select(a => new MiniByteWatchDetailed(domain, a));
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToWords(this IEnumerable<long> addresses, MemoryDomain domain, bool bigEndian)
|
||||
=> addresses.Select(a => new MiniWordWatch(domain, a, bigEndian));
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToDetailedWords(this IEnumerable<long> addresses, MemoryDomain domain, bool bigEndian)
|
||||
=> addresses.Select(a => new MiniWordWatchDetailed(domain, a, bigEndian));
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToDWords(this IEnumerable<long> addresses, MemoryDomain domain, bool bigEndian)
|
||||
=> addresses.Select(a => new MiniDWordWatch(domain, a, bigEndian));
|
||||
|
||||
private static IEnumerable<IMiniWatch> ToDetailedDWords(this IEnumerable<long> addresses, MemoryDomain domain, bool bigEndian)
|
||||
=> addresses.Select(a => new MiniDWordWatchDetailed(domain, a, bigEndian));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,61 +298,13 @@ namespace BizHawk.Client.Common.RamSearchEngine
|
|||
_watchList.Clear();
|
||||
}
|
||||
|
||||
switch (_settings.Size)
|
||||
_watchList = _settings.Size switch
|
||||
{
|
||||
default:
|
||||
case WatchSize.Byte:
|
||||
if (_settings.IsDetailed())
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniByteWatchDetailed(_settings.Domain, addr));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniByteWatch(_settings.Domain, addr));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case WatchSize.Word:
|
||||
if (_settings.IsDetailed())
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniWordWatchDetailed(_settings.Domain, addr, _settings.BigEndian));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniWordWatch(_settings.Domain, addr, _settings.BigEndian));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case WatchSize.DWord:
|
||||
if (_settings.IsDetailed())
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniDWordWatchDetailed(_settings.Domain, addr, _settings.BigEndian));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var addr in addresses)
|
||||
{
|
||||
_watchList.Add(new MiniDWordWatch(_settings.Domain, addr, _settings.BigEndian));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
WatchSize.Byte => addresses.ToBytes(_settings).ToList(),
|
||||
WatchSize.Word => addresses.ToWords(_settings).ToList(),
|
||||
WatchSize.DWord => addresses.ToDWords(_settings).ToList(),
|
||||
_ => addresses.ToBytes(_settings).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Sort(string column, bool reverse)
|
||||
|
|
Loading…
Reference in New Issue