using System;

namespace Decal.Filters;

public abstract class RawTable<EntryType>
{
	private int mCount;

	private EntryType[] mTable;

	public EntryType this[int index]
	{
		get
		{
			if (index >= 0 && index < mCount)
			{
				return mTable[index];
			}
			return default(EntryType);
		}
		protected set
		{
			if (index >= 0 && index < mCount)
			{
				mTable[index] = value;
			}
		}
	}

	public int Length => mCount;

	public event EventHandler Update;

	internal abstract bool LoadFrom(byte[] Data);

	internal bool UpdateFrom(byte[] Data)
	{
		bool num = LoadFrom(Data);
		if (num)
		{
			this.Update(this, null);
		}
		return num;
	}

	protected void InitializeTable(int n)
	{
		mCount = 0;
		mTable = (EntryType[])Array.CreateInstance(typeof(EntryType), n);
	}

	protected void Add(EntryType entry)
	{
		if (mCount < mTable.Length)
		{
			mTable[mCount++] = entry;
		}
	}
}
