Ignore:
Timestamp:
Jun 21, 2012, 10:39:13 AM (12 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/NativeGenerics/Units/GenericMatrix.pas

    r324 r379  
    1919      TRow = array of TItem;
    2020      TMerge = function(Item1, Item2: TItem): TItem of object;
     21      PItem = ^TItem;
    2122
    2223      TIndex = record
     
    6869    function Add(Item: TItem): TIndex;
    6970    procedure AddMatrix(Values: array of TRow);
    70     procedure AddList(List: TGMatrix);
    71     procedure Assign(Source: TGMatrix);
     71    procedure AddList(List: TGMatrix<TItem>);
     72    procedure Assign(Source: TGMatrix<TItem>);
    7273    procedure Clear; virtual;
    7374    procedure Contract;
     
    7576    procedure Delete(Index: TIndex); virtual;
    7677    procedure DeleteItems(Index, Count: TIndex);
    77     function EqualTo(List: TGMatrix): Boolean;
     78    function EqualTo(List: TGMatrix<TItem>): Boolean;
    7879    procedure Expand;
    7980    function Extract(Item: TItem): TItem;
     
    8586    procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
    8687    function IndexOf(Item: TItem; Start: TIndex = 0): TIndex;
    87     function IndexOfList(List: TGMatrix; Start: TIndex = 0): TIndex;
     88    function IndexOfList(List: TGMatrix<TItem>; Start: TIndex = 0): TIndex;
    8889    procedure Insert(Index: TIndex; Item: TItem);
    89     procedure InsertList(Index: TIndex; List: TGMatrix);
     90    procedure InsertList(Index: TIndex; List: TGMatrix<TItem>);
    9091    procedure InsertArray(Index: TIndex; Values: array of TItem);
    9192    procedure Move(CurIndex, NewIndex: TIndex);
    9293    procedure MoveItems(CurIndex, NewIndex, Count: TIndex);
    93     procedure Merge(Index: TIndex; Source: TGMatrix; Proc: TMerge);
    94     procedure Replace(Index: TIndex; Source: TGMatrix);
     94    procedure Merge(Index: TIndex; Source: TGMatrix<TItem>; Proc: TMerge);
     95    procedure Replace(Index: TIndex; Source: TGMatrix<TItem>);
    9596    function Remove(Item: TItem): TIndex;
    9697    procedure Reverse;
     
    107108      TIndex = TGAbstractMatrix<TItem>.TIndex;
    108109  private
     110    FRowSize: Integer;
     111    FCellSize: Integer;
    109112    FData: Pointer;
    110113    FCount: TIndex;
     114  public
     115    constructor Create;
     116    function GetItemXY(X: TIndexX; Y: TIndexY): TItem; override;
     117    procedure PutItemXY(X: TIndexX; Y: TIndexY; const AValue: TItem); override;
     118    property Data: Pointer read FData;
     119    property Count: TIndex read FCount write SetCount;
    111120  end;
    112121
     
    120129
    121130
     131{ TGRawMatrix }
     132
     133constructor TGRawMatrix<TItem>.Create;
     134begin
     135  FCellSize := SizeOf(TItem);
     136end;
     137
     138function TGRawMatrix<TItem>.GetItemXY(X: TIndexX; Y: TIndexY): TItem;
     139begin
     140  Result := PItem(X * FCellSize + Y * FRowSize)^;
     141end;
     142
     143procedure TGRawMatrix<TItem>.PutItemXY(X: TIndexX; Y: TIndexY; const AValue: TItem);
     144begin
     145  PItem(X * FCellSize + Y * FRowSize)^ := AValue;
     146end;
     147
    122148{ TGMatrix }
    123149
    124 procedure TGMatrix<TItem>.Replace(Index: TIndex; Source: TGMatrix);
     150procedure TGMatrix<TItem>.Replace(Index: TIndex; Source: TGMatrix<TItem>);
    125151var
    126152  X: TIndexX;
     
    138164end;
    139165
    140 procedure TGMatrix<TItem>.Merge(Index: TIndex; Source: TGMatrix; Proc: TMerge);
     166procedure TGMatrix<TItem>.Merge(Index: TIndex; Source: TGMatrix<TItem>; Proc: TMerge);
    141167var
    142168  X: TIndexX;
     
    221247end;
    222248
    223 procedure TGMatrix<TItem>.Assign(Source: TGMatrix);
     249procedure TGMatrix<TItem>.Assign(Source: TGMatrix<TItem>);
    224250var
    225251  Index: TIndex;
     
    309335end;
    310336
    311 procedure TGMatrix<TItem>.InsertList(Index: TIndex; List: TGMatrix);
     337procedure TGMatrix<TItem>.InsertList(Index: TIndex; List: TGMatrix<TItem>);
    312338var
    313339  I: TIndex;
     
    321347end;
    322348
    323 function TGMatrix<TItem>.IndexOfList(List: TGMatrix; Start: TIndex): TIndex;
     349function TGMatrix<TItem>.IndexOfList(List: TGMatrix<TItem>; Start: TIndex): TIndex;
    324350var
    325351  I: TIndex;
     
    429455end;
    430456
    431 function TGMatrix<TItem>.EqualTo(List: TGMatrix): Boolean;
     457function TGMatrix<TItem>.EqualTo(List: TGMatrix<TItem>): Boolean;
    432458var
    433459  I: TIndex;
     
    575601end;
    576602
    577 procedure TGMatrix<TItem>.AddList(List: TGMatrix);
     603procedure TGMatrix<TItem>.AddList(List: TGMatrix<TItem>);
    578604var
    579605  I: TIndex;
Note: See TracChangeset for help on using the changeset viewer.