DOCUMENTATION: Added XML documentation to DiscImageChef.Helpers.

This commit is contained in:
2017-12-23 03:51:42 +00:00
parent 6622bef335
commit 481e39c399
17 changed files with 687 additions and 437 deletions

View File

@@ -31,12 +31,24 @@ namespace DiscImageChef
{ {
public static partial class ArrayHelpers public static partial class ArrayHelpers
{ {
/// <summary>
/// Fills an array with the specified value
/// </summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T value) public static void ArrayFill<T>(T[] destinationArray, T value)
{ {
// if called with a single value, wrap the value in an array and call the main function // if called with a single value, wrap the value in an array and call the main function
ArrayFill(destinationArray, new[] {value}); ArrayFill(destinationArray, new[] {value});
} }
/// <summary>
/// Fills an array with the contents of the specified array
/// </summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T[] value) public static void ArrayFill<T>(T[] destinationArray, T[] value)
{ {
if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray));
@@ -54,6 +66,12 @@ namespace DiscImageChef
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
} }
/// <summary>
/// Converts a byte array to its hexadecimal representation
/// </summary>
/// <param name="array">Byte array</param>
/// <param name="upper"><c>true</c> to use uppercase</param>
/// <returns></returns>
public static string ByteArrayToHex(byte[] array, bool upper = false) public static string ByteArrayToHex(byte[] array, bool upper = false)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@@ -36,11 +36,21 @@ namespace DiscImageChef
{ {
public static partial class ArrayHelpers public static partial class ArrayHelpers
{ {
/// <summary>
/// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20)
/// </summary>
/// <param name="array">Array</param>
/// <returns>True if null or whitespace</returns>
public static bool ArrayIsNullOrWhiteSpace(byte[] array) public static bool ArrayIsNullOrWhiteSpace(byte[] array)
{ {
return array == null || array.All(b => b == 0x00 || b == 0x20); return array == null || array.All(b => b == 0x00 || b == 0x20);
} }
/// <summary>
/// Checks if an array is null or filled with the NULL byte (0x00)
/// </summary>
/// <param name="array">Array</param>
/// <returns>True if null</returns>
public static bool ArrayIsNullOrEmpty(byte[] array) public static bool ArrayIsNullOrEmpty(byte[] array)
{ {
return array == null || array.All(b => b == 0x00); return array == null || array.All(b => b == 0x00);

View File

@@ -49,318 +49,177 @@ namespace DiscImageChef
/// </summary> /// </summary>
public static bool IsLittleEndian { get; set; } public static bool IsLittleEndian { get; set; }
// should default to false, which is what we want for Empire
/// <summary> /// <summary>
/// Converts the specified double-precision floating point number to a 64-bit /// Converts the specified double-precision floating point number to a 64-bit signed integer.
/// signed integer.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// A 64-bit signed integer whose value is equivalent to value.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>A 64-bit signed integer whose value is equivalent to value.</returns>
/// <exception cref="NotImplementedException">It is not currently implemented</exception>
public static long DoubleToInt64Bits(double value) public static long DoubleToInt64Bits(double value)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
///
/// <summary> /// <summary>
/// Returns the specified Boolean value as an array of bytes. /// Returns the specified Boolean value as an array of bytes.
///
/// Parameters:
/// value:
/// A Boolean value.
///
/// Returns:
/// An array of bytes with length 1.
/// </summary> /// </summary>
/// <param name="value">A Boolean value.</param>
/// <returns>An array of bytes with length 1.</returns>
public static byte[] GetBytes(bool value) public static byte[] GetBytes(bool value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified Unicode character value as an array of bytes. /// Returns the specified Unicode character value as an array of bytes.
///
/// Parameters:
/// value:
/// A character to convert.
///
/// Returns:
/// An array of bytes with length 2.
/// </summary> /// </summary>
/// <param name="value">A character to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(char value) public static byte[] GetBytes(char value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified double-precision floating point value as an array of /// Returns the specified double-precision floating point value as an array of bytes.
/// bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(double value) public static byte[] GetBytes(double value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified single-precision floating point value as an array of /// Returns the specified single-precision floating point value as an array of bytes.
/// bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(float value) public static byte[] GetBytes(float value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 32-bit signed integer value as an array of bytes. /// Returns the specified 32-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(int value) public static byte[] GetBytes(int value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 64-bit signed integer value as an array of bytes. /// Returns the specified 64-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(long value) public static byte[] GetBytes(long value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 16-bit signed integer value as an array of bytes. /// Returns the specified 16-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 2.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(short value) public static byte[] GetBytes(short value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 32-bit unsigned integer value as an array of bytes. /// Returns the specified 32-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
/// </summary> /// </summary>
//[CLSCompliant(false)] /// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(uint value) public static byte[] GetBytes(uint value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 64-bit unsigned integer value as an array of bytes. /// Returns the specified 64-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
/// </summary> /// </summary>
//[CLSCompliant(false)] /// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(ulong value) public static byte[] GetBytes(ulong value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Returns the specified 16-bit unsigned integer value as an array of bytes. /// Returns the specified 16-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 2.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(ushort value) public static byte[] GetBytes(ushort value)
{ {
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
} }
///
/// <summary> /// <summary>
/// Converts the specified 64-bit signed integer to a double-precision floating /// Converts the specified 64-bit signed integer to a double-precision floating point number.
/// point number.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// A double-precision floating point number whose value is equivalent to value.
/// </summary> /// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>A double-precision floating point number whose value is equivalent to value.</returns>
public static double Int64BitsToDouble(long value) public static double Int64BitsToDouble(long value)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
///
/// <summary> /// <summary>
/// Returns a Boolean value converted from one byte at a specified position in /// Returns a Boolean value converted from one byte at a specified position in a byte array.
/// a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// true if the byte at startIndex in value is nonzero; otherwise, false.
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>true if the byte at <see cref="startIndex"/> in value is nonzero; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static bool ToBoolean(byte[] value, int startIndex) public static bool ToBoolean(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
///
/// <summary> /// <summary>
/// Returns a Unicode character converted from two bytes at a specified position /// Returns a Unicode character converted from two bytes at a specified position in a byte array.
/// in a byte array.
///
/// Parameters:
/// value:
/// An array.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A character formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A character formed by two bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static char ToChar(byte[] value, int startIndex) public static char ToChar(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
///
/// <summary> /// <summary>
/// Returns a double-precision floating point number converted from eight bytes /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
/// at a specified position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A double precision floating point number formed by eight bytes beginning
/// at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A double precision floating point number formed by eight bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static double ToDouble(byte[] value, int startIndex) public static double ToDouble(byte[] value, int startIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
///
/// <summary> /// <summary>
/// Returns a 16-bit signed integer converted from two bytes at a specified position /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
/// in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 16-bit signed integer formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 16-bit signed integer formed by two bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static short ToInt16(byte[] value, int startIndex) public static short ToInt16(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -368,32 +227,15 @@ namespace DiscImageChef
: BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex);
} }
///
/// <summary> /// <summary>
/// Returns a 32-bit signed integer converted from four bytes at a specified /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 32-bit signed integer formed by four bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit signed integer formed by four bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static int ToInt32(byte[] value, int startIndex) public static int ToInt32(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -401,32 +243,15 @@ namespace DiscImageChef
: BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex);
} }
///
/// <summary> /// <summary>
/// Returns a 64-bit signed integer converted from eight bytes at a specified /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 64-bit signed integer formed by eight bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit signed integer formed by eight bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static long ToInt64(byte[] value, int startIndex) public static long ToInt64(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -434,33 +259,15 @@ namespace DiscImageChef
: BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex);
} }
///
/// <summary> /// <summary>
/// Returns a single-precision floating point number converted from four bytes /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
/// at a specified position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A single-precision floating point number formed by four bytes beginning at
/// startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A single-precision floating point number formed by four bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static float ToSingle(byte[] value, int startIndex) public static float ToSingle(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -468,52 +275,25 @@ namespace DiscImageChef
: BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex);
} }
///
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified array of bytes /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in value; for example, "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
public static string ToString(byte[] value) public static string ToString(byte[] value)
{ {
return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray());
} }
///
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in a subarray of value; for example,
/// "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static string ToString(byte[] value, int startIndex) public static string ToString(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -521,39 +301,16 @@ namespace DiscImageChef
: BitConverter.ToString(value.Reverse().ToArray(), startIndex); : BitConverter.ToString(value.Reverse().ToArray(), startIndex);
} }
///
/// <summary> /// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// length:
/// The number of array elements in value to convert.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in a subarray of value; for example,
/// "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex or length is less than zero. -or- startIndex is greater than
/// zero and is greater than or equal to the length of value.
///
/// System.ArgumentException:
/// The combination of startIndex and length does not specify a position within
/// value; that is, the startIndex parameter is greater than the length of value
/// minus the length parameter.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <param name="length">The number of array elements in value to convert.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value.</exception>
/// <exception cref="System.ArgumentException">The combination of startIndex and length does not specify a position within value; that is, the startIndex parameter is greater than the length of value minus the length parameter.</exception>
public static string ToString(byte[] value, int startIndex, int length) public static string ToString(byte[] value, int startIndex, int length)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -561,31 +318,15 @@ namespace DiscImageChef
: BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length);
} }
///
/// <summary> /// <summary>
/// Returns a 16-bit unsigned integer converted from two bytes at a specified /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
/// position in a byte array.
///
/// Parameters:
/// value:
/// The array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 16-bit unsigned integer formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">The array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 16-bit unsigned integer formed by two bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static ushort ToUInt16(byte[] value, int startIndex) public static ushort ToUInt16(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -593,32 +334,15 @@ namespace DiscImageChef
: BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex);
} }
///
/// <summary> /// <summary>
/// Returns a 32-bit unsigned integer converted from four bytes at a specified /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 32-bit unsigned integer formed by four bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit unsigned integer formed by four bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static uint ToUInt32(byte[] value, int startIndex) public static uint ToUInt32(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian
@@ -626,32 +350,15 @@ namespace DiscImageChef
: BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex);
} }
///
/// <summary> /// <summary>
/// Returns a 64-bit unsigned integer converted from eight bytes at a specified /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
/// </summary> /// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static ulong ToUInt64(byte[] value, int startIndex) public static ulong ToUInt64(byte[] value, int startIndex)
{ {
return !IsLittleEndian return !IsLittleEndian

9
CHS.cs
View File

@@ -34,6 +34,15 @@ namespace DiscImageChef.Helpers
{ {
public static class CHS public static class CHS
{ {
/// <summary>
/// Converts a CHS position to a LBA one
/// </summary>
/// <param name="cyl">Cylinder</param>
/// <param name="head">Head</param>
/// <param name="sector">Sector</param>
/// <param name="maxHead">Number of heads</param>
/// <param name="maxSector">Number of sectors per track</param>
/// <returns></returns>
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector)
{ {
return maxHead == 0 || maxSector == 0 return maxHead == 0 || maxSector == 0

View File

@@ -34,6 +34,13 @@ namespace DiscImageChef
{ {
public static partial class ArrayHelpers public static partial class ArrayHelpers
{ {
/// <summary>
/// Compares two byte arrays
/// </summary>
/// <param name="different"><c>true</c> if they are different in any way</param>
/// <param name="sameSize"><c>true</c> if they have the same size</param>
/// <param name="compareArray1">Left array</param>
/// <param name="compareArray2">Right array</param>
public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1,
byte[] compareArray2) byte[] compareArray2)
{ {

View File

@@ -34,6 +34,11 @@ namespace DiscImageChef.Helpers
{ {
public static class CountBits public static class CountBits
{ {
/// <summary>
/// Counts the number of bits set to <c>true</c> in a number
/// </summary>
/// <param name="number">Number</param>
/// <returns>Bits set to <c>true</c></returns>
public static int Count(uint number) public static int Count(uint number)
{ {
number = number - ((number >> 1) & 0x55555555); number = number - ((number >> 1) & 0x55555555);

View File

@@ -46,41 +46,82 @@ namespace DiscImageChef
static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0);
static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0); static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
/// <summary>
/// Converts a Macintosh timestamp to a .NET DateTime
/// </summary>
/// <param name="MacTimeStamp">Macintosh timestamp (seconds since 1st Jan. 1904)</param>
/// <returns>.NET DateTime</returns>
public static DateTime MacToDateTime(ulong MacTimeStamp) public static DateTime MacToDateTime(ulong MacTimeStamp)
{ {
return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000)); return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000));
} }
/// <summary>
/// Converts a Lisa timestamp to a .NET DateTime
/// </summary>
/// <param name="LisaTimeStamp">Lisa timestamp (seconds since 1st Jan. 1901)</param>
/// <returns>.NET DateTime</returns>
public static DateTime LisaToDateTime(uint LisaTimeStamp) public static DateTime LisaToDateTime(uint LisaTimeStamp)
{ {
return LisaEpoch.AddSeconds(LisaTimeStamp); return LisaEpoch.AddSeconds(LisaTimeStamp);
} }
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXToDateTime(int UNIXTimeStamp) public static DateTime UNIXToDateTime(int UNIXTimeStamp)
{ {
return UNIXEpoch.AddSeconds(UNIXTimeStamp); return UNIXEpoch.AddSeconds(UNIXTimeStamp);
} }
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXToDateTime(long UNIXTimeStamp) public static DateTime UNIXToDateTime(long UNIXTimeStamp)
{ {
return UNIXEpoch.AddSeconds(UNIXTimeStamp); return UNIXEpoch.AddSeconds(UNIXTimeStamp);
} }
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp)
{ {
return UNIXEpoch.AddSeconds(UNIXTimeStamp); return UNIXEpoch.AddSeconds(UNIXTimeStamp);
} }
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="seconds">Seconds since 1st Jan. 1970)</param>
/// <param name="nanoseconds">Nanoseconds</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds) public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds)
{ {
return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100);
} }
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp) public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp)
{ {
return UNIXEpoch.AddSeconds(UNIXTimeStamp); return UNIXEpoch.AddSeconds(UNIXTimeStamp);
} }
/// <summary>
/// Converts a High Sierra Format timestamp to a .NET DateTime
/// </summary>
/// <param name="VDDateTime">High Sierra Format timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime HighSierraToDateTime(byte[] VDDateTime) public static DateTime HighSierraToDateTime(byte[] VDDateTime)
{ {
byte[] isotime = new byte[17]; byte[] isotime = new byte[17];
@@ -89,6 +130,11 @@ namespace DiscImageChef
} }
// TODO: Timezone // TODO: Timezone
/// <summary>
/// Converts an ISO9660 timestamp to a .NET DateTime
/// </summary>
/// <param name="VDDateTime">ISO9660 timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime ISO9660ToDateTime(byte[] VDDateTime) public static DateTime ISO9660ToDateTime(byte[] VDDateTime)
{ {
int year, month, day, hour, minute, second, hundredths; int year, month, day, hour, minute, second, hundredths;
@@ -155,13 +201,25 @@ namespace DiscImageChef
return decodedDT; return decodedDT;
} }
// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC /// <summary>
/// Converts a VMS timestamp to a .NET DateTime
/// </summary>
/// <param name="vmsDate">VMS timestamp (tenths of microseconds since day 0 of the Julian Date)</param>
/// <returns>.NET DateTime</returns>
/// <remarks>C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC</remarks>
public static DateTime VMSToDateTime(ulong vmsDate) public static DateTime VMSToDateTime(ulong vmsDate)
{ {
double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail
return JulianEpoch.AddMilliseconds(delta); return JulianEpoch.AddMilliseconds(delta);
} }
/// <summary>
/// Converts an Amiga timestamp to a .NET DateTime
/// </summary>
/// <param name="days">Days since the 1st Jan. 1978</param>
/// <param name="minutes">Minutes since o'clock</param>
/// <param name="ticks">Ticks</param>
/// <returns>.NET DateTime</returns>
public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks)
{ {
DateTime temp = AmigaEpoch.AddDays(days); DateTime temp = AmigaEpoch.AddDays(days);
@@ -169,6 +227,11 @@ namespace DiscImageChef
return temp.AddMilliseconds(ticks * 20); return temp.AddMilliseconds(ticks * 20);
} }
/// <summary>
/// Converts an UCSD Pascal timestamp to a .NET DateTime
/// </summary>
/// <param name="dateRecord">UCSD Pascal timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime UCSDPascalToDateTime(short dateRecord) public static DateTime UCSDPascalToDateTime(short dateRecord)
{ {
int year = ((dateRecord & 0xFE00) >> 9) + 1900; int year = ((dateRecord & 0xFE00) >> 9) + 1900;
@@ -181,6 +244,12 @@ namespace DiscImageChef
return new DateTime(year, month, day); return new DateTime(year, month, day);
} }
/// <summary>
/// Converts a DOS timestamp to a .NET DateTime
/// </summary>
/// <param name="date">Date</param>
/// <param name="time">Time</param>
/// <returns>.NET DateTime</returns>
public static DateTime DOSToDateTime(ushort date, ushort time) public static DateTime DOSToDateTime(ushort date, ushort time)
{ {
int year = ((date & 0xFE00) >> 9) + 1980; int year = ((date & 0xFE00) >> 9) + 1980;
@@ -203,6 +272,11 @@ namespace DiscImageChef
return dosdate; return dosdate;
} }
/// <summary>
/// Converts a CP/M timestamp to .NET DateTime
/// </summary>
/// <param name="timestamp">CP/M timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime CPMToDateTime(byte[] timestamp) public static DateTime CPMToDateTime(byte[] timestamp)
{ {
ushort days = BitConverter.ToUInt16(timestamp, 0); ushort days = BitConverter.ToUInt16(timestamp, 0);
@@ -216,11 +290,26 @@ namespace DiscImageChef
return temp; return temp;
} }
// TODO: This is unix
public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp)
{ {
return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp);
} }
/// <summary>
/// Converts an ECMA timestamp to a .NET DateTime
/// </summary>
/// <param name="typeAndTimeZone">Timezone</param>
/// <param name="year">Year</param>
/// <param name="month">Month</param>
/// <param name="day">Day</param>
/// <param name="hour">Hour</param>
/// <param name="minute">Minute</param>
/// <param name="second">Second</param>
/// <param name="centiseconds">Centiseconds</param>
/// <param name="hundredsOfMicroseconds">Hundreds of microseconds</param>
/// <param name="microseconds">Microseconds</param>
/// <returns></returns>
public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour, public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour,
byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds, byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds,
byte microseconds) byte microseconds)
@@ -245,11 +334,21 @@ namespace DiscImageChef
.AddTicks(ticks).DateTime; .AddTicks(ticks).DateTime;
} }
/// <summary>
/// Convers a Solaris high resolution timestamp to .NET DateTime
/// </summary>
/// <param name="HRTimeStamp">Solaris high resolution timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp)
{ {
return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100)); return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100));
} }
/// <summary>
/// Converts an OS-9 timestamp to .NET DateTime
/// </summary>
/// <param name="date">OS-9 timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime OS9ToDateTime(byte[] date) public static DateTime OS9ToDateTime(byte[] date)
{ {
if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue;
@@ -267,6 +366,11 @@ namespace DiscImageChef
return os9date; return os9date;
} }
/// <summary>
/// Converts a LIF timestamp to .NET DateTime
/// </summary>
/// <param name="date">LIF timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime LifToDateTime(byte[] date) public static DateTime LifToDateTime(byte[] date)
{ {
if(date == null || date.Length != 6) return new DateTime(1970, 1, 1, 0, 0, 0); if(date == null || date.Length != 6) return new DateTime(1970, 1, 1, 0, 0, 0);
@@ -274,6 +378,16 @@ namespace DiscImageChef
return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]);
} }
/// <summary>
/// Converts a LIF timestamp to .NET DateTime
/// </summary>
/// <param name="year">Yer</param>
/// <param name="month">Month</param>
/// <param name="day">Day</param>
/// <param name="hour">Hour</param>
/// <param name="minute">Minute</param>
/// <param name="second">Second</param>
/// <returns>.NET DateTime</returns>
public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second) public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second)
{ {
try try

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2018 Natalia Portillo // Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
// TODO: Just remove
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="byte"/>
/// </summary>
public class ExtentsByte public class ExtentsByte
{ {
List<Tuple<byte, byte>> backend; List<Tuple<byte, byte>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsByte() public ExtentsByte()
{ {
backend = new List<Tuple<byte, byte>>(); backend = new List<Tuple<byte, byte>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsByte(IEnumerable<Tuple<byte, byte>> list) public ExtentsByte(IEnumerable<Tuple<byte, byte>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(byte item) public void Add(byte item)
{ {
Tuple<byte, byte> removeOne = null; Tuple<byte, byte> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(byte start, byte end, bool run = false) public void Add(byte start, byte end, bool run = false)
{ {
byte realEnd; byte realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(byte t = start; t <= realEnd; t++) Add(t); for(byte t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(byte item) public bool Contains(byte item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(byte item) public bool Remove(byte item)
{ {
Tuple<byte, byte> toRemove = null; Tuple<byte, byte> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<byte, byte>[] ToArray() public Tuple<byte, byte>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(byte item, out byte start) public bool GetStart(byte item, out byte start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="int"/>
/// </summary>
public class ExtentsInt public class ExtentsInt
{ {
List<Tuple<int, int>> backend; List<Tuple<int, int>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsInt() public ExtentsInt()
{ {
backend = new List<Tuple<int, int>>(); backend = new List<Tuple<int, int>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsInt(IEnumerable<Tuple<int, int>> list) public ExtentsInt(IEnumerable<Tuple<int, int>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(int item) public void Add(int item)
{ {
Tuple<int, int> removeOne = null; Tuple<int, int> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(int start, int end, bool run = false) public void Add(int start, int end, bool run = false)
{ {
int realEnd; int realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(int t = start; t <= realEnd; t++) Add(t); for(int t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(int item) public bool Contains(int item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(int item) public bool Remove(int item)
{ {
Tuple<int, int> toRemove = null; Tuple<int, int> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<int, int>[] ToArray() public Tuple<int, int>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(int item, out int start) public bool GetStart(int item, out int start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="long"/>
/// </summary>
public class ExtentsLong public class ExtentsLong
{ {
List<Tuple<long, long>> backend; List<Tuple<long, long>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsLong() public ExtentsLong()
{ {
backend = new List<Tuple<long, long>>(); backend = new List<Tuple<long, long>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsLong(IEnumerable<Tuple<long, long>> list) public ExtentsLong(IEnumerable<Tuple<long, long>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(long item) public void Add(long item)
{ {
Tuple<long, long> removeOne = null; Tuple<long, long> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(long start, long end, bool run = false) public void Add(long start, long end, bool run = false)
{ {
long realEnd; long realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(long t = start; t <= realEnd; t++) Add(t); for(long t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(long item) public bool Contains(long item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(long item) public bool Remove(long item)
{ {
Tuple<long, long> toRemove = null; Tuple<long, long> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<long, long>[] ToArray() public Tuple<long, long>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(long item, out long start) public bool GetStart(long item, out long start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="sbyte"/>
/// </summary>
public class ExtentsSByte public class ExtentsSByte
{ {
List<Tuple<sbyte, sbyte>> backend; List<Tuple<sbyte, sbyte>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsSByte() public ExtentsSByte()
{ {
backend = new List<Tuple<sbyte, sbyte>>(); backend = new List<Tuple<sbyte, sbyte>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list) public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(sbyte item) public void Add(sbyte item)
{ {
Tuple<sbyte, sbyte> removeOne = null; Tuple<sbyte, sbyte> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(sbyte start, sbyte end, bool run = false) public void Add(sbyte start, sbyte end, bool run = false)
{ {
sbyte realEnd; sbyte realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(sbyte t = start; t <= realEnd; t++) Add(t); for(sbyte t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(sbyte item) public bool Contains(sbyte item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(sbyte item) public bool Remove(sbyte item)
{ {
Tuple<sbyte, sbyte> toRemove = null; Tuple<sbyte, sbyte> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<sbyte, sbyte>[] ToArray() public Tuple<sbyte, sbyte>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(sbyte item, out sbyte start) public bool GetStart(sbyte item, out sbyte start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="short"/>
/// </summary>
public class ExtentsShort public class ExtentsShort
{ {
List<Tuple<short, short>> backend; List<Tuple<short, short>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsShort() public ExtentsShort()
{ {
backend = new List<Tuple<short, short>>(); backend = new List<Tuple<short, short>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsShort(IEnumerable<Tuple<short, short>> list) public ExtentsShort(IEnumerable<Tuple<short, short>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(short item) public void Add(short item)
{ {
Tuple<short, short> removeOne = null; Tuple<short, short> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(short start, short end, bool run = false) public void Add(short start, short end, bool run = false)
{ {
short realEnd; short realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(short t = start; t <= realEnd; t++) Add(t); for(short t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(short item) public bool Contains(short item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(short item) public bool Remove(short item)
{ {
Tuple<short, short> toRemove = null; Tuple<short, short> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<short, short>[] ToArray() public Tuple<short, short>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(short item, out short start) public bool GetStart(short item, out short start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="uint"/>
/// </summary>
public class ExtentsUInt public class ExtentsUInt
{ {
List<Tuple<uint, uint>> backend; List<Tuple<uint, uint>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsUInt() public ExtentsUInt()
{ {
backend = new List<Tuple<uint, uint>>(); backend = new List<Tuple<uint, uint>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list) public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(uint item) public void Add(uint item)
{ {
Tuple<uint, uint> removeOne = null; Tuple<uint, uint> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(uint start, uint end, bool run = false) public void Add(uint start, uint end, bool run = false)
{ {
uint realEnd; uint realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(uint t = start; t <= realEnd; t++) Add(t); for(uint t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(uint item) public bool Contains(uint item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(uint item) public bool Remove(uint item)
{ {
Tuple<uint, uint> toRemove = null; Tuple<uint, uint> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<uint, uint>[] ToArray() public Tuple<uint, uint>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(uint item, out uint start) public bool GetStart(uint item, out uint start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="ulong"/>
/// </summary>
public class ExtentsULong public class ExtentsULong
{ {
List<Tuple<ulong, ulong>> backend; List<Tuple<ulong, ulong>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsULong() public ExtentsULong()
{ {
backend = new List<Tuple<ulong, ulong>>(); backend = new List<Tuple<ulong, ulong>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list) public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(ulong item) public void Add(ulong item)
{ {
Tuple<ulong, ulong> removeOne = null; Tuple<ulong, ulong> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(ulong start, ulong end, bool run = false) public void Add(ulong start, ulong end, bool run = false)
{ {
ulong realEnd; ulong realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(ulong t = start; t <= realEnd; t++) Add(t); for(ulong t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(ulong item) public bool Contains(ulong item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(ulong item) public bool Remove(ulong item)
{ {
Tuple<ulong, ulong> toRemove = null; Tuple<ulong, ulong> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<ulong, ulong>[] ToArray() public Tuple<ulong, ulong>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(ulong item, out ulong start) public bool GetStart(ulong item, out ulong start)
{ {
start = 0; start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents namespace Extents
{ {
/// <summary>
/// Implements extents for <see cref="ushort"/>
/// </summary>
public class ExtentsUShort public class ExtentsUShort
{ {
List<Tuple<ushort, ushort>> backend; List<Tuple<ushort, ushort>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsUShort() public ExtentsUShort()
{ {
backend = new List<Tuple<ushort, ushort>>(); backend = new List<Tuple<ushort, ushort>>();
} }
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list) public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list)
{ {
backend = list.OrderBy(t => t.Item1).ToList(); backend = list.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count; public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(ushort item) public void Add(ushort item)
{ {
Tuple<ushort, ushort> removeOne = null; Tuple<ushort, ushort> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList(); backend = backend.OrderBy(t => t.Item1).ToList();
} }
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(ushort start, ushort end, bool run = false) public void Add(ushort start, ushort end, bool run = false)
{ {
ushort realEnd; ushort realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(ushort t = start; t <= realEnd; t++) Add(t); for(ushort t = start; t <= realEnd; t++) Add(t);
} }
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(ushort item) public bool Contains(ushort item)
{ {
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
} }
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear() public void Clear()
{ {
backend.Clear(); backend.Clear();
} }
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(ushort item) public bool Remove(ushort item)
{ {
Tuple<ushort, ushort> toRemove = null; Tuple<ushort, ushort> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true; return true;
} }
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<ushort, ushort>[] ToArray() public Tuple<ushort, ushort>[] ToArray()
{ {
return backend.ToArray(); return backend.ToArray();
} }
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(ushort item, out ushort start) public bool GetStart(ushort item, out ushort start)
{ {
start = 0; start = 0;

View File

@@ -37,11 +37,22 @@ namespace DiscImageChef
{ {
public static class PrintHex public static class PrintHex
{ {
/// <summary>
/// Prints a byte array as hexadecimal values to the console
/// </summary>
/// <param name="array">Array</param>
/// <param name="width">Width of line</param>
public static void PrintHexArray(byte[] array, int width) public static void PrintHexArray(byte[] array, int width)
{ {
DicConsole.WriteLine(ByteArrayToHexArrayString(array, width)); DicConsole.WriteLine(ByteArrayToHexArrayString(array, width));
} }
/// <summary>
/// Prints a byte array as hexadecimal values to a string
/// </summary>
/// <param name="array">Array</param>
/// <param name="width">Width of line</param>
/// <returns>String containing hexadecimal values</returns>
public static string ByteArrayToHexArrayString(byte[] array, int width) public static string ByteArrayToHexArrayString(byte[] array, int width)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();