Ignore:
Timestamp:
Oct 30, 2010, 6:39:12 PM (14 years ago)
Author:
george
Message:
  • Added: Ability of TListObject to own items and be able to free them on deletion and list destruction.
Location:
Generics/TemplateGenerics/Generic
Files:
2 edited

Legend:

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

    r77 r78  
    1717begin
    1818  Result := FItems[Index];
    19 end;
    20 
    21 function TGList.GetCount: TListIndex;
    22 begin
    23   Result := FCount;
    2419end;
    2520
     
    8984end;
    9085
     86procedure TGList.Contract;
     87begin
     88  if (Capacity > 256) and (FCount < Capacity shr 2) then
     89  begin
     90    Capacity := Capacity shr 1;
     91  end;
     92end;
     93
    9194function TGList.Extract(Item: TListItem): TListItem;
    9295var
     
    344347  FCount := FCount - 1;
    345348  System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem));
    346   // Shrink the list if appropriate
    347   if (Capacity > 256) and (FCount < Capacity shr 2) then
    348   begin
    349     Capacity := Capacity shr 1;
    350   end;
     349  Contract;
    351350end;
    352351
  • Generics/TemplateGenerics/Generic/ListInterface.tpl

    r77 r78  
    1414    FCount: TListIndex;
    1515    function Get(Index: TListIndex): TListItem;
    16     function GetCount: TListIndex;
    1716    function GetCapacity: TListIndex;
    1817    procedure SetCapacity(const AValue: TListIndex);
    19     procedure Put(Index: TListIndex; const AValue: TListItem);
     18    procedure Put(Index: TListIndex; const AValue: TListItem); virtual;
    2019    procedure SetCount(const AValue: TListIndex);
    2120    procedure QuickSort(L, R : TListIndex; Compare: TGListSortCompare);
     
    2322    // All items
    2423    procedure Reverse;
    25     procedure Clear;
     24    procedure Clear; virtual;
    2625    procedure Expand;
     26    procedure Contract;
    2727    procedure Sort(Compare: TGListSortCompare);
    2828    function Implode(Separator: string; Converter: TGListStringConverter): string;
     
    3434    // One item
    3535    function Add(Item: TListItem): TListIndex;
    36     procedure Delete(Index: TListIndex);
     36    procedure Delete(Index: TListIndex); virtual;
    3737    function Extract(Item: TListItem): TListItem;
    3838    procedure Exchange(Index1, Index2: TListIndex);
     
    5151    function IndexOfList(List: TGList; Start: TListIndex = 0): TListIndex;
    5252    // Other
    53     property Count: TListIndex read GetCount write SetCount;
     53    property Count: TListIndex read FCount write SetCount;
    5454    property Capacity: TListIndex read GetCapacity write SetCapacity;
    5555    // Array
Note: See TracChangeset for help on using the changeset viewer.