1st Aura Project Layout
This commit is contained in:
+72
-36
@@ -9,20 +9,13 @@ uses
|
||||
type
|
||||
TMutable<T> = record
|
||||
type
|
||||
IWriter = interface
|
||||
procedure SetValue(const Value: T);
|
||||
function Exchange(const Value: T): T;
|
||||
end;
|
||||
|
||||
IMutable = interface
|
||||
{$REGION 'property access'}
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: IWriter;
|
||||
{$ENDREGION}
|
||||
property Changed: TSignal read GetChanged;
|
||||
property Value: T read GetValue;
|
||||
property Writer: IWriter read GetWriter;
|
||||
end;
|
||||
|
||||
{$REGION 'private'}
|
||||
@@ -34,9 +27,7 @@ type
|
||||
private
|
||||
FMutable: IMutable;
|
||||
function GetChanged: TSignal; inline;
|
||||
function GetIsWriteable: Boolean;
|
||||
function GetValue: T; inline;
|
||||
procedure SetValue(const Value: T);
|
||||
{$ENDREGION}
|
||||
public
|
||||
constructor Create(const AMutable: IMutable);
|
||||
@@ -47,13 +38,36 @@ type
|
||||
class property Null: IMutable read FNull;
|
||||
|
||||
class function Construct(const Changing: TSignal; const Proc: TFunc<T>): TMutable<T>; overload; static;
|
||||
class function CreateWriteable: TMutable<T>; overload; static;
|
||||
|
||||
function Protect: TMutable<T>;
|
||||
property Value: T read GetValue;
|
||||
property Changed: TSignal read GetChanged;
|
||||
end;
|
||||
|
||||
TWriteable<T> = record
|
||||
type
|
||||
IWriteable = interface(TMutable<T>.IMutable)
|
||||
procedure SetValue(const Value: T);
|
||||
function Exchange(const Value: T): T;
|
||||
end;
|
||||
|
||||
{$REGION 'private'}
|
||||
private
|
||||
FWriteable: IWriteable;
|
||||
function GetChanged: TSignal; inline;
|
||||
function GetValue: T; inline;
|
||||
procedure SetValue(const Value: T);
|
||||
{$ENDREGION}
|
||||
public
|
||||
constructor Create(const AWriteable: IWriteable);
|
||||
class operator Implicit(const A: IWriteable): TWriteable<T>; overload;
|
||||
class operator Implicit(const A: TWriteable<T>): IWriteable; overload;
|
||||
|
||||
class function CreateWriteable: TWriteable<T>; overload; static;
|
||||
|
||||
function Protect: TWriteable<T>;
|
||||
|
||||
property Value: T read GetValue write SetValue;
|
||||
property Changed: TSignal read GetChanged;
|
||||
property IsWriteable: Boolean read GetIsWriteable;
|
||||
end;
|
||||
|
||||
TLazy<T> = record
|
||||
@@ -114,40 +128,16 @@ begin
|
||||
Result := TMycFuncMutable<T>.Create(Changing, Proc);
|
||||
end;
|
||||
|
||||
class function TMutable<T>.CreateWriteable: TMutable<T>;
|
||||
begin
|
||||
Result := TMycWriteableMutable<T>.Create(Default(T));
|
||||
end;
|
||||
|
||||
function TMutable<T>.GetChanged: TSignal;
|
||||
begin
|
||||
Result := FMutable.Changed;
|
||||
end;
|
||||
|
||||
function TMutable<T>.GetIsWriteable: Boolean;
|
||||
begin
|
||||
Result := Assigned(FMutable.Writer);
|
||||
end;
|
||||
|
||||
function TMutable<T>.GetValue: T;
|
||||
begin
|
||||
Result := FMutable.Value;
|
||||
end;
|
||||
|
||||
function TMutable<T>.Protect: TMutable<T>;
|
||||
begin
|
||||
if not (FMutable is TMycProtectedMutable<T>) then
|
||||
Result := TMycProtectedMutable<T>.Create(FMutable)
|
||||
else
|
||||
Result := FMutable;
|
||||
end;
|
||||
|
||||
procedure TMutable<T>.SetValue(const Value: T);
|
||||
begin
|
||||
Assert(IsWriteable);
|
||||
FMutable.Writer.SetValue(Value);
|
||||
end;
|
||||
|
||||
class operator TMutable<T>.Implicit(const A: TMutable<T>): IMutable;
|
||||
begin
|
||||
Result := A.FMutable;
|
||||
@@ -212,4 +202,50 @@ begin
|
||||
Dest.FLazy := FNull;
|
||||
end;
|
||||
|
||||
{ TWriteable<T> }
|
||||
|
||||
constructor TWriteable<T>.Create(const AWriteable: IWriteable);
|
||||
begin
|
||||
FWriteable := AWriteable;
|
||||
Assert(Assigned(FWriteable));
|
||||
end;
|
||||
|
||||
class function TWriteable<T>.CreateWriteable: TWriteable<T>;
|
||||
begin
|
||||
Result := TMycWriteableMutable<T>.Create(Default(T));
|
||||
end;
|
||||
|
||||
function TWriteable<T>.GetChanged: TSignal;
|
||||
begin
|
||||
Result := FWriteable.Changed;
|
||||
end;
|
||||
|
||||
function TWriteable<T>.GetValue: T;
|
||||
begin
|
||||
Result := FWriteable.Value;
|
||||
end;
|
||||
|
||||
function TWriteable<T>.Protect: TWriteable<T>;
|
||||
begin
|
||||
if not (FWriteable is TMycProtectedMutable<T>) then
|
||||
Result := TMycProtectedMutable<T>.Create(FWriteable)
|
||||
else
|
||||
Result := FWriteable;
|
||||
end;
|
||||
|
||||
procedure TWriteable<T>.SetValue(const Value: T);
|
||||
begin
|
||||
FWriteable.SetValue(Value);
|
||||
end;
|
||||
|
||||
class operator TWriteable<T>.Implicit(const A: IWriteable): TWriteable<T>;
|
||||
begin
|
||||
Result.Create(A);
|
||||
end;
|
||||
|
||||
class operator TWriteable<T>.Implicit(const A: TWriteable<T>): IWriteable;
|
||||
begin
|
||||
Result := A.FWriteable;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user