daily update on 20240315 by nitload youmu
This commit is contained in:
@@ -1,7 +1,51 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public delegate void TimeSourceProvider(TimeProvider subscriber);
|
||||
|
||||
public class TimeProvider
|
||||
{
|
||||
private readonly long _spanLength;
|
||||
private long _spanBegin;
|
||||
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
|
||||
|
||||
public static TimeSourceProvider DefaultProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
return new(StgSharp.SubscribeTimeProvider);
|
||||
}
|
||||
}
|
||||
|
||||
public TimeProvider(
|
||||
long spanLength
|
||||
)
|
||||
{
|
||||
_spanLength = spanLength;
|
||||
}
|
||||
|
||||
internal void CheckTime(long microseconds)
|
||||
{
|
||||
if (microseconds - _spanBegin > _spanLength)
|
||||
{
|
||||
_spanBegin = microseconds;
|
||||
timeSpanCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public void SubcsribeToTimeSource(TimeSourceProvider serviceHandler)
|
||||
{
|
||||
serviceHandler(this);
|
||||
}
|
||||
|
||||
public static implicit operator uint(TimeProvider provider)
|
||||
{
|
||||
return provider.timeSpanCount.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
|
||||
{
|
||||
internal readonly T _defualtValue;
|
||||
@@ -38,24 +82,34 @@ namespace StgSharp
|
||||
{
|
||||
case TypeCode.Byte:
|
||||
break;
|
||||
|
||||
case TypeCode.Int16:
|
||||
break;
|
||||
|
||||
case TypeCode.Int32:
|
||||
break;
|
||||
|
||||
case TypeCode.Int64:
|
||||
break;
|
||||
|
||||
case TypeCode.Double:
|
||||
break;
|
||||
|
||||
case TypeCode.Single:
|
||||
break;
|
||||
|
||||
case TypeCode.SByte:
|
||||
break;
|
||||
|
||||
case TypeCode.UInt16:
|
||||
break;
|
||||
|
||||
case TypeCode.UInt32:
|
||||
break;
|
||||
|
||||
case TypeCode.UInt64:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentException("Input is not number value type");
|
||||
break;
|
||||
@@ -66,7 +120,6 @@ namespace StgSharp
|
||||
_defualtSubValue = defualtSubValue;
|
||||
}
|
||||
|
||||
|
||||
public void Add(T value)
|
||||
{
|
||||
_value += value;
|
||||
@@ -113,6 +166,5 @@ namespace StgSharp
|
||||
{
|
||||
return counter.Value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user