Changeset 93 for trunk/Packages/TemplateGenerics/Generic/GenericList.inc
- Timestamp:
- Jul 20, 2018, 10:25:06 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 6 6 compiled 7 7 heaptrclog.trc 8 LazFuck.dbg
-
- Property svn:ignore
-
trunk/Packages/TemplateGenerics/Generic/GenericList.inc
r54 r93 12 12 // - all items operations (Clear, Reverse, Sort) 13 13 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; 20 17 21 18 // 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; 23 27 private 24 28 FItems: array of TGListItem; … … 34 38 procedure SetLast(AValue: TGListItem); 35 39 procedure SetFirst(AValue: TGListItem); 36 procedure QuickSort(L, R : TGListIndex; Compare: TGListSortCompare); 40 procedure QuickSort(L, R : TGListIndex; Compare: TSortCompare); 41 procedure DoUpdate; 37 42 protected 38 43 procedure Put(Index: TGListIndex; const AValue: TGListItem); virtual; … … 51 56 function EqualTo(List: TGList): Boolean; 52 57 procedure Exchange(Index1, Index2: TGListIndex); 53 procedure Explode(Text, Separator: string; Converter: T GListFromStringConverter; SlicesCount: Integer = -1);58 procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); 54 59 function Extract(Item: TGListItem): TGListItem; 55 60 property First: TGListItem read GetFirst write SetFirst; 56 61 procedure Fill(Start, Count: TGListIndex; Value: TGListItem); 57 function GetArray(Index, ACount: TGListIndex): T GListItemArray;62 function GetArray(Index, ACount: TGListIndex): TItemArray; 58 63 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; 60 66 function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex; virtual; 61 67 function IndexOfList(List: TGList; Start: TGListIndex = 0): TGListIndex; … … 73 79 procedure ReplaceListPart(Index: TGListIndex; Source: TGList; 74 80 SourceIndex, SourceCount: TGListIndex); 75 procedure Sort(Compare: TGListSortCompare); 81 procedure ReplaceBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex); 82 procedure Sort(Compare: TSortCompare); 76 83 procedure SetArray(Values: array of TGListItem); 77 84 procedure BeginUpdate; … … 82 89 property Items[Index: TGListIndex]: TGListItem read Get write Put; default; 83 90 property Last: TGListItem read GetLast write SetLast; 84 end; 85 91 property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate; 92 end; 93 86 94 {$UNDEF INTERFACE} 87 95 {$ENDIF} … … 102 110 begin 103 111 FCount := 0; 112 FUpdateCount := 0; 113 end; 114 115 procedure TGList.GetBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex); 116 var 117 P: PItem; 118 I: TGListIndex; 119 begin 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; 129 end; 130 131 procedure TGList.ReplaceBuffer(Index: TGListIndex; var Buffer; Count: TGListIndex); 132 var 133 P: PItem; 134 I: TGListIndex; 135 begin 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; 104 145 end; 105 146 … … 200 241 end; 201 242 202 function TGList.GetArray(Index, ACount: TGListIndex): T GListItemArray;243 function TGList.GetArray(Index, ACount: TGListIndex): TItemArray; 203 244 var 204 245 I: Integer; … … 218 259 end; 219 260 220 procedure TGList.QuickSort(L, R: TGListIndex; Compare: T GListSortCompare);261 procedure TGList.QuickSort(L, R: TGListIndex; Compare: TSortCompare); 221 262 var 222 263 I, J: TGListIndex; … … 302 343 if (Index < 0) or (Index > FCount) then 303 344 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; 307 352 end; 308 353 … … 487 532 end; 488 533 489 procedure TGList.Sort(Compare: T GListSortCompare);534 procedure TGList.Sort(Compare: TSortCompare); 490 535 begin 491 536 if FCount > 1 then … … 525 570 procedure TGList.EndUpdate; 526 571 begin 527 Dec(FUpdateCount); 528 Update; 572 if FUpdateCount > 0 then Dec(FUpdateCount); 573 if FUpdateCount = 0 then DoUpdate; 574 end; 575 576 procedure TGList.DoUpdate; 577 begin 578 if Assigned(FOnUpdate) then FOnUpdate(Self); 529 579 end; 530 580 531 581 procedure TGList.Update; 532 582 begin 533 if Assigned(FOnUpdate) and (FUpdateCount = 0) then FOnUpdate(Self);534 end; 535 536 function TGList.Implode(Separator: string; Converter: T GListToStringConverter): string;583 if FUpdateCount = 0 then DoUpdate; 584 end; 585 586 function TGList.Implode(Separator: string; Converter: TToStringConverter): string; 537 587 var 538 588 I: TGListIndex; … … 548 598 end; 549 599 550 procedure TGList.Explode(Text, Separator: string; Converter: T GListFromStringConverter; SlicesCount: Integer = -1);600 procedure TGList.Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); 551 601 begin 552 602 Clear;
Note:
See TracChangeset
for help on using the changeset viewer.