daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+56 -75
View File
@@ -1,80 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Counter.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
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;
internal readonly T _defualtAddValue;
internal readonly T _defualtSubValue;
internal readonly T _defualtValue;
internal dynamic _value;
public T Value
{
get { return _value; }
set { _value = value; }
}
public T Span
{
get { return _value - _defualtValue; }
}
public T Increament
{
get { return _defualtAddValue; }
}
public T Decreament
{
get { return _defualtSubValue; }
}
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
{
var type = Type.GetTypeCode(defualtValue.GetType());
@@ -120,6 +88,18 @@ namespace StgSharp
_defualtSubValue = defualtSubValue;
}
public T Decreament => _defualtSubValue;
public T Increament => _defualtAddValue;
public T Span => _value - _defualtValue;
public T Value
{
get => _value;
set => _value = value;
}
public void Add(T value)
{
_value += value;
@@ -130,11 +110,6 @@ namespace StgSharp
_value += _defualtAddValue;
}
public void Sub(T value)
{
_value -= value;
}
public void QuickSub()
{
_value -= _defualtSubValue;
@@ -145,10 +120,14 @@ namespace StgSharp
_value = _defualtValue;
}
public static Counter<T> operator ++(Counter<T> counter)
public void Sub(T value)
{
counter.QuickAdd();
return counter;
_value -= value;
}
public override string ToString()
{
return Value.ToString();
}
public static Counter<T> operator --(Counter<T> counter)
@@ -157,14 +136,16 @@ namespace StgSharp
return counter;
}
public override string ToString()
public static Counter<T> operator ++(Counter<T> counter)
{
return Value.ToString();
counter.QuickAdd();
return counter;
}
public static implicit operator T(Counter<T> counter)
{
return counter.Value;
}
}
}