AxibugEmuOnline/AxibugEmuOnline.Client.PSVita/Assets/VirtualNes.Core/CoreLibs/ByteArrayRef.cs

67 lines
1.6 KiB
C#
Raw Normal View History

2024-12-08 21:50:52 +08:00
using System;
namespace VirtualNes.Core
{
public class ArrayRef<T>
{
private T[] m_rawArray;
private int m_offset;
private int m_length;
public int Offset
{
get => m_offset;
set
{
var gap = value - m_offset;
m_length -= gap;
}
}
public ArrayRef() { }
public ArrayRef(T[] array, int offset, int length)
{
SetArray(array, offset, length);
}
public ArrayRef(T[] array) : this(array, 0, array.Length) { }
public ArrayRef(T[] array, int offset) : this(array, offset, array.Length - offset) { }
public void SetArray(T[] array, int offset, int length)
{
m_rawArray = array;
m_offset = offset;
m_length = length;
}
public void SetArray(T[] array, int offset)
{
m_rawArray = array;
m_offset = offset;
m_length = array.Length - offset;
}
public T this[int index]
{
get
{
return m_rawArray[m_offset + index];
}
set
{
m_rawArray[(m_offset + index)] = value;
}
}
public static implicit operator ArrayRef<T>(T[] array)
{
return new ArrayRef<T>(array);
}
public static implicit operator Span<T>(ArrayRef<T> array)
{
return new Span<T>(array.m_rawArray, array.Offset, array.m_length);
}
}
}