2025-08-19 07:27:39 -04:00
|
|
|
using System.IO;
|
|
|
|
|
|
2026-03-18 16:37:59 -04:00
|
|
|
namespace SabreTools.Wrappers
|
2025-08-19 07:27:39 -04:00
|
|
|
{
|
2025-11-11 09:57:38 -05:00
|
|
|
public abstract class WrapperBase<TModel> : WrapperBase, IWrapper<TModel>
|
2025-08-19 07:27:39 -04:00
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2025-11-11 09:57:38 -05:00
|
|
|
public TModel GetModel() => Model;
|
2025-08-19 07:27:39 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Internal model
|
|
|
|
|
/// </summary>
|
2025-11-11 09:57:38 -05:00
|
|
|
public TModel Model { get; }
|
2025-08-19 07:27:39 -04:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2025-09-16 21:54:26 -04:00
|
|
|
#region Byte Array Constructors
|
2025-08-19 07:27:39 -04:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a byte array
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, byte[] data)
|
2025-09-16 21:54:26 -04:00
|
|
|
: this(model, data, 0, data.Length)
|
2025-08-19 07:27:39 -04:00
|
|
|
{
|
2025-09-16 21:54:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a byte array
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
|
|
|
|
/// <param name="offset">Offset into the data to use as the window start</param>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, byte[] data, int offset)
|
2025-09-16 21:54:26 -04:00
|
|
|
: this(model, data, offset, data.Length - offset)
|
|
|
|
|
{
|
|
|
|
|
}
|
2025-08-19 07:27:39 -04:00
|
|
|
|
2025-09-16 21:54:26 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a byte array
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
|
|
|
|
/// <param name="offset">Offset into the data to use as the window start</param>
|
|
|
|
|
/// <param name="length">Length of the window into the data</param>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, byte[] data, int offset, int length)
|
2025-09-16 21:54:26 -04:00
|
|
|
: base(data, offset, length)
|
|
|
|
|
{
|
2025-08-19 07:27:39 -04:00
|
|
|
Model = model;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 21:54:26 -04:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Stream Constructors
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a Stream
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
2025-09-16 21:54:26 -04:00
|
|
|
/// <remarks>Uses the current stream position as the offset</remarks>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, Stream data)
|
2025-09-16 21:54:26 -04:00
|
|
|
: this(model, data, data.Position, data.Length - data.Position)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 07:27:39 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a Stream
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
|
|
|
|
/// <param name="offset">Offset into the data to use as the window start</param>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, Stream data, long offset)
|
2025-09-16 21:54:26 -04:00
|
|
|
: this(model, data, offset, data.Length - offset)
|
2025-08-19 07:27:39 -04:00
|
|
|
{
|
2025-09-16 21:54:26 -04:00
|
|
|
}
|
2025-08-19 07:27:39 -04:00
|
|
|
|
2025-09-16 21:54:26 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new instance of the wrapper from a Stream
|
|
|
|
|
/// </summary>
|
2025-09-16 22:07:05 -04:00
|
|
|
/// <param name="model">Model to be used in the wrapper</param>
|
|
|
|
|
/// <param name="data">Underlying data for the wrapper</param>
|
|
|
|
|
/// <param name="offset">Offset into the data to use as the window start</param>
|
|
|
|
|
/// <param name="length">Length of the window into the data</param>
|
2025-11-11 09:57:38 -05:00
|
|
|
protected WrapperBase(TModel model, Stream data, long offset, long length)
|
2025-09-16 21:54:26 -04:00
|
|
|
: base(data, offset, length)
|
|
|
|
|
{
|
2025-08-19 07:27:39 -04:00
|
|
|
Model = model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|