using Qrakhen.Qamp.Core.Collections.Abstractions;
namespace Qrakhen.Qamp.Core.Collections;
///
/// Dynamic Pointer able to point to any object implementing the interface.
///
public class Pointer
{
protected IGetSet Target;
public long Cursor;
public T Current {
get => Get();
set => Set(value);
}
public Pointer(IGetSet target, long pointer = 0)
{
Target = target;
Cursor = pointer;
}
public Pointer Branch(long delta = 0)
{
return new Pointer(Target, Cursor + delta);
}
///
/// Returns the next item from and increases the pointer by 1.
///
public T Next() => Target.Get(Cursor++);
///
/// Sets the value of RELATIVE from the current position ().
///
public void Set(long delta, T value) => Target.Set(Cursor + delta, value);
///
/// Sets the value of at the current location.
///
public void Set(T value) => Set(Cursor, value);
///
/// Gets the value of RELATIVE from the current position ().
///
public T Get(long delta) => Target.Get(Cursor + delta);
///
/// Gets the value of at the current location.
///
public T Get() => Get(Cursor);
public override string ToString()
{
return $"&{Cursor:X4}={Current}";
}
}