Ignore:
Timestamp:
Jul 20, 2018, 10:25:06 AM (6 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        66compiled
        77heaptrclog.trc
         8LazFuck.dbg
  • trunk/Packages/TemplateGenerics/Generic/GenericList.inc

    r54 r93  
    1212  // - all items operations (Clear, Reverse, Sort)
    1313
    14   TGList = class;
    15 
    16   TGListSortCompare = function(Item1, Item2: TGListItem): Integer of object;
    17   TGListToStringConverter = function(Item: TGListItem): string;
    18   TGListFromStringConverter = function(Text: string): TGListItem;
    19   TGListItemArray = array of TGListItem;
     14  //TGAbstractList = class
     15
     16  //end;
    2017
    2118  // TGList<TGListIndex, TGListItem> = class
    22   TGList = class
     19  TGList = class//(TGAbstractList)
     20  public
     21    type
     22      PItem = ^TGListItem;
     23      TSortCompare = function(Item1, Item2: TGListItem): Integer of object;
     24      TToStringConverter = function(Item: TGListItem): string;
     25      TFromStringConverter = function(Text: string): TGListItem;
     26      TItemArray = array of TGListItem;
    2327  private
    2428    FItems: array of TGListItem;
     
    3438    procedure SetLast(AValue: TGListItem);
    3539    procedure SetFirst(AValue: TGListItem);
    36     procedure QuickSort(L, R : TGListIndex; Compare: TGListSortCompare);
     40    procedure QuickSort(L, R : TGListIndex; Compare: TSortCompare);
     41    procedure DoUpdate;
    3742  protected
    3843    procedure Put(Index: TGListIndex; const AValue: TGListItem); virtual;
     
    5156    function EqualTo(List: TGList): Boolean;
    5257    procedure Exchange(Index1, Index2: TGListIndex);
    53     procedure Explode(Text, Separator: string; Converter: TGListFromStringConverter; SlicesCount: Integer = -1);
     58    procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
    5459    function Extract(Item: TGListItem): TGListItem;
    5560    property First: TGListItem read GetFirst write SetFirst;
    5661    procedure Fill(Start, Count: TGListIndex; Value: TGListItem);
    57     function GetArray(Index, ACount: TGListIndex): TGListItemArray;
     62    function GetArray(Index, ACount: TGListIndex): TItemArray;
    5863    procedure GetList(List: TGList; Index, ACount: TGListIndex);
    59     function Implode(Separator: string; Converter: TGListToStringConverter): string;
     64    procedure GetBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex);
     65    function Implode(Separator: string; Converter: TToStringConverter): string;
    6066    function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex; virtual;
    6167    function IndexOfList(List: TGList; Start: TGListIndex = 0): TGListIndex;
     
    7379    procedure ReplaceListPart(Index: TGListIndex; Source: TGList;
    7480      SourceIndex, SourceCount: TGListIndex);
    75     procedure Sort(Compare: TGListSortCompare);
     81    procedure ReplaceBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex);
     82    procedure Sort(Compare: TSortCompare);
    7683    procedure SetArray(Values: array of TGListItem);
    7784    procedure BeginUpdate;
     
    8289    property Items[Index: TGListIndex]: TGListItem read Get write Put; default;
    8390    property Last: TGListItem read GetLast write SetLast;
    84   end;
    85  
     91    property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
     92  end;
     93
    8694{$UNDEF INTERFACE}
    8795{$ENDIF}
     
    102110begin
    103111  FCount := 0;
     112  FUpdateCount := 0;
     113end;
     114
     115procedure TGList.GetBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex);
     116var
     117  P: PItem;
     118  I: TGListIndex;
     119begin
     120  if (Index + Count) > FCount then
     121    raise EListError.CreateFmt(SListIndexError, [Index + Count]);
     122  P := PItem(@Buffer);
     123  I := 0;
     124  while I < Count do begin
     125    P^ := Items[Index + I];
     126    Inc(P, 1);
     127    I := I + 1;
     128  end;
     129end;
     130
     131procedure TGList.ReplaceBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex);
     132var
     133  P: PItem;
     134  I: TGListIndex;
     135begin
     136  if (Index + Count) > FCount then
     137    raise EListError.CreateFmt(SListIndexError, [Index + Count]);
     138  P := PItem(@Buffer);
     139  I := 0;
     140  while I < Count do begin
     141    Items[Index + I] := P^;
     142    Inc(P, 1);
     143    I := I + 1;
     144  end;
    104145end;
    105146
     
    200241end;
    201242
    202 function TGList.GetArray(Index, ACount: TGListIndex): TGListItemArray;
     243function TGList.GetArray(Index, ACount: TGListIndex): TItemArray;
    203244var
    204245  I: Integer;
     
    218259end;
    219260
    220 procedure TGList.QuickSort(L, R: TGListIndex; Compare: TGListSortCompare);
     261procedure TGList.QuickSort(L, R: TGListIndex; Compare: TSortCompare);
    221262var
    222263  I, J: TGListIndex;
     
    302343  if (Index < 0) or (Index > FCount) then
    303344    raise EListError.CreateFmt(SListIndexError, [Index]);
    304   InsertCount(Index, 1);
    305   FItems[Index] := Item;
    306   Update;
     345  try
     346    BeginUpdate;
     347    InsertCount(Index, 1);
     348    FItems[Index] := Item;
     349  finally
     350    EndUpdate;
     351  end;
    307352end;
    308353
     
    487532end;
    488533
    489 procedure TGList.Sort(Compare: TGListSortCompare);
     534procedure TGList.Sort(Compare: TSortCompare);
    490535begin
    491536  if FCount > 1 then
     
    525570procedure TGList.EndUpdate;
    526571begin
    527   Dec(FUpdateCount);
    528   Update;
     572  if FUpdateCount > 0 then Dec(FUpdateCount);
     573  if FUpdateCount = 0 then DoUpdate;
     574end;
     575
     576procedure TGList.DoUpdate;
     577begin
     578  if Assigned(FOnUpdate) then FOnUpdate(Self);
    529579end;
    530580
    531581procedure TGList.Update;
    532582begin
    533   if Assigned(FOnUpdate) and (FUpdateCount = 0) then FOnUpdate(Self);
    534 end;
    535 
    536 function TGList.Implode(Separator: string; Converter: TGListToStringConverter): string;
     583  if FUpdateCount = 0 then DoUpdate;
     584end;
     585
     586function TGList.Implode(Separator: string; Converter: TToStringConverter): string;
    537587var
    538588  I: TGListIndex;
     
    548598end;
    549599
    550 procedure TGList.Explode(Text, Separator: string; Converter: TGListFromStringConverter; SlicesCount: Integer = -1);
     600procedure TGList.Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
    551601begin
    552602  Clear;
Note: See TracChangeset for help on using the changeset viewer.