1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-26 13:16:02 +00:00
Ryujinx/ARMeilleure/Common/Counter.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2021-04-09 17:52:28 +01:00
namespace ARMeilleure.Common
{
/// <summary>
/// Represents an 8-bit counter.
/// </summary>
class Counter
{
private readonly int _index;
private readonly EntryTable<byte> _countTable;
/// <summary>
/// Initializes a new instance of the <see cref="Counter"/> class from the specified
/// <see cref="EntryTable{byte}"/> instance and index.
/// </summary>
/// <param name="countTable"><see cref="EntryTable{byte}"/> instance</param>
/// <param name="index">Index in the <see cref="EntryTable{TEntry}"/></param>
private Counter(EntryTable<byte> countTable, int index)
{
_countTable = countTable;
_index = index;
}
/// <summary>
/// Gets a reference to the value of the counter.
/// </summary>
public ref byte Value => ref _countTable.GetValue(_index);
/// <summary>
/// Tries to create a <see cref="Counter"/> instance from the specified <see cref="EntryTable{byte}"/> instance.
/// </summary>
/// <param name="countTable"><see cref="EntryTable{TEntry}"/> from which to create the <see cref="Counter"/></param>
/// <param name="counter"><see cref="Counter"/> instance if success; otherwise <see langword="null"/></param>
/// <returns><see langword="true"/> if success; otherwise <see langword="false"/></returns>
public static bool TryCreate(EntryTable<byte> countTable, out Counter counter)
{
if (countTable.TryAllocate(out int index))
{
counter = new Counter(countTable, index);
return true;
}
counter = null;
return false;
}
}
}