Immutability and strip the / off the path
x) Better path substring x) Add some interfaces for immutability
This commit is contained in:
parent
8879e98229
commit
bea7080a5c
12
imm/FSM.cs
12
imm/FSM.cs
@ -10,15 +10,17 @@ namespace imm;
|
||||
|
||||
|
||||
|
||||
public record class Context : imm.Recorded<Context>
|
||||
public record class Context : imm.Recorded<Context>, Imm
|
||||
{
|
||||
|
||||
Meta Imm.Meta => base.Meta;
|
||||
}
|
||||
|
||||
public record class State<TSUB, CTX>( CTX Context ) : imm.Recorded<TSUB>
|
||||
public record class State<TSUB, CTX>( CTX Context ) : imm.Recorded<TSUB>, Imm
|
||||
where TSUB : State<TSUB, CTX>
|
||||
where CTX : Context
|
||||
{
|
||||
Meta Imm.Meta => base.Meta;
|
||||
|
||||
virtual public (CTX, TSUB) onEnter(CTX ctx, State<TSUB, CTX> oldState)
|
||||
{
|
||||
return (ctx, (TSUB)this);
|
||||
@ -32,11 +34,13 @@ public record class State<TSUB, CTX>( CTX Context ) : imm.Recorded<TSUB>
|
||||
|
||||
|
||||
|
||||
public record class FSM<TSUB, ST, CTX> : imm.Recorded<TSUB>
|
||||
public record class FSM<TSUB, ST, CTX> : imm.Recorded<TSUB>, Imm
|
||||
where TSUB : FSM<TSUB, ST, CTX>
|
||||
where ST : State<ST, CTX>
|
||||
where CTX : Context
|
||||
{
|
||||
Meta Imm.Meta => base.Meta;
|
||||
|
||||
public CTX Context { get; init; }
|
||||
public ST State { get; init; }
|
||||
|
||||
|
||||
25
imm/Imm.cs
25
imm/Imm.cs
@ -49,13 +49,32 @@ static public class Util
|
||||
}
|
||||
}
|
||||
|
||||
public interface Meta
|
||||
{
|
||||
public uint Version => 0;
|
||||
public string Reason => "";
|
||||
public string Expression => "";
|
||||
public string MemberName => "";
|
||||
public string FilePath => "";
|
||||
public int LineNumber => -1;
|
||||
public DateTime CreatedAt => DateTime.MinValue;
|
||||
public DateTime TouchedAt => DateTime.MinValue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public interface Imm
|
||||
{
|
||||
public Meta Meta { get; }
|
||||
}
|
||||
|
||||
//[lib.Ser( Types = lib.Types.None )]
|
||||
public record class Versioned<T>
|
||||
public record class Versioned<T> : Imm
|
||||
where T : Versioned<T>
|
||||
{
|
||||
public delegate void ChangeDelegate( T ZZOld, T next );
|
||||
|
||||
public record class MetaData
|
||||
public record class MetaData : Meta
|
||||
{
|
||||
public uint Version { get; internal set; } = 0;
|
||||
public string Reason { get; internal set; } = "";
|
||||
@ -78,6 +97,8 @@ public record class Versioned<T>
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public MetaData Meta => MetaStorage;
|
||||
|
||||
Meta Imm.Meta => MetaStorage;
|
||||
|
||||
[lib.Dont]
|
||||
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public ChangeDelegate OnChange = (x, y) => {};
|
||||
|
||||
@ -21,7 +21,7 @@ static public class iu
|
||||
[CallerLineNumber] int lineNumber = 0,
|
||||
[CallerArgumentExpression("fn")]
|
||||
string expression = default )
|
||||
where T : Recorded<T>
|
||||
where T : Recorded<T>, Imm
|
||||
{
|
||||
obj = obj.Process( fn, reason, memberName, filePath, lineNumber, expression );
|
||||
return obj;
|
||||
@ -34,7 +34,7 @@ static public class iu
|
||||
[CallerLineNumber] int lineNumber = 0,
|
||||
[CallerArgumentExpression("fn")]
|
||||
string expression = default )
|
||||
where T : Recorded<T>
|
||||
where T : Recorded<T>, Imm
|
||||
{
|
||||
obj = obj.Process( fn, reason, memberName, filePath, lineNumber, expression );
|
||||
return obj;
|
||||
@ -48,7 +48,7 @@ static public class iu
|
||||
[CallerLineNumber] int lineNumber = 0,
|
||||
[CallerArgumentExpression("fn")]
|
||||
string expression = default )
|
||||
where T : Versioned<T>
|
||||
where T : Versioned<T>, Imm
|
||||
{
|
||||
obj = obj.Process( fn, reason );
|
||||
return obj;
|
||||
|
||||
@ -176,11 +176,16 @@ static public class log
|
||||
{
|
||||
var cwd = Directory.GetCurrentDirectory();
|
||||
|
||||
var rel = fullPath.Substring( cwd.Length );
|
||||
var rel = fullPath.Substring( cwd.Length + 1 );
|
||||
|
||||
return rel;
|
||||
}
|
||||
|
||||
static public string thisFilePath( [CallerFilePath] string path = "" )
|
||||
{
|
||||
return relativePath( path );
|
||||
}
|
||||
|
||||
// Forwards.
|
||||
static public void fatal( string msg, string cat = "", object obj = null, [CallerFilePath] string path = "", [CallerLineNumber] int line = -1, [CallerMemberName] string member = "" )
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user