using System;
namespace MatFileHandler
{
///
/// A better interface for using duration objects.
///
public class DurationAdapter
{
private readonly double[] data;
///
/// Initializes a new instance of the class.
///
/// Source duration object.
public DurationAdapter(IArray array)
{
var matObject = array as IMatObject;
if (matObject?.ClassName != "duration")
{
throw new ArgumentException("The object provided is not a duration.");
}
var dataObject = matObject["millis", 0];
data = dataObject.ConvertToDoubleArray()
?? throw new HandlerException("Cannot extract data for the duration adapter.");
Dimensions = dataObject.Dimensions;
}
///
/// Gets duration array dimensions.
///
public int[] Dimensions { get; }
///
/// Gets duration object at given position.
///
/// Indices.
/// Value.
public TimeSpan this[params int[] list] => TimeSpan.FromTicks((long)(10000.0 * data[Dimensions.DimFlatten(list)]));
}
}