/* * ShortLargeArray.cs * * Copyright © 2009 * Diversified Technical Systems, Inc. * All Rights Reserved */ using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Text; using DTS.Common.Utilities; using DTS.Common.Utilities.DotNetProgrammingConstructs; namespace DTS.Common.Utilities.IO.MemoryMap { /// /// a of /// /// public class ShortLargeArray : LargeArray { /// /// Initialize an instance of a . /// /// /// /// The size of the collection. /// public ShortLargeArray(ulong size) : this(size, null, null) { } /// /// Initialize an instance of a . /// /// /// /// The size of the collection. /// /// /// /// The name of the directory where this LargeArray will store the temporary /// serializations of its items. If null, then the default location will be used. /// /// /// /// The 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. /// /// public ShortLargeArray(ulong size, string scratchFileDirectory, string scratchFilePrefix) : base(size, scratchFileDirectory, scratchFilePrefix) { } /// /// Get the size of the datum handled by this class. /// public override uint DatumSize => sizeof(short); /// /// Get the "zero" value for this class' datum type. /// protected override short DatumClearValue => 0; /// /// Get the datum value at the specified index. /// /// /// /// The index of the datum to be returned. /// /// /// /// The value of the datum at the specified index. /// /// protected override short GetDatumAtIndex(ulong index) { try { short rv; if (index > long.MaxValue) throw new ApplicationException("overflowed an Int64 variable with a UInt64 value"); rv = (short)(ViewArray[(long)((2 * index))] & 0xFFFF); rv += (short)((ViewArray[(long)((2 * index) + 1)] & 0xFFFF) << 8); return rv; } catch (System.Exception ex) { throw new ShortLargeArray.Exception("encountered problem getting datum at index " + index.ToString(), ex); } } /// /// Set the datum value at the specified index. /// /// /// /// The datum to be written to the specified index. /// /// /// /// The index at which the specified datum value will be written. /// /// protected override void SetDatumAtIndex(short datum, ulong index) { try { if (index > long.MaxValue) throw new ApplicationException("overflowed an Int64 variable with a UInt64 value"); (ViewArray[(long)((2 * index))]) = (byte)((datum) & 0xFFFF); (ViewArray[(long)((2 * index) + 1)]) = (byte)((datum >> 8) & 0xFFFF); } catch (System.Exception ex) { throw new ShortLargeArray.Exception("encountered problem setting datum (" + datum.ToString() + ") at index " + index.ToString(), ex); } } /// /// Creates a new object that is a copy of the current instance. /// /// /// /// A new that is a copy of the current instance. /// /// public override object Clone() { try { var clone = new ShortLargeArray(Size); for (ulong i = 0; i < clone.LargeCount; i++) clone[i] = this[i]; return clone; } catch (System.Exception ex) { throw new Exception("encountered problem cloning " + GetType().FullName, ex); } } /// /// Get/set the value at the specified index. /// /// /// /// The index of the datum to be referenced. /// /// /// /// The value of the datum at the specified index. /// /// public new short this[ulong index] { get => base[index]; set => base[index] = value; } } }