168 lines
5.8 KiB
C#
168 lines
5.8 KiB
C#
|
|
/*
|
|||
|
|
* DoubleLargeArray.cs
|
|||
|
|
*
|
|||
|
|
* Copyright © 2009
|
|||
|
|
* Diversified Technical Systems, Inc.
|
|||
|
|
* All Rights Reserved
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
using System;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
|
|||
|
|
// ReSharper disable once CheckNamespace
|
|||
|
|
namespace DTS.Common.Utilities.IO.MemoryMap
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// A <see cref="T:IO.MemoryMap.LargeArray" /> of doubles
|
|||
|
|
/// </summary>
|
|||
|
|
public class DoubleLargeArray : LargeArray<double>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Initialize an instance of a <see cref="IO.MemoryMap.DoubleLargeArray"/>.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="size">
|
|||
|
|
/// The <see cref="ulong"/> size of the collection.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
public DoubleLargeArray(ulong size)
|
|||
|
|
: this(size, null, null)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Initialize an instance of a <see cref="IO.MemoryMap.DoubleLargeArray"/>.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="size">
|
|||
|
|
/// The <see cref="ulong"/> size of the collection.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="scratchFileDirectory">
|
|||
|
|
/// The <see cref="string"/> name of the directory where this LargeArray will store the temporary
|
|||
|
|
/// serializations of its items. If null, then the default location will be used.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <param name="scratchFilePrefix">
|
|||
|
|
/// The <see cref="string"/> file name prefix under which this LargeArray will store temporary
|
|||
|
|
/// serializations of its items. Initialized to DefaultFilePrefix's value at object
|
|||
|
|
/// creation, unless an alternate is specified by the user. If null, then the default prefix
|
|||
|
|
/// will be used.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
public DoubleLargeArray(ulong size, string scratchFileDirectory, string scratchFilePrefix)
|
|||
|
|
: base(size, scratchFileDirectory, scratchFilePrefix)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get the <see cref="uint"/> size of the datum handled by this class.
|
|||
|
|
/// </summary>
|
|||
|
|
public override uint DatumSize => sizeof(double);
|
|||
|
|
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get the "zero" value for this class' datum type.
|
|||
|
|
/// </summary>
|
|||
|
|
protected override double DatumClearValue => 0.0;
|
|||
|
|
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get the datum value at the specified index.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="index">
|
|||
|
|
/// The <see cref="T:System.UInt64" /> index of the datum to be returned.
|
|||
|
|
/// </param>
|
|||
|
|
/// <returns>
|
|||
|
|
/// The value of the <see cref="T:System.Double" /> datum at the specified index.
|
|||
|
|
/// </returns>
|
|||
|
|
protected override double GetDatumAtIndex(ulong index)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (index > long.MaxValue)
|
|||
|
|
throw new ApplicationException("overflowed an Int64 variable with a UInt64 value");
|
|||
|
|
var bytes = new byte[DatumSize];
|
|||
|
|
for (var i = 0; i < DatumSize; i++)
|
|||
|
|
bytes[i] = ViewArray[(long)(DatumSize * index) + i];
|
|||
|
|
return BitConverter.ToDouble(bytes, 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception("encountered problem getting datum at index " + index, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
/// <summary>
|
|||
|
|
/// Set the datum value at the specified index.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="datum">
|
|||
|
|
/// The <see cref="T:System.Double" /> datum to be written to the specified index.
|
|||
|
|
/// </param>
|
|||
|
|
/// <param name="index">
|
|||
|
|
/// The <see cref="T:System.UInt64" /> index at which the specified datum value will be written.
|
|||
|
|
/// </param>
|
|||
|
|
protected override void SetDatumAtIndex(double datum, ulong index)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (index > long.MaxValue)
|
|||
|
|
throw new ApplicationException("overflowed an Int64 variable with a UInt64 value");
|
|||
|
|
var bytes = BitConverter.GetBytes(datum);
|
|||
|
|
Debug.Assert(bytes.Length == DatumSize);
|
|||
|
|
for (var i = 0; i < DatumSize; i++)
|
|||
|
|
ViewArray[(long)(DatumSize * index) + i] = bytes[i];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception("encountered problem setting datum (" + datum + ") at index " + index, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <inheritdoc />
|
|||
|
|
/// <summary>
|
|||
|
|
/// Creates a new object that is a copy of the current instance.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns>
|
|||
|
|
/// A new <see cref="T:System.Object" /> that is a copy of the current instance.
|
|||
|
|
/// </returns>
|
|||
|
|
public override object Clone()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var clone = new DoubleLargeArray(Size);
|
|||
|
|
for (var i = 0UL; i < clone.LargeCount; i++)
|
|||
|
|
clone[i] = this[i];
|
|||
|
|
return clone;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception("encountered problem cloning " + GetType().FullName, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get/set the value at the specified index.
|
|||
|
|
/// </summary>
|
|||
|
|
///
|
|||
|
|
/// <param name="index">
|
|||
|
|
/// The <see cref="ulong"/> index of the datum to be referenced.
|
|||
|
|
/// </param>
|
|||
|
|
///
|
|||
|
|
/// <returns>
|
|||
|
|
/// The <see cref="double"/> value of the datum at the specified index.
|
|||
|
|
/// </returns>
|
|||
|
|
///
|
|||
|
|
public new double this[ulong index]
|
|||
|
|
{
|
|||
|
|
get => (short)base[index];
|
|||
|
|
|
|||
|
|
set => base[index] = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|