128 lines
3.3 KiB
C#
128 lines
3.3 KiB
C#
using System;
|
|
using System.Xml.Linq;
|
|
using System.Globalization;
|
|
|
|
namespace DataFileAnalyzer
|
|
{
|
|
/// <summary>
|
|
/// The key of a data file.
|
|
/// This is only used on a local computer. Never shared between users.
|
|
/// </summary>
|
|
public struct DataFileKey : IComparable, IComparable<DataFileKey>
|
|
{
|
|
/// <summary>
|
|
/// The invalid key value
|
|
/// </summary>
|
|
public static readonly UInt64 InvalidKeyValue = 0xFFFFFFFFFFFFFFFF;
|
|
|
|
/// <summary>
|
|
/// The invalid key
|
|
/// </summary>
|
|
public static readonly DataFileKey Invalid = new DataFileKey(InvalidKeyValue);
|
|
|
|
/// <summary>
|
|
/// The value of the key
|
|
/// </summary>
|
|
private UInt64 m_keyValue;
|
|
|
|
/// <summary>
|
|
/// The value of the key
|
|
/// </summary>
|
|
public UInt64 KeyValue { get { return m_keyValue; } set { m_keyValue = value; } }
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public DataFileKey(UInt64 _value) { m_keyValue = _value; }
|
|
|
|
/// <summary>
|
|
/// Comparison
|
|
/// </summary>
|
|
public override bool Equals(object _other)
|
|
{
|
|
return
|
|
_other.GetType() == typeof(DataFileKey) &&
|
|
m_keyValue == ((DataFileKey)_other).m_keyValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Comparison
|
|
/// </summary>
|
|
public static bool operator ==(DataFileKey k1, DataFileKey k2)
|
|
{
|
|
return k1.Equals(k2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Comparison
|
|
/// </summary>
|
|
public static bool operator !=(DataFileKey k1, DataFileKey k2)
|
|
{
|
|
return !k1.Equals(k2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hash code
|
|
/// </summary>
|
|
public override int GetHashCode()
|
|
{
|
|
return KeyValue.GetHashCode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ToString
|
|
/// </summary>
|
|
public override string ToString()
|
|
{
|
|
return KeyValue.ToString("X16");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is it an invalid key?
|
|
/// </summary>
|
|
public bool IsInvalid()
|
|
{
|
|
return m_keyValue == InvalidKeyValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set this key as invalid
|
|
/// </summary>
|
|
public void SetInvalid()
|
|
{
|
|
m_keyValue = InvalidKeyValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save to an XML element
|
|
/// </summary>
|
|
public static bool Save(DataFileKey _key, XElement _element)
|
|
{
|
|
_element.SetAttributeValue("Key", _key.ToString());
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load from an XML element
|
|
/// </summary>
|
|
public static DataFileKey Load(XElement _element)
|
|
{
|
|
UInt64 keyValue;
|
|
if (UInt64.TryParse(_element.Attribute("Key").Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out keyValue))
|
|
return new DataFileKey(keyValue);
|
|
return DataFileKey.Invalid;
|
|
}
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if (!(obj is DataFileKey))
|
|
return 1;
|
|
return CompareTo((DataFileKey)obj);
|
|
}
|
|
|
|
public int CompareTo(DataFileKey other)
|
|
{
|
|
return ToString().CompareTo(other.ToString());
|
|
}
|
|
}
|
|
}
|