More WatchList comments

Finished coments on WatchList object
This commit is contained in:
Hathor86 2015-12-02 22:47:24 +01:00
parent 0f6ef723bf
commit 31cc08a954
5 changed files with 276 additions and 138 deletions

1
.gitignore vendored
View File

@ -266,3 +266,4 @@
/LuaInterface/Lua/src/Release-LUAPERKS
/LuaInterface/Release-LUAPERKS
output/BizHawk.Client.ApiHawk.dll
output/dll/BizHawk.Client.ApiHawk.dll

View File

@ -32,7 +32,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<OutputPath>..\output\dll\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
@ -40,7 +40,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<OutputPath>..\output\dll\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Diagnostics;
using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common;
@ -13,6 +14,7 @@ namespace BizHawk.Client.Common
/// with a specific size (8, 16 or 32bits).
/// This is an abstract class
/// </summary>
[DebuggerDisplay("Note={Notes}, Value={ValueString}")]
public abstract partial class Watch
: IEquatable<Watch>,
IEquatable<Cheat>,
@ -68,7 +70,7 @@ namespace BizHawk.Client.Common
#region Static
/// <summary>
/// Generate a <see cref="Watch"/> from a given string
/// Generate sa <see cref="Watch"/> from a given string
/// String is tab separate
/// </summary>
/// <param name="line">Entire string, tab seperated for each value Order is:
@ -138,7 +140,7 @@ namespace BizHawk.Client.Common
}
/// <summary>
/// Generate a new <see cref="Watch"/> instance
/// Generates a new <see cref="Watch"/> instance
/// Can be either <see cref="ByteWatch"/>, <see cref="WordWatch"/>, <see cref="DWordWatch"/> or <see cref="SeparatorWatch"/>
/// </summary>
/// <param name="domain">The <see cref="MemoryDomain"/> where you want to watch</param>
@ -168,7 +170,7 @@ namespace BizHawk.Client.Common
}
/// <summary>
/// Generate a new <see cref="Watch"/> instance
/// Generates a new <see cref="Watch"/> instance
/// Can be either <see cref="ByteWatch"/>, <see cref="WordWatch"/>, <see cref="DWordWatch"/> or <see cref="SeparatorWatch"/>
/// </summary>
/// <param name="domain">The <see cref="MemoryDomain"/> where you want to watch</param>
@ -184,7 +186,7 @@ namespace BizHawk.Client.Common
}
/// <summary>
/// Generate a new <see cref="Watch"/> instance
/// Generates a new <see cref="Watch"/> instance
/// Can be either <see cref="ByteWatch"/>, <see cref="WordWatch"/>, <see cref="DWordWatch"/> or <see cref="SeparatorWatch"/>
/// </summary>
/// <param name="domain">The <see cref="MemoryDomain"/> where you want to watch</param>
@ -310,18 +312,18 @@ namespace BizHawk.Client.Common
#region Abstracts
/// <summary>
/// Get a list a <see cref="DisplayType"/> that can be used for this <see cref="Watch"/>
/// Gets a list a <see cref="DisplayType"/> that can be used for this <see cref="Watch"/>
/// </summary>
/// <returns>An enumartion that contains all valid <see cref="DisplayType"/></returns>
public abstract IEnumerable<DisplayType> AvailableTypes();
/// <summary>
/// Reset the previous value; set it to the current one
/// Resets the previous value; set it to the current one
/// </summary>
public abstract void ResetPrevious();
/// <summary>
/// Update the Watch (read it from <see cref="MemoryDomain"/>
/// Updates the Watch (read it from <see cref="MemoryDomain"/>
/// </summary>
public abstract void Update();
@ -413,7 +415,7 @@ namespace BizHawk.Client.Common
#endregion Protected
/// <summary>
/// Set the number of changes to 0
/// Sets the number of changes to 0
/// </summary>
public void ClearChangeCount()
{
@ -423,7 +425,7 @@ namespace BizHawk.Client.Common
#region IEquatable<Watch>
/// <summary>
/// Determine if this <see cref="Watch"/> is equals to another
/// Determines if this <see cref="Watch"/> is equals to another
/// </summary>
/// <param name="obj">The <see cref="Watch"/> to compare</param>
/// <returns>True if both object are equals; otherwise, false</returns>
@ -446,7 +448,7 @@ namespace BizHawk.Client.Common
#region IEquatable<Cheat>
/// <summary>
/// Determine if this <see cref="Watch"/> is equals to an instance of <see cref="Cheat"/>
/// Determines if this <see cref="Watch"/> is equals to an instance of <see cref="Cheat"/>
/// </summary>
/// <param name="obj">The <see cref="Cheat"/> to compare</param>
/// <returns>True if both object are equals; otherwise, false</returns>
@ -463,7 +465,7 @@ namespace BizHawk.Client.Common
#region IComparable<Watch>
/// <summary>
/// Compare two <see cref="Watch"/> together and determine wich one comes first.
/// Compares two <see cref="Watch"/> together and determine wich one comes first.
/// First we look the address and then the size
/// </summary>
/// <param name="other">The other <see cref="Watch"/> to compare to</param>
@ -497,7 +499,7 @@ namespace BizHawk.Client.Common
#endregion IComparable<Watch>
/// <summary>
/// Determine if this object is Equals to another
/// Determines if this object is Equals to another
/// </summary>
/// <param name="obj">The object to compare</param>
/// <returns>True if both object are equals; otherwise, false</returns>
@ -521,14 +523,14 @@ namespace BizHawk.Client.Common
/// <summary>
/// Hash the current watch and gets a unique value
/// </summary>
/// <returns>int that can serves as a unique representation of current Watch</returns>
/// <returns><see cref="int"/> that can serves as a unique representation of current Watch</returns>
public override int GetHashCode()
{
return this.Domain.GetHashCode() + (int)(this.Address);
}
/// <summary>
/// Determine if the specified <see cref="DisplayType"/> can be
/// Determines if the specified <see cref="DisplayType"/> can be
/// used for the current <see cref="Watch"/>
/// </summary>
/// <param name="type"><see cref="DisplayType"/> you want to check</param>
@ -539,7 +541,7 @@ namespace BizHawk.Client.Common
}
/// <summary>
/// Transform the current instance into a string
/// Transforms the current instance into a string
/// </summary>
/// <returns>A <see cref="string"/> representation of the current <see cref="Watch"/></returns>
public override string ToString()

View File

@ -85,107 +85,161 @@ namespace BizHawk.Client.Common
#region Methods
[Obsolete("Use the method with single parameter instead")]
public void RefreshDomains(IMemoryDomains core, MemoryDomain domain)
{
_memoryDomains = core;
_domain = domain;
#region ICollection<Watch>
_watchList.ForEach(w =>
{
if (w.Domain != null)
{
w.Domain = _memoryDomains[w.Domain.Name];
}
});
/// <summary>
/// Adds a <see cref="Watch"/> into the current collection
/// </summary>
/// <param name="watch"><see cref="Watch"/> to add</param>
public void Add(Watch watch)
{
_watchList.Add(watch);
Changes = true;
}
public void RefreshDomains(IMemoryDomains core)
/// <summary>
/// Removes all item from the current collection
/// Clear also the file name
/// </summary>
public void Clear()
{
_memoryDomains = core;
Parallel.ForEach<Watch>(_watchList, watch =>
_watchList.Clear();
Changes = false;
_currentFilename = string.Empty;
}
/// <summary>
/// Determines if the current <see cref="WatchList"/> contains the
/// specified <see cref="Watch"/>
/// </summary>
/// <param name="watch">The object to</param>
/// <returns></returns>
public bool Contains(Watch watch)
{
return _watchList.Contains(watch);
}
/// <summary>
/// Copies the elements of the current <see cref="WatchList"/>
/// into an <see cref="Array"/> starting at a particular <see cref="Array"/> index
/// </summary>
/// <param name="array">The one-dimension <see cref="Array"/> that will serve as destination to copy</param>
/// <param name="arrayIndex">Zero-based index where the copy should starts</param>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentOutOfRangeException"></exception>
/// <exception cref="ArgumentException"></exception>
public void CopyTo(Watch[] array, int arrayIndex)
{
_watchList.CopyTo(array, arrayIndex);
}
/// <summary>
/// Removes the first of specified <see cref="Watch"/>
/// </summary>
/// <param name="watch"><see cref="Watch"/> to remove</param>
/// <returns>True if <see cref="Watch"/> successfully removed; otherwise, false</returns>
public bool Remove(Watch watch)
{
bool result = _watchList.Remove(watch);
if (result)
{
watch.Domain = core[watch.Domain.Name];
watch.ResetPrevious();
watch.Update();
watch.ClearChangeCount();
Changes = true;
}
);
return result;
}
#endregion
public string AddressFormatStr // TODO: this is probably compensating for not using the ToHex string extension
{
get
{
if (_domain != null)
{
return "{0:X" + (_domain.Size - 1).NumHexDigits() + "}";
}
#region IList<Watch>
return string.Empty;
}
/// <summary>
/// Determines the zero-base position of the specified <see cref="Watch"/>
/// into the <see cref="WatchList"/>
/// </summary>
/// <param name="watch"><see cref="Watch"/> to look for</param>
/// <returns>Zero-base position if <see cref="Watch"/> has been found; otherwise -1</returns>
public int IndexOf(Watch watch)
{
return _watchList.IndexOf(watch);
}
public int Count
/// <summary>
/// Insert a <see cref="Watch"/> at the specified index
/// </summary>
/// <param name="index">The zero-base index where the <see cref="Watch"/> should be inserted</param>
/// <param name="watch"><see cref="Watch"/> to insert</param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public void Insert(int index, Watch watch)
{
get
{
return _watchList.Count;
}
_watchList.Insert(index, watch);
}
public int WatchCount
/// <summary>
/// Removes item at the specified index
/// </summary>
/// <param name="index">Zero-based index of the <see cref="Watch"/> to remove</param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public void RemoveAt(int index)
{
get
{
return _watchList.Count<Watch>(watch => !watch.IsSeparator);
}
_watchList.RemoveAt(index);
Changes = true;
}
[Obsolete("Use count property instead")]
public int ItemCount
{
get
{
return Count;
}
}
#endregion IList<Watch>
[Obsolete("Use domain from individual watch instead")]
public MemoryDomain Domain
{
get { return _domain; }
set { _domain = value; }
}
public bool IsReadOnly { get { return false; } }
public string CurrentFileName
{
get { return _currentFilename; }
set { _currentFilename = value; }
}
public bool Changes { get; set; }
public Watch this[int index]
{
get { return _watchList[index]; }
set { _watchList[index] = value; }
}
#region IEnumerable<Watch>
/// <summary>
/// Returns an enumerator that iterates through the collection
/// </summary>
/// <returns>An <see cref="IEnumerator{T}"/> for the current collection</returns>
public IEnumerator<Watch> GetEnumerator()
{
return _watchList.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates through the collection
/// </summary>
/// <returns>An <see cref="IEnumerator"/> for the current collection</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion IEnumerable<Watch>
/// <summary>
/// Add an existing collection of <see cref="Watch"/> into the current one
/// <see cref="Watch"/> equality will be checked to avoid doubles
/// </summary>
/// <param name="watches"><see cref="IEnumerable{Watch}"/> of watch to merge</param>
public void AddRange(IEnumerable<Watch> watches)
{
Parallel.ForEach<Watch>(watches, watch =>
{
if (!_watchList.Contains(watch))
{
_watchList.Add(watch);
}
});
Changes = true;
}
/// <summary>
/// Clears change count of all <see cref="Watch"/> in the collection
/// </summary>
public void ClearChangeCounts()
{
Parallel.ForEach<Watch>(_watchList, watch => watch.ClearChangeCount());
}
/// <summary>
/// Sort the current list based on one of the constant
/// </summary>
/// <param name="column">Value that specify sorting base</param>
/// <param name="reverse">Value that define the ordering. Ascending (true) or desceding (false)</param>
public void OrderWatches(string column, bool reverse)
{
switch (column)
@ -324,13 +378,27 @@ namespace BizHawk.Client.Common
}
}
public void Clear()
/// <summary>
/// Sets WatchList's domain list to a new one
/// <see cref="Watch"/> domain will also be refreshed
/// </summary>
/// <param name="core">New domains</param>
public void RefreshDomains(IMemoryDomains core)
{
_watchList.Clear();
Changes = false;
_currentFilename = string.Empty;
_memoryDomains = core;
Parallel.ForEach<Watch>(_watchList, watch =>
{
watch.Domain = core[watch.Domain.Name];
watch.ResetPrevious();
watch.Update();
watch.ClearChangeCount();
}
);
}
/// <summary>
/// Updates all <see cref="Watch"/> ine the current collection
/// </summary>
public void UpdateValues()
{
Parallel.ForEach<Watch>(_watchList, watch =>
@ -339,66 +407,134 @@ namespace BizHawk.Client.Common
});
}
public void Add(Watch watch)
public string AddressFormatStr // TODO: this is probably compensating for not using the ToHex string extension
{
_watchList.Add(watch);
Changes = true;
}
public void AddRange(IList<Watch> watches)
{
_watchList.AddRange(watches);
Changes = true;
}
public bool Remove(Watch watch)
{
var result = _watchList.Remove(watch);
if (result)
get
{
Changes = true;
}
if (_domain != null)
{
return "{0:X" + (_domain.Size - 1).NumHexDigits() + "}";
}
return result;
}
public void Insert(int index, Watch watch)
{
_watchList.Insert(index, watch);
}
public void ClearChangeCounts()
{
foreach (var watch in _watchList)
{
watch.ClearChangeCount();
return string.Empty;
}
}
public bool Contains(Watch watch)
#endregion
#region Propeties
#region ICollection<Watch>
/// <summary>
/// Gets the number of elements contained in this <see cref="WatchList"/>
/// </summary>
public int Count
{
return _watchList.Any(w =>
w.Size == watch.Size &&
w.Type == watch.Type &&
w.Domain == watch.Domain &&
w.Address == watch.Address &&
w.BigEndian == watch.BigEndian);
get
{
return _watchList.Count;
}
}
public void CopyTo(Watch[] array, int arrayIndex)
/// <summary>
/// <see cref="WatchList"/> is alsways read-write
/// so this value will be always false
/// </summary>
public bool IsReadOnly
{
_watchList.CopyTo(array, arrayIndex);
get
{
return false;
}
}
public int IndexOf(Watch watch)
#endregion ICollection<Watch>
#region IList<Watch>
/// <summary>
/// Gets or sets element at the specified index
/// </summary>
/// <param name="index">The zero based index of the element you want to get or set</param>
/// <returns><see cref="Watch"/> at the specified index</returns>
public Watch this[int index]
{
return _watchList.IndexOf(watch);
get
{
return _watchList[index];
}
set
{
_watchList[index] = value;
}
}
public void RemoveAt(int index)
#endregion IList<Watch>
/// <summary>
/// Gets a value indicating if collection has changed or not
/// </summary>
public bool Changes { get; set; }
/// <summary>
/// Gets or sets current <see cref="WatchList"/>'s filename
/// </summary>
public string CurrentFileName
{
_watchList.RemoveAt(index);
Changes = true;
get
{
return _currentFilename;
}
set
{
_currentFilename = value;
}
}
/// <summary>
/// Gets the number of <see cref="Watch"/> that are not <see cref="SeparatorWatch"/>
/// </summary>
public int WatchCount
{
get
{
return _watchList.Count<Watch>(watch => !watch.IsSeparator);
}
}
#endregion
[Obsolete("Use the method with single parameter instead")]
public void RefreshDomains(IMemoryDomains core, MemoryDomain domain)
{
_memoryDomains = core;
_domain = domain;
_watchList.ForEach(w =>
{
if (w.Domain != null)
{
w.Domain = _memoryDomains[w.Domain.Name];
}
});
}
[Obsolete("Use count property instead")]
public int ItemCount
{
get
{
return Count;
}
}
[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
@ -608,7 +744,6 @@ namespace BizHawk.Client.Common
return true;
}
#endregion
}
}

View File

@ -84,7 +84,7 @@ namespace BizHawk.Client.EmuHawk
public T Load<T>(string toolPath, bool focus = true)
where T : class, IToolForm
{
if (!IsAvailable<T>())
if (!IsAvailable<T>() && typeof(T) != typeof(IExternalToolForm))
{
return null;
}
@ -566,7 +566,7 @@ namespace BizHawk.Client.EmuHawk
//Hard stuff as we need a proxy object that inherit from MarshalByRefObject.
if (toolType == typeof(IExternalToolForm))
{
if (MessageBox.Show(@"Are you sure want to load this external tool?\r\nAccept ONLY if you trust the source and if you know what you're doing. In any other case, choose no."
if (MessageBox.Show("Are you sure want to load this external tool?\r\nAccept ONLY if you trust the source and if you know what you're doing. In any other case, choose no."
, "Confirmm loading", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try