Ignore:
Timestamp:
Dec 20, 2021, 6:45:12 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Removed: CoolTranslator merged into Common package.
  • Modified: Code cleanup.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/TemplateGenerics/Generic/GenericMatrix.inc

    r34 r51  
    3030    procedure PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem); virtual;
    3131    procedure SetCount(const AValue: TGMatrixIndex);
     32    procedure CheckRange(X: TGMatrixIndexX; Y: TGMatrixIndexY); inline;
    3233  public
     34    constructor Create; virtual;
    3335    function Add(Item: TGMatrixItem): TGMatrixIndex;
    3436    procedure AddMatrix(Values: array of TGMatrixRow);
     
    140142begin
    141143  if (Capacity.X <> AValue.X) and (Capacity.Y <> AValue.Y) then begin
    142 (*    SetLength(FItems, AValue.Y);
     144    SetLength(FItems, AValue.Y);
    143145    Y := 0;
    144146    while Y < Length(FItems) do begin
     
    146148      Y := Y + 1;
    147149    end;
    148   end;
    149   *)
    150     SetLength(FItems, AValue.Y, AValue.X);
     150
     151  {  SetLength(FItems, AValue.Y, AValue.X);}
    151152  end;
    152153end;
    153154
    154155function TGMatrix.GetItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY): TGMatrixItem;
     156begin
     157  CheckRange(X, Y);
     158  Result := FItems[Y, X];
     159end;
     160
     161function TGMatrix.GetItem(Index: TGMatrixIndex): TGMatrixItem;
     162begin
     163  CheckRange(Index.X, Index.Y);
     164  Result := FItems[Index.Y, Index.X];
     165end;
     166
     167procedure TGMatrix.PutItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY; const AValue: TGMatrixItem);
     168begin
     169  CheckRange(X, Y);
     170  FItems[Y, X] := AValue;
     171end;
     172
     173procedure TGMatrix.PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem);
     174begin
     175  CheckRange(Index.X, Index.Y);
     176  FItems[Index.Y, Index.X] := AValue;
     177end;
     178
     179procedure TGMatrix.SetCount(const AValue: TGMatrixIndex);
     180begin
     181  Capacity := AValue;
     182  FCount := AValue;
     183end;
     184
     185procedure TGMatrix.CheckRange(X: TGMatrixIndexX; Y: TGMatrixIndexY);
    155186begin
    156187  if (X < 0) or (X >= Count.X) or
    157188    (Y < 0) or (Y >= Count.Y) then
    158189    raise EListError.CreateFmt(SMatrixIndexError, [X, Y]);
    159   Result := FItems[Y, X];
    160 end;
    161 
    162 function TGMatrix.GetItem(Index: TGMatrixIndex): TGMatrixItem;
    163 begin
    164   if (Index.X < 0) or (Index.X >= Count.X) or
    165     (Index.Y < 0) or (Index.Y >= Count.Y) then
    166     raise EListError.CreateFmt(SMatrixIndexError, [Index.X, Index.Y]);
    167   Result := FItems[Index.Y, Index.X];
    168 end;
    169 
    170 procedure TGMatrix.PutItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY; const AValue: TGMatrixItem);
    171 begin
    172   if (X < 0) or (X >= Count.X) or
    173     (Y < 0) or (Y >= Count.Y) then
    174     raise EListError.CreateFmt(SMatrixIndexError, [X, Y]);
    175   FItems[Y, X] := AValue;
    176 end;
    177 
    178 procedure TGMatrix.PutItem(Index: TGMatrixIndex; const AValue: TGMatrixItem);
    179 begin
    180   if (Index.X < 0) or (Index.X >= Count.X) or
    181     (Index.Y < 0) or (Index.Y >= Count.Y) then
    182     raise EListError.CreateFmt(SMatrixIndexError, [Index.X, Index.Y]);
    183   FItems[Index.Y, Index.X] := AValue;
    184 end;
    185 
    186 procedure TGMatrix.SetCount(const AValue: TGMatrixIndex);
    187 begin
    188   Capacity := AValue;
    189   FCount := AValue;
    190190end;
    191191
     
    555555end;
    556556
     557constructor TGMatrix.Create;
     558begin
     559  SetLength(FItems, 0, 0);
     560  FCount := CreateIndex(0, 0);
     561end;
     562
    557563procedure TGMatrix.Clear;
    558564begin
Note: See TracChangeset for help on using the changeset viewer.