Ignore:
Timestamp:
Oct 29, 2010, 1:26:32 PM (14 years ago)
Author:
george
Message:
  • Added: Generic range type.
  • Added: Specialized TListByte type which si simply memory block.
  • Added: New functionality to TGList.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/ListImplementation.tpl

    r76 r77  
    109109end;
    110110
    111 function TGList.IndexOf(Item: TListItem): TListIndex;
    112 begin
    113   Result := 0;
     111function TGList.IndexOf(Item: TListItem; Start: TListIndex): TListIndex;
     112begin
     113  Result := Start;
    114114  while (Result < FCount) and
    115115  not CompareMem(Addr(FItems[Result]), Addr(Item), SizeOf(TListItem)) do
     
    138138    I := I + 1;
    139139  end;
     140end;
     141
     142function TGList.IndexOfList(List: TGList; Start: TListIndex): TListIndex;
     143var
     144  I: TListIndex;
     145begin
     146  if List.Count > 0 then begin
     147    Result := IndexOf(List[0], Start);
     148    if Result <> -1 then begin
     149      I := 1;
     150      while I < List.Count do begin
     151        if not CompareMem(Addr(FItems[Result + I]), Addr(List.FItems[I]), SizeOf(TListItem)) then begin
     152          Result := -1;
     153          Break;
     154        end;
     155        I := I + 1;
     156      end;
     157    end;
     158  end else Result := -1;
    140159end;
    141160
     
    200219end;
    201220
    202 (*function TGList.Equals(Obj: TObject): Boolean;
    203 var
    204   I: TListIndex;
    205 begin
    206   Result := Count = (Obj as TGList).Count;
     221function TGList.Equals(List: TGList): Boolean;
     222var
     223  I: TListIndex;
     224begin
     225  Result := Count = List.Count;
    207226  if Result then begin
    208227    I := 0;
    209228    while I < Count do begin
    210       if Items[I] <> (Obj as TGList)[I] then begin
     229      if not CompareMem(Addr(FItems[I]), Addr(List.FItems[I]), SizeOf(TListItem)) then begin
    211230        Result := False;
    212231        Break;
     
    215234    end;
    216235  end;
    217 end;*)
     236end;
    218237
    219238procedure TGList.Reverse;
     
    241260  while I <= High(Values) do begin
    242261    Add(Values[I]);
     262    I := I + 1;
     263  end;
     264end;
     265
     266procedure TGList.SetArray(Values: array of TListItem);
     267var
     268  I: TListIndex;
     269begin
     270  Clear;
     271  I := 0;
     272  while I <= High(Values) do begin
     273    Add(Values[I]);
     274    I := I + 1;
     275  end;
     276end;
     277
     278procedure TGList.InsertArray(Index: TListIndex; Values: array of TListItem);
     279var
     280  I: TListIndex;
     281begin
     282  I := 0;
     283  while I <= High(Values) do begin
     284    Insert(Index + I, Values[I]);
    243285    I := I + 1;
    244286  end;
     
    255297    if I < (Count - 1) then
    256298      Result := Result + Separator;
     299    I := I + 1;
     300  end;
     301end;
     302
     303procedure TGList.Perform(Operation: TGListOperation);
     304var
     305  I: TListIndex;
     306begin
     307  I := 0;
     308  while I < Count do begin
     309    Operation(Self, @FItems[I]);
    257310    I := I + 1;
    258311  end;
     
    309362end;
    310363
     364procedure TGList.Fill(Start, Count: TListIndex; Value: TListItem);
     365begin
     366  while Count > 0 do begin
     367    Items[Start] := Value;
     368    Count := Count - 1;
     369    Start := Start + 1;
     370  end;
     371end;
     372
    311373procedure TGList.Exchange(Index1, Index2: TListIndex);
    312374var
Note: See TracChangeset for help on using the changeset viewer.