1st Aura Project Layout
This commit is contained in:
+18
-40
@@ -13,7 +13,6 @@ type
|
||||
private
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
end;
|
||||
|
||||
TMycMutableBase<T> = class(TInterfacedObject, TMutable<T>.IMutable)
|
||||
@@ -21,7 +20,6 @@ type
|
||||
FChanged: TEvent;
|
||||
FChangeState: TSignal.TSubscription;
|
||||
function GetChanged: TSignal;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
protected
|
||||
function GetValue: T; virtual; abstract;
|
||||
public
|
||||
@@ -38,14 +36,13 @@ type
|
||||
constructor Create(const AChanged: TSignal; const AProc: TFunc<T>);
|
||||
end;
|
||||
|
||||
TMycWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TMutable<T>.IWriter)
|
||||
TMycWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TWriteable<T>.IWriteable)
|
||||
private
|
||||
FValue: T;
|
||||
FChanged: TEvent;
|
||||
protected
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
function Exchange(const Value: T): T;
|
||||
public
|
||||
constructor Create(const AValue: T);
|
||||
@@ -81,24 +78,26 @@ type
|
||||
constructor Create(const AChanged: TSignal.ISignal; const AProc: TFunc<T>);
|
||||
end;
|
||||
|
||||
TMycProtectedMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TMutable<T>.IWriter)
|
||||
TMycProtectedMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TWriteable<T>.IWriteable)
|
||||
private
|
||||
FMutable: TMutable<T>.IMutable;
|
||||
FWriteable: TWriteable<T>.IWriteable;
|
||||
FLock: Integer;
|
||||
protected
|
||||
function Exchange(const Value: T): T;
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
procedure Lock; inline;
|
||||
procedure Release; inline;
|
||||
public
|
||||
constructor Create(const AMutable: TMutable<T>.IMutable);
|
||||
constructor Create(const AWriteable: TWriteable<T>.IWriteable);
|
||||
procedure SetValue(const Value: T);
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.Generics.Defaults;
|
||||
|
||||
{ TMycNullMutable<T> }
|
||||
|
||||
function TMycNullMutable<T>.GetChanged: TSignal;
|
||||
@@ -111,11 +110,6 @@ begin
|
||||
Result := Default(T);
|
||||
end;
|
||||
|
||||
function TMycNullMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{ TMycMutableBase<T> }
|
||||
|
||||
constructor TMycMutableBase<T>.Create(const AChanged: TSignal);
|
||||
@@ -136,11 +130,6 @@ begin
|
||||
Result := FChanged.Signal;
|
||||
end;
|
||||
|
||||
function TMycMutableBase<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{ TMycWriteableMutable<T> }
|
||||
|
||||
constructor TMycWriteableMutable<T>.Create(const AValue: T);
|
||||
@@ -166,15 +155,13 @@ begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
function TMycWriteableMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
procedure TMycWriteableMutable<T>.SetValue(const Value: T);
|
||||
begin
|
||||
FValue := Value;
|
||||
FChanged.Notify;
|
||||
if not TEqualityComparer<T>.Default.Equals(FValue, Value) then
|
||||
begin
|
||||
FValue := Value;
|
||||
FChanged.Notify;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TMycNullLazy<T> }
|
||||
@@ -248,18 +235,17 @@ end;
|
||||
|
||||
{ TMycProtectedMutable<T> }
|
||||
|
||||
constructor TMycProtectedMutable<T>.Create(const AMutable: TMutable<T>.IMutable);
|
||||
constructor TMycProtectedMutable<T>.Create(const AWriteable: TWriteable<T>.IWriteable);
|
||||
begin
|
||||
inherited Create;
|
||||
FMutable := AMutable;
|
||||
FWriteable := AWriteable;
|
||||
end;
|
||||
|
||||
function TMycProtectedMutable<T>.Exchange(const Value: T): T;
|
||||
begin
|
||||
Lock;
|
||||
try
|
||||
Assert(FMutable.Writer <> nil);
|
||||
Result := FMutable.Writer.Exchange(Value);
|
||||
Result := FWriteable.Exchange(Value);
|
||||
finally
|
||||
Release;
|
||||
end;
|
||||
@@ -267,26 +253,19 @@ end;
|
||||
|
||||
function TMycProtectedMutable<T>.GetChanged: TSignal;
|
||||
begin
|
||||
Result := FMutable.Changed;
|
||||
Result := FWriteable.Changed;
|
||||
end;
|
||||
|
||||
function TMycProtectedMutable<T>.GetValue: T;
|
||||
begin
|
||||
Lock;
|
||||
try
|
||||
Result := FMutable.Value;
|
||||
Result := FWriteable.Value;
|
||||
finally
|
||||
Release;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMycProtectedMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := nil;
|
||||
if FMutable.Writer <> nil then
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
procedure TMycProtectedMutable<T>.Lock;
|
||||
begin
|
||||
while AtomicExchange(FLock, 1) = 1 do
|
||||
@@ -302,8 +281,7 @@ procedure TMycProtectedMutable<T>.SetValue(const Value: T);
|
||||
begin
|
||||
Lock;
|
||||
try
|
||||
Assert(FMutable.Writer <> nil);
|
||||
FMutable.Writer.SetValue(Value);
|
||||
FWriteable.SetValue(Value);
|
||||
finally
|
||||
Release;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user