Changeset 65 for Generics


Ignore:
Timestamp:
Oct 27, 2010, 2:09:59 PM (14 years ago)
Author:
george
Message:
  • Updated: Generic List unit.
Location:
Generics/units
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/units/GenericList.pas

    r37 r65  
    77uses
    88  Classes, SysUtils, fgl;
     9
     10resourcestring
     11  SNotImplemented = 'Not implememnted';
    912
    1013type
     
    4851    property Capacity: TIndexType read GetCapacity write SetCapacity;
    4952  public
     53    // All items
     54    procedure Reverse;
     55    procedure Clear;
     56    procedure Expand;
     57    procedure Sort(Compare: TGListSortCompare);
     58    function Implode(Separator: string): string;
     59    // Many items
     60    procedure MoveItems(CurIndex, NewIndex, Count: TIndexType);
     61    // One item
    5062    function Add(Item: TItemType): TIndexType;
    51     function AddList(var Source): TIndexType;
    52     procedure Clear;
    5363    procedure Delete(Index: TIndexType);
    54     procedure DeleteItems(Index, Count: TIndexType);
    5564    procedure Exchange(Index1, Index2: TIndexType);
    56     procedure Expand;
    5765    function Extract(Item: TItemType): TItemType;
    58     function ExtractList(Item: TItemType; Count: TIndexType): TItemType;
    5966    function First: TItemType;
    6067    function IndexOf(Item: TItemType): TIndexType;
    6168    procedure Insert(Index: TIndexType; Item: TItemType);
    62     procedure InsertList(Index: TIndexType; var Source);
    6369    function Last: TItemType;
    6470    procedure Move(CurIndex, NewIndex: TIndexType);
    65     procedure MoveItems(CurIndex, NewIndex, Count: TIndexType);
    6671    function Remove(Item: TItemType): TIndexType;
    67     procedure Reverse;
    68     procedure Sort(Compare: TGListSortCompare);
    6972    property Items[Index: TIndexType]: TItemType read Get write Put; default;
     73    // List
     74    function AddList(var Source): TIndexType;
     75    procedure Assign(var List);
     76    procedure DeleteItems(Index, Count: TIndexType);
     77    function Equals(Obj: TObject): Boolean; override;
     78    function ExtractList(Item: TItemType; Count: TIndexType): TItemType;
     79    procedure InsertList(Index: TIndexType; var Source);
     80    // Other
    7081    property Count: TIndexType read GetCount write SetCount;
     82    // Additional
     83    procedure SetArray(Values: array of TItemType);
    7184  end;
    7285
     
    157170   P := FItems[ (L + R) div 2 ];
    158171   repeat
    159      while Compare(P, FItems[i]) > 0 do
     172     while Compare(P, FItems[I]) > 0 do
    160173       I := I + 1;
    161174     while Compare(P, FItems[J]) < 0 do
     
    176189end;
    177190
     191procedure TGList.Assign(var List);
     192var
     193  I: Integer;
     194begin
     195  (*Count := List.Count;
     196  I := 0;
     197  while I < Count do begin
     198    Items[I] := List[I];
     199  end;*)
     200  raise Exception.Create(SNotImplemented);
     201end;
     202
    178203procedure TGList.Expand;
    179204var
     
    191216function TGList.Extract(Item: TItemType): TItemType;
    192217var
    193   I: Integer;
     218  I: TIndexType;
    194219begin
    195220  I := IndexOf(Item);
     
    203228function TGList.ExtractList(Item: TItemType; Count: TIndexType): TItemType;
    204229begin
    205 
     230  raise Exception.Create(SNotImplemented);
    206231end;
    207232
     
    243268  end;
    244269  *)
     270  raise Exception.Create(SNotImplemented);
    245271end;
    246272
     
    268294procedure TGList.MoveItems(CurIndex, NewIndex, Count: TIndexType);
    269295begin
    270 
     296  raise Exception.Create(SNotImplemented);
    271297end;
    272298
     
    278304end;
    279305
     306function TGList.Equals(Obj: TObject): Boolean;
     307var
     308  I: TIndexType;
     309begin
     310(*  Result := Count = List.Count;
     311  if Result then begin
     312    I := 0;
     313    while I < Count do
     314      if Items[I] <> List[I] then Result := False;
     315  end;
     316  *)
     317  // Not implemented
     318  raise Exception.Create(SNotImplemented);
     319  Result := False;
     320end;
     321
    280322procedure TGList.Reverse;
    281323begin
    282 
     324  raise Exception.Create(SNotImplemented);
    283325end;
    284326
     
    287329  if FCount > 1 then
    288330    QuickSort(0, FCount - 1, Compare);
     331end;
     332
     333procedure TGList.SetArray(Values: array of TItemType);
     334var
     335  I: TIndexType;
     336begin
     337  Clear;
     338  I := 0;
     339  while I <= High(Values) do begin
     340    Add(Values[I]);
     341    I := I + 1;
     342  end;
     343end;
     344
     345function TGList.Implode(Separator: string): string;
     346var
     347  I: TIndexType;
     348begin
     349  Result := '';
     350  I := 0;
     351  while I < Count do begin
     352//    Result := Result + string(Items[I]);
     353    if I < (Count - 1) then
     354      Result := Result + Separator;
     355    I := I + 1;
     356  end;
    289357end;
    290358
     
    308376  end;
    309377  *)
     378 // Not implemented
     379 Result := 0;
     380 raise Exception.Create(SNotImplemented);
    310381end;
    311382
Note: See TracChangeset for help on using the changeset viewer.