namespace ARMeilleure.Common
{
///
/// Represents an 8-bit counter.
///
class Counter
{
private readonly int _index;
private readonly EntryTable _countTable;
///
/// Initializes a new instance of the class from the specified
/// instance and index.
///
/// instance
/// Index in the
private Counter(EntryTable countTable, int index)
{
_countTable = countTable;
_index = index;
}
///
/// Gets a reference to the value of the counter.
///
public ref byte Value => ref _countTable.GetValue(_index);
///
/// Tries to create a instance from the specified instance.
///
/// from which to create the
/// instance if success; otherwise
/// if success; otherwise
public static bool TryCreate(EntryTable countTable, out Counter counter)
{
if (countTable.TryAllocate(out int index))
{
counter = new Counter(countTable, index);
return true;
}
counter = null;
return false;
}
}
}