36 lines
921 B
C#
36 lines
921 B
C#
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
|
|
|
namespace Qrakhen.Qamp.Core.Execution;
|
|
|
|
public class Instructions<T>(IEnumerable<T> instructions) :
|
|
ISteppable<T>,
|
|
IPeekable<T>,
|
|
ISeekable<long, T>
|
|
{
|
|
private readonly T[] _instructions = instructions.ToArray();
|
|
|
|
public long Position { get; private set; } = 0;
|
|
|
|
public long Length => _instructions.LongLength;
|
|
public bool Done => Position >= _instructions.Length;
|
|
|
|
public T this[long offset] => offset < Length ?
|
|
_instructions[offset] :
|
|
throw new ArgumentOutOfRangeException($"Tried to access offset beyond instruction length {offset}:{Length}");
|
|
|
|
public T Seek(long position)
|
|
{
|
|
Position = position;
|
|
return _instructions[Position];
|
|
}
|
|
|
|
public T Next()
|
|
{
|
|
return _instructions[Position++];
|
|
}
|
|
|
|
public T Peek(int delta = 0)
|
|
{
|
|
return _instructions[Position + delta];
|
|
}
|
|
} |