ProtectedMutable
This commit is contained in:
+14
-9
@@ -11,6 +11,7 @@ type
|
||||
type
|
||||
IWriter = interface
|
||||
procedure SetValue(const Value: T);
|
||||
function Exchange(const Value: T): T;
|
||||
end;
|
||||
|
||||
IMutable = interface
|
||||
@@ -46,9 +47,10 @@ type
|
||||
class property Null: IMutable read FNull;
|
||||
|
||||
class function Construct(const Changing: TSignal; const Proc: TFunc<T>): TMutable<T>; overload; static;
|
||||
class function CreateProtected: TMutable<T>; overload; static;
|
||||
class function CreateWriteable: TMutable<T>; overload; static;
|
||||
|
||||
function Protect: TMutable<T>;
|
||||
|
||||
property Value: T read GetValue write SetValue;
|
||||
property Changed: TSignal read GetChanged;
|
||||
property IsWriteable: Boolean read GetIsWriteable;
|
||||
@@ -112,11 +114,6 @@ begin
|
||||
Result := TMycFuncMutable<T>.Create(Changing, Proc);
|
||||
end;
|
||||
|
||||
class function TMutable<T>.CreateProtected: TMutable<T>;
|
||||
begin
|
||||
Result := TMycProtectedWriteableMutable<T>.Create(Default(T));
|
||||
end;
|
||||
|
||||
class function TMutable<T>.CreateWriteable: TMutable<T>;
|
||||
begin
|
||||
Result := TMycWriteableMutable<T>.Create(Default(T));
|
||||
@@ -129,7 +126,7 @@ end;
|
||||
|
||||
function TMutable<T>.GetIsWriteable: Boolean;
|
||||
begin
|
||||
Result := Assigned( FMutable.Writer );
|
||||
Result := Assigned(FMutable.Writer);
|
||||
end;
|
||||
|
||||
function TMutable<T>.GetValue: T;
|
||||
@@ -137,10 +134,18 @@ 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 );
|
||||
Assert(IsWriteable);
|
||||
FMutable.Writer.SetValue(Value);
|
||||
end;
|
||||
|
||||
class operator TMutable<T>.Implicit(const A: TMutable<T>): IMutable;
|
||||
|
||||
Reference in New Issue
Block a user