Code formatting
This commit is contained in:
+55
-55
@@ -18,24 +18,24 @@ type
|
||||
function GetIsSet: Boolean;
|
||||
{$ENDREGION}
|
||||
// Subscribes a given subscriber to this TState.
|
||||
function Subscribe( Subscriber: IMycSubscriber ): Pointer;
|
||||
procedure Unsubscribe( Tag: Pointer );
|
||||
function Subscribe(Subscriber: IMycSubscriber): Pointer;
|
||||
procedure Unsubscribe(Tag: Pointer);
|
||||
// IsSet is true if the TState has been reached or the condition is met.
|
||||
property IsSet: Boolean read GetIsSet;
|
||||
end;
|
||||
|
||||
TState = record // helper for IMycState
|
||||
type
|
||||
TSubscription = record
|
||||
private
|
||||
FState: IMycState;
|
||||
FTag: Pointer; // Tag identifying this subscription within the notifier list.
|
||||
constructor Create( const AState: IMycState; ATag: Pointer );
|
||||
public
|
||||
class operator Initialize( out Dest: TSubscription );
|
||||
// Unsubscribes from the associated TState.
|
||||
procedure Unsubscribe;
|
||||
end;
|
||||
type
|
||||
TSubscription = record
|
||||
private
|
||||
FState: IMycState;
|
||||
FTag: Pointer; // Tag identifying this subscription within the notifier list.
|
||||
constructor Create(const AState: IMycState; ATag: Pointer);
|
||||
public
|
||||
class operator Initialize(out Dest: TSubscription);
|
||||
// Unsubscribes from the associated TState.
|
||||
procedure Unsubscribe;
|
||||
end;
|
||||
|
||||
strict private
|
||||
class var
|
||||
@@ -45,25 +45,25 @@ type
|
||||
FState: IMycState;
|
||||
function GetIsSet: Boolean; inline;
|
||||
public
|
||||
constructor Create( const AState: IMycState );
|
||||
constructor Create(const AState: IMycState);
|
||||
|
||||
class operator Implicit( const A: IMycState ): TState; overload;
|
||||
class operator Implicit( const A: TState ): IMycState; overload;
|
||||
class operator Implicit(const A: IMycState): TState; overload;
|
||||
class operator Implicit(const A: TState): IMycState; overload;
|
||||
|
||||
class function All( const States: TArray<TState> ): TState; static;
|
||||
class function Any( const States: TArray<TState> ): TState; static;
|
||||
class function All(const States: TArray<TState>): TState; static;
|
||||
class function Any(const States: TArray<TState>): TState; static;
|
||||
|
||||
class property Null: IMycState read FNull;
|
||||
|
||||
function Subscribe( Subscriber: IMycSubscriber ): TSubscription; inline;
|
||||
procedure Unsubscribe( Tag: Pointer ); inline;
|
||||
function Subscribe(Subscriber: IMycSubscriber): TSubscription; inline;
|
||||
procedure Unsubscribe(Tag: Pointer); inline;
|
||||
|
||||
property IsSet: Boolean read GetIsSet;
|
||||
end;
|
||||
|
||||
// IMycLatch is a specific type of flag that, once set, remains set (non-resettable).
|
||||
// It typically becomes set when an internal countdown reaches zero.
|
||||
IMycLatch = interface( IMycSubscriber )
|
||||
IMycLatch = interface(IMycSubscriber)
|
||||
// Provides access to the IMycState interface of the flag.
|
||||
function GetState: TState;
|
||||
property State: TState read GetState;
|
||||
@@ -86,7 +86,7 @@ type
|
||||
|
||||
class function Construct(Count: Integer): TLatch; static;
|
||||
|
||||
class function Enqueue(var Gate: TLatch; Count: Integer=1): TState; static;
|
||||
class function Enqueue(var Gate: TLatch; Count: Integer = 1): TState; static;
|
||||
|
||||
class property Null: IMycLatch read FNull;
|
||||
|
||||
@@ -97,7 +97,7 @@ type
|
||||
|
||||
// IMycDirty represents a resettable flag, typically indicating if a State is "dirty" (requiring attention) or "clean".
|
||||
// It inherits from IMycFlag, meaning it has a State, can be notified, and subscribed to.
|
||||
IMycDirty = interface( IMycSubscriber )
|
||||
IMycDirty = interface(IMycSubscriber)
|
||||
// Provides access to the IMycState interface of the flag.
|
||||
function GetState: TState;
|
||||
// Resets the flag to its "clean" (not set / not dirty) State.
|
||||
@@ -119,26 +119,26 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
Myc.Core.Notifier, Myc.Core.Signals;
|
||||
Myc.Core.Notifier,
|
||||
Myc.Core.Signals;
|
||||
|
||||
{ TState.TSubscription }
|
||||
|
||||
constructor TState.TSubscription.Create( const AState: IMycState; ATag:
|
||||
TMycNotifyList<IMycSubscriber>.TTag );
|
||||
constructor TState.TSubscription.Create(const AState: IMycState; ATag: TMycNotifyList<IMycSubscriber>.TTag);
|
||||
begin
|
||||
Assert( Assigned( AState ) );
|
||||
Assert(Assigned(AState));
|
||||
FState := AState;
|
||||
FTag := ATag;
|
||||
end;
|
||||
|
||||
procedure TState.TSubscription.Unsubscribe;
|
||||
begin
|
||||
FState.Unsubscribe( FTag );
|
||||
FState.Unsubscribe(FTag);
|
||||
FState := TState.Null;
|
||||
FTag := nil;
|
||||
end;
|
||||
|
||||
class operator TState.TSubscription.Initialize( out Dest: TSubscription );
|
||||
class operator TState.TSubscription.Initialize(out Dest: TSubscription);
|
||||
begin
|
||||
Dest.FState := TState.Null;
|
||||
Dest.FTag := nil;
|
||||
@@ -146,42 +146,42 @@ end;
|
||||
|
||||
{ TState }
|
||||
|
||||
constructor TState.Create( const AState: IMycState );
|
||||
constructor TState.Create(const AState: IMycState);
|
||||
begin
|
||||
FState := AState;
|
||||
if not Assigned( FState ) then
|
||||
if not Assigned(FState) then
|
||||
FState := FNull;
|
||||
end;
|
||||
|
||||
class constructor TState.ClassCreate;
|
||||
begin
|
||||
// Create a singleton null latch instance that is initially (and always) set.
|
||||
FNull := TMycNullState.Create( ); // Calls the instance constructor
|
||||
FNull := TMycNullState.Create(); // Calls the instance constructor
|
||||
end;
|
||||
|
||||
class function TState.All( const States: TArray<TState> ): TState;
|
||||
class function TState.All(const States: TArray<TState>): TState;
|
||||
var
|
||||
Latch: IMycLatch;
|
||||
begin
|
||||
Latch := TLatch.Construct( Length( States ) );
|
||||
for var i := 0 to High( States ) do
|
||||
States[i].Subscribe( Latch );
|
||||
Latch := TLatch.Construct(Length(States));
|
||||
for var i := 0 to High(States) do
|
||||
States[i].Subscribe(Latch);
|
||||
Result := Latch.State;
|
||||
end;
|
||||
|
||||
class function TState.Any( const States: TArray<TState> ): TState;
|
||||
class function TState.Any(const States: TArray<TState>): TState;
|
||||
var
|
||||
Latch: IMycLatch;
|
||||
begin
|
||||
if Length( States ) = 0 then
|
||||
if Length(States) = 0 then
|
||||
begin
|
||||
Result := TState.Null;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Latch := TLatch.Construct( 1 );
|
||||
for var i := 0 to High( States ) do
|
||||
States[i].Subscribe( Latch );
|
||||
Latch := TLatch.Construct(1);
|
||||
for var i := 0 to High(States) do
|
||||
States[i].Subscribe(Latch);
|
||||
Result := Latch.State;
|
||||
end;
|
||||
end;
|
||||
@@ -191,24 +191,24 @@ begin
|
||||
Result := FState.IsSet;
|
||||
end;
|
||||
|
||||
function TState.Subscribe( Subscriber: IMycSubscriber ): TSubscription;
|
||||
function TState.Subscribe(Subscriber: IMycSubscriber): TSubscription;
|
||||
begin
|
||||
Result := TSubscription.Create( FState, FState.Subscribe( Subscriber ) );
|
||||
Result := TSubscription.Create(FState, FState.Subscribe(Subscriber));
|
||||
end;
|
||||
|
||||
procedure TState.Unsubscribe( Tag: Pointer );
|
||||
procedure TState.Unsubscribe(Tag: Pointer);
|
||||
begin
|
||||
FState.Unsubscribe( Tag );
|
||||
FState.Unsubscribe(Tag);
|
||||
end;
|
||||
|
||||
class operator TState.Implicit( const A: TState ): IMycState;
|
||||
class operator TState.Implicit(const A: TState): IMycState;
|
||||
begin
|
||||
Result := A.FState;
|
||||
end;
|
||||
|
||||
class operator TState.Implicit( const A: IMycState ): TState;
|
||||
class operator TState.Implicit(const A: IMycState): TState;
|
||||
begin
|
||||
Result.Create( A );
|
||||
Result.Create(A);
|
||||
end;
|
||||
|
||||
{ TLatch }
|
||||
@@ -224,24 +224,24 @@ end;
|
||||
constructor TLatch.Create(const ALatch: IMycLatch);
|
||||
begin
|
||||
FLatch := ALatch;
|
||||
if not Assigned( FLatch ) then
|
||||
if not Assigned(FLatch) then
|
||||
FLatch := FNull;
|
||||
end;
|
||||
|
||||
class function TLatch.Construct(Count: Integer): TLatch;
|
||||
begin
|
||||
if Count > 0 then
|
||||
Result := TMycLatch.Create( Count )
|
||||
Result := TMycLatch.Create(Count)
|
||||
else
|
||||
Result := FNull;
|
||||
end;
|
||||
|
||||
class function TLatch.Enqueue(var Gate: TLatch; Count: Integer=1): TState;
|
||||
class function TLatch.Enqueue(var Gate: TLatch; Count: Integer = 1): TState;
|
||||
begin
|
||||
var gateState := Gate.State;
|
||||
Gate := TMycLatch.Create( Count );
|
||||
gateState.Subscribe( Gate );
|
||||
exit( Gate.State );
|
||||
Gate := TMycLatch.Create(Count);
|
||||
gateState.Subscribe(Gate);
|
||||
exit(Gate.State);
|
||||
end;
|
||||
|
||||
function TLatch.GetState: TState;
|
||||
@@ -256,7 +256,7 @@ end;
|
||||
|
||||
class operator TLatch.Implicit(const A: IMycLatch): TLatch;
|
||||
begin
|
||||
Result.Create( A );
|
||||
Result.Create(A);
|
||||
end;
|
||||
|
||||
class operator TLatch.Implicit(const A: TLatch): IMycLatch;
|
||||
|
||||
Reference in New Issue
Block a user