| 1 | {$IFDEF INTERFACE}
|
|---|
| 2 |
|
|---|
| 3 | TGList = class;
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | // TGList<TGListIndex, TGListItem> = class
|
|---|
| 7 | TGList = class
|
|---|
| 8 | type
|
|---|
| 9 | TSortCompare = function(Item1, Item2: TGListItem): Integer of object;
|
|---|
| 10 | TToStringConverter = function(Item: TGListItem): string;
|
|---|
| 11 | TFromStringConverter = function(Text: string): TGListItem;
|
|---|
| 12 | TItemArray = array of TGListItem;
|
|---|
| 13 | private
|
|---|
| 14 | FItems: array of TGListItem;
|
|---|
| 15 | FCount: TGListIndex;
|
|---|
| 16 | function Get(Index: TGListIndex): TGListItem;
|
|---|
| 17 | function GetCapacity: TGListIndex;
|
|---|
| 18 | function GetLast: TGListItem;
|
|---|
| 19 | function GetFirst: TGListItem;
|
|---|
| 20 | procedure SetCapacity(const AValue: TGListIndex);
|
|---|
| 21 | procedure SetCapacityOptimized(const NewCapacity: TGListIndex);
|
|---|
| 22 | procedure SetLast(AValue: TGListItem);
|
|---|
| 23 | procedure SetFirst(AValue: TGListItem);
|
|---|
| 24 | procedure Put(Index: TGListIndex; const AValue: TGListItem); virtual;
|
|---|
| 25 | procedure SetCount(const AValue: TGListIndex); virtual;
|
|---|
| 26 | procedure QuickSort(L, R : TGListIndex; Compare: TSortCompare);
|
|---|
| 27 | public
|
|---|
| 28 | function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean; inline;
|
|---|
| 29 | function Add(Item: TGListItem): TGListIndex;
|
|---|
| 30 | procedure AddArray(Values: array of TGListItem);
|
|---|
| 31 | procedure AddList(List: TGList);
|
|---|
| 32 | procedure Assign(Source: TGList); virtual;
|
|---|
| 33 | procedure Clear; virtual;
|
|---|
| 34 | procedure Delete(Index: TGListIndex); virtual;
|
|---|
| 35 | procedure DeleteItems(Index, Count: TGListIndex);
|
|---|
| 36 | function EqualTo(List: TGList): Boolean;
|
|---|
| 37 | procedure Exchange(Index1, Index2: TGListIndex);
|
|---|
| 38 | procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
|
|---|
| 39 | function Extract(Item: TGListItem): TGListItem;
|
|---|
| 40 | property First: TGListItem read GetFirst write SetFirst;
|
|---|
| 41 | procedure Fill(Start, Count: TGListIndex; Value: TGListItem);
|
|---|
| 42 | function GetArray: TItemArray;
|
|---|
| 43 | function Implode(Separator: string; Converter: TToStringConverter): string;
|
|---|
| 44 | function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex;
|
|---|
| 45 | function IndexOfList(List: TGList; Start: TGListIndex = 0): TGListIndex;
|
|---|
| 46 | procedure Insert(Index: TGListIndex; Item: TGListItem);
|
|---|
| 47 | procedure InsertList(Index: TGListIndex; List: TGList);
|
|---|
| 48 | procedure InsertArray(Index: TGListIndex; Values: array of TGListItem);
|
|---|
| 49 | procedure Move(CurIndex, NewIndex: TGListIndex);
|
|---|
| 50 | procedure MoveItems(CurIndex, NewIndex, Count: TGListIndex);
|
|---|
| 51 | function Remove(Item: TGListItem): TGListIndex;
|
|---|
| 52 | procedure Reverse;
|
|---|
| 53 | procedure Replace(Index: TGListIndex; Source: TGList);
|
|---|
| 54 | procedure Sort(Compare: TSortCompare);
|
|---|
| 55 | procedure SetArray(Values: TItemArray);
|
|---|
| 56 | property Count: TGListIndex read FCount write SetCount;
|
|---|
| 57 | property Capacity: TGListIndex read GetCapacity write SetCapacity;
|
|---|
| 58 | property Items[Index: TGListIndex]: TGListItem read Get write Put; default;
|
|---|
| 59 | property Last: TGListItem read GetLast write SetLast;
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | {$UNDEF INTERFACE}
|
|---|
| 63 | {$ENDIF}
|
|---|
| 64 |
|
|---|
| 65 | {$IFDEF IMPLEMENTATION_USES}
|
|---|
| 66 |
|
|---|
| 67 | uses
|
|---|
| 68 | RtlConsts;
|
|---|
| 69 |
|
|---|
| 70 | {$UNDEF IMPLEMENTATION_USES}
|
|---|
| 71 | {$ENDIF}
|
|---|
| 72 |
|
|---|
| 73 | {$IFDEF IMPLEMENTATION}
|
|---|
| 74 |
|
|---|
| 75 | { TGList }
|
|---|
| 76 |
|
|---|
| 77 | procedure TGList.Replace(Index: TGListIndex; Source: TGList);
|
|---|
| 78 | var
|
|---|
| 79 | I: TGListIndex;
|
|---|
| 80 | begin
|
|---|
| 81 | I := 0;
|
|---|
| 82 | while I < Source.Count do begin
|
|---|
| 83 | Items[Index + I] := Source[I];
|
|---|
| 84 | I := I + 1;
|
|---|
| 85 | end;
|
|---|
| 86 | end;
|
|---|
| 87 |
|
|---|
| 88 | function TGList.GetCapacity: TGListIndex;
|
|---|
| 89 | begin
|
|---|
| 90 | Result := Length(FItems);
|
|---|
| 91 | end;
|
|---|
| 92 |
|
|---|
| 93 | procedure TGList.SetCapacity(const AValue: TGListIndex);
|
|---|
| 94 | begin
|
|---|
| 95 | if (AValue < FCount) then
|
|---|
| 96 | raise EListError.CreateFmt(SListCapacityError, [AValue]);
|
|---|
| 97 | SetLength(FItems, AValue);
|
|---|
| 98 | end;
|
|---|
| 99 |
|
|---|
| 100 | procedure TGList.SetCapacityOptimized(const NewCapacity: TGListIndex);
|
|---|
| 101 | var
|
|---|
| 102 | IncSize: TGListIndex;
|
|---|
| 103 | begin
|
|---|
| 104 | if NewCapacity > Capacity then begin
|
|---|
| 105 | IncSize := NewCapacity - Capacity;
|
|---|
| 106 | // Expand
|
|---|
| 107 | if IncSize = 1 then begin
|
|---|
| 108 | IncSize := 4;
|
|---|
| 109 | if Capacity > 3 then IncSize := IncSize + 4;
|
|---|
| 110 | if Capacity > 8 then IncSize := IncSize + 8;
|
|---|
| 111 | if Capacity > 63 then IncSize := IncSize + Capacity shr 2; // Grow by one quarter
|
|---|
| 112 | end;
|
|---|
| 113 | Capacity := Capacity + IncSize;
|
|---|
| 114 | end else
|
|---|
| 115 | if NewCapacity < Capacity then begin
|
|---|
| 116 | // Contract
|
|---|
| 117 | if (Capacity > 256) and (FCount < Capacity shr 2) then
|
|---|
| 118 | begin
|
|---|
| 119 | Capacity := Capacity shr 1;
|
|---|
| 120 | end;
|
|---|
| 121 | end;
|
|---|
| 122 | end;
|
|---|
| 123 |
|
|---|
| 124 | function TGList.Get(Index: TGListIndex): TGListItem;
|
|---|
| 125 | begin
|
|---|
| 126 | if (Index < 0) or (Index >= Count) then
|
|---|
| 127 | raise EListError.CreateFmt(SListIndexError, [Index]);
|
|---|
| 128 | Result := FItems[Index];
|
|---|
| 129 | end;
|
|---|
| 130 |
|
|---|
| 131 | procedure TGList.Put(Index: TGListIndex; const AValue: TGListItem);
|
|---|
| 132 | begin
|
|---|
| 133 | if (Index < 0) or (Index >= Count) then
|
|---|
| 134 | raise EListError.CreateFmt(SListIndexError, [Index]);
|
|---|
| 135 | FItems[Index] := AValue;
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 | procedure TGList.SetCount(const AValue: TGListIndex);
|
|---|
| 139 | begin
|
|---|
| 140 | if (AValue < 0) then
|
|---|
| 141 | raise EListError.CreateFmt(SListCountError, [AValue]);
|
|---|
| 142 | if AValue > Capacity then SetCapacityOptimized(AValue); // Before FCount change
|
|---|
| 143 | FCount := AValue;
|
|---|
| 144 | if AValue < Capacity then SetCapacityOptimized(AValue); // After FCount change
|
|---|
| 145 | end;
|
|---|
| 146 |
|
|---|
| 147 | function TGList.GetArray: TItemArray;
|
|---|
| 148 | var
|
|---|
| 149 | I: Integer;
|
|---|
| 150 | begin
|
|---|
| 151 | SetLength(Result, Count);
|
|---|
| 152 | I := 0;
|
|---|
| 153 | while I < Count do begin
|
|---|
| 154 | Result[I] := FItems[I];
|
|---|
| 155 | I := I + 1;
|
|---|
| 156 | end;
|
|---|
| 157 | end;
|
|---|
| 158 |
|
|---|
| 159 | procedure TGList.QuickSort(L, R: TGListIndex; Compare: TSortCompare);
|
|---|
| 160 | var
|
|---|
| 161 | I, J: TGListIndex;
|
|---|
| 162 | P, Q: TGListItem;
|
|---|
| 163 | begin
|
|---|
| 164 | repeat
|
|---|
| 165 | I := L;
|
|---|
| 166 | J := R;
|
|---|
| 167 | P := FItems[(L + R) div 2];
|
|---|
| 168 | repeat
|
|---|
| 169 | while Compare(P, FItems[I]) > 0 do
|
|---|
| 170 | I := I + 1;
|
|---|
| 171 | while Compare(P, FItems[J]) < 0 do
|
|---|
| 172 | J := J - 1;
|
|---|
| 173 | if I <= J then
|
|---|
| 174 | begin
|
|---|
| 175 | Q := FItems[I];
|
|---|
| 176 | FItems[I] := FItems[J];
|
|---|
| 177 | FItems[J] := Q;
|
|---|
| 178 | I := I + 1;
|
|---|
| 179 | J := J - 1;
|
|---|
| 180 | end;
|
|---|
| 181 | until I > J;
|
|---|
| 182 | if L < J then
|
|---|
| 183 | QuickSort(L, J, Compare);
|
|---|
| 184 | L := I;
|
|---|
| 185 | until I >= R;
|
|---|
| 186 | end;
|
|---|
| 187 |
|
|---|
| 188 | procedure TGList.Assign(Source: TGList);
|
|---|
| 189 | var
|
|---|
| 190 | I: TGListIndex;
|
|---|
| 191 | begin
|
|---|
| 192 | Count := Source.Count;
|
|---|
| 193 | I := 0;
|
|---|
| 194 | while I < Count do begin
|
|---|
| 195 | FItems[I] := Source[I];
|
|---|
| 196 | I := I + 1;
|
|---|
| 197 | end;
|
|---|
| 198 | end;
|
|---|
| 199 |
|
|---|
| 200 | function TGList.Extract(Item: TGListItem): TGListItem;
|
|---|
| 201 | var
|
|---|
| 202 | I: TGListIndex;
|
|---|
| 203 | begin
|
|---|
| 204 | I := IndexOf(Item);
|
|---|
| 205 | if I >= 0 then begin
|
|---|
| 206 | Result := Item;
|
|---|
| 207 | Delete(I);
|
|---|
| 208 | end else
|
|---|
| 209 | raise EListError.CreateFmt(SListIndexError, [0]);
|
|---|
| 210 | end;
|
|---|
| 211 |
|
|---|
| 212 | function TGList.CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
|
|---|
| 213 | var
|
|---|
| 214 | I: Cardinal;
|
|---|
| 215 | begin
|
|---|
| 216 | Result := True;
|
|---|
| 217 | I := 0;
|
|---|
| 218 | if (P1) <> (P2) then
|
|---|
| 219 | while Result and (I < Length) do
|
|---|
| 220 | begin
|
|---|
| 221 | Result := PByte(P1)^ = PByte(P2)^;
|
|---|
| 222 | Inc(I);
|
|---|
| 223 | Inc(pchar(P1));
|
|---|
| 224 | Inc(pchar(P2));
|
|---|
| 225 | end;
|
|---|
| 226 | end;
|
|---|
| 227 |
|
|---|
| 228 | function TGList.IndexOf(Item: TGListItem; Start: TGListIndex): TGListIndex;
|
|---|
| 229 | begin
|
|---|
| 230 | Result := Start;
|
|---|
| 231 | while (Result < FCount) and
|
|---|
| 232 | not CompareMem(@FItems[Result], @Item, SizeOf(TGListItem)) do
|
|---|
| 233 | // not (CompareByte(FItems[Result], Item, SizeOf(TGListItem)) = 0) do
|
|---|
| 234 | Result := Result + 1;
|
|---|
| 235 | if Result = FCount then Result := -1;
|
|---|
| 236 | end;
|
|---|
| 237 |
|
|---|
| 238 | procedure TGList.Insert(Index: TGListIndex; Item: TGListItem);
|
|---|
| 239 | begin
|
|---|
| 240 | if (Index < 0) or (Index > FCount ) then
|
|---|
| 241 | raise EListError.CreateFmt(SListIndexError, [Index]);
|
|---|
| 242 | if FCount = Capacity then SetCapacityOptimized(Capacity + 1);
|
|---|
| 243 | if Index < FCount then
|
|---|
| 244 | System.Move(FItems[Index], FItems[Index + 1], (FCount - Index) * SizeOf(TGListItem));
|
|---|
| 245 | FItems[Index] := Item;
|
|---|
| 246 | FCount := FCount + 1;
|
|---|
| 247 | end;
|
|---|
| 248 |
|
|---|
| 249 | procedure TGList.InsertList(Index: TGListIndex; List: TGList);
|
|---|
| 250 | var
|
|---|
| 251 | I: TGListIndex;
|
|---|
| 252 | begin
|
|---|
| 253 | I := 0;
|
|---|
| 254 | while (I < List.Count) do begin
|
|---|
| 255 | Insert(Index + I, List[I]);
|
|---|
| 256 | I := I + 1;
|
|---|
| 257 | end;
|
|---|
| 258 | end;
|
|---|
| 259 |
|
|---|
| 260 | function TGList.IndexOfList(List: TGList; Start: TGListIndex): TGListIndex;
|
|---|
| 261 | var
|
|---|
| 262 | I: TGListIndex;
|
|---|
| 263 | begin
|
|---|
| 264 | if List.Count > 0 then begin
|
|---|
| 265 | Result := IndexOf(List[0], Start);
|
|---|
| 266 | if Result <> -1 then begin
|
|---|
| 267 | I := 1;
|
|---|
| 268 | while I < List.Count do begin
|
|---|
| 269 | if not CompareMem(Addr(FItems[Result + I]), Addr(List.FItems[I]), SizeOf(TGListItem)) then begin
|
|---|
| 270 | Result := -1;
|
|---|
| 271 | Break;
|
|---|
| 272 | end;
|
|---|
| 273 | I := I + 1;
|
|---|
| 274 | end;
|
|---|
| 275 | end;
|
|---|
| 276 | end else Result := -1;
|
|---|
| 277 | end;
|
|---|
| 278 |
|
|---|
| 279 | function TGList.GetLast: TGListItem;
|
|---|
| 280 | begin
|
|---|
| 281 | if FCount = 0 then
|
|---|
| 282 | raise EListError.CreateFmt(SListIndexError, [0])
|
|---|
| 283 | else
|
|---|
| 284 | Result := FItems[FCount - 1];
|
|---|
| 285 | end;
|
|---|
| 286 |
|
|---|
| 287 | procedure TGList.SetLast(AValue: TGListItem);
|
|---|
| 288 | begin
|
|---|
| 289 | if FCount = 0 then
|
|---|
| 290 | raise EListError.CreateFmt(SListIndexError, [0])
|
|---|
| 291 | else
|
|---|
| 292 | FItems[FCount - 1] := AValue;
|
|---|
| 293 | end;
|
|---|
| 294 |
|
|---|
| 295 | function TGList.GetFirst: TGListItem;
|
|---|
| 296 | begin
|
|---|
| 297 | if FCount = 0 then
|
|---|
| 298 | raise EListError.CreateFmt(SListIndexError, [0])
|
|---|
| 299 | else
|
|---|
| 300 | Result := FItems[0];
|
|---|
| 301 | end;
|
|---|
| 302 |
|
|---|
| 303 | procedure TGList.SetFirst(AValue: TGListItem);
|
|---|
| 304 | begin
|
|---|
| 305 | if FCount = 0 then
|
|---|
| 306 | raise EListError.CreateFmt(SListIndexError, [0])
|
|---|
| 307 | else
|
|---|
| 308 | FItems[0] := AValue;
|
|---|
| 309 | end;
|
|---|
| 310 |
|
|---|
| 311 | procedure TGList.Move(CurIndex, NewIndex: TGListIndex);
|
|---|
| 312 | var
|
|---|
| 313 | Temp: TGListItem;
|
|---|
| 314 | begin
|
|---|
| 315 | if ((CurIndex < 0) or (CurIndex > Count - 1)) then
|
|---|
| 316 | raise EListError.CreateFmt(SListIndexError, [CurIndex]);
|
|---|
| 317 | if ((NewIndex < 0) or (NewIndex > Count -1)) then
|
|---|
| 318 | raise EListError.CreateFmt(SlistIndexError, [NewIndex]);
|
|---|
| 319 | Temp := FItems[CurIndex];
|
|---|
| 320 | if NewIndex > CurIndex then begin
|
|---|
| 321 | System.Move(FItems[CurIndex + 1], FItems[CurIndex], (NewIndex - CurIndex) * SizeOf(TGListItem));
|
|---|
| 322 | end else
|
|---|
| 323 | if NewIndex < CurIndex then begin
|
|---|
| 324 | System.Move(FItems[NewIndex], FItems[NewIndex + 1], (CurIndex - NewIndex) * SizeOf(TGListItem));
|
|---|
| 325 | end;
|
|---|
| 326 | FItems[NewIndex] := Temp;
|
|---|
| 327 | //Delete(CurIndex);
|
|---|
| 328 | //Insert(NewIndex, Temp);
|
|---|
| 329 | end;
|
|---|
| 330 |
|
|---|
| 331 | procedure TGList.MoveItems(CurIndex, NewIndex, Count: TGListIndex);
|
|---|
| 332 | var
|
|---|
| 333 | S: Integer;
|
|---|
| 334 | D: Integer;
|
|---|
| 335 | begin
|
|---|
| 336 | if CurIndex < NewIndex then begin
|
|---|
| 337 | S := CurIndex + Count - 1;
|
|---|
| 338 | D := NewIndex + Count - 1;
|
|---|
| 339 | while S >= CurIndex do begin
|
|---|
| 340 | Move(S, D);
|
|---|
| 341 | S := S - 1;
|
|---|
| 342 | D := D - 1;
|
|---|
| 343 | end;
|
|---|
| 344 | end else
|
|---|
| 345 | if CurIndex > NewIndex then begin
|
|---|
| 346 | S := CurIndex;
|
|---|
| 347 | D := NewIndex;
|
|---|
| 348 | while S < (CurIndex + Count) do begin
|
|---|
| 349 | Move(S, D);
|
|---|
| 350 | S := S + 1;
|
|---|
| 351 | D := D + 1;
|
|---|
| 352 | end;
|
|---|
| 353 | end;
|
|---|
| 354 | end;
|
|---|
| 355 |
|
|---|
| 356 | function TGList.Remove(Item: TGListItem): TGListIndex;
|
|---|
| 357 | begin
|
|---|
| 358 | Result := IndexOf(Item);
|
|---|
| 359 | if Result <> -1 then
|
|---|
| 360 | Delete(Result);
|
|---|
| 361 | end;
|
|---|
| 362 |
|
|---|
| 363 | function TGList.EqualTo(List: TGList): Boolean;
|
|---|
| 364 | var
|
|---|
| 365 | I: TGListIndex;
|
|---|
| 366 | begin
|
|---|
| 367 | Result := Count = List.Count;
|
|---|
| 368 | if Result then begin
|
|---|
| 369 | I := 0;
|
|---|
| 370 | while I < Count do begin
|
|---|
| 371 | if not CompareMem(Addr(FItems[I]), Addr(List.FItems[I]), SizeOf(TGListItem)) then begin
|
|---|
| 372 | Result := False;
|
|---|
| 373 | Break;
|
|---|
| 374 | end;
|
|---|
| 375 | I := I + 1;
|
|---|
| 376 | end;
|
|---|
| 377 | end;
|
|---|
| 378 | end;
|
|---|
| 379 |
|
|---|
| 380 | procedure TGList.Reverse;
|
|---|
| 381 | var
|
|---|
| 382 | I: TGListIndex;
|
|---|
| 383 | begin
|
|---|
| 384 | I := 0;
|
|---|
| 385 | while I < (Count div 2) do begin
|
|---|
| 386 | Exchange(I, Count - 1 - I);
|
|---|
| 387 | I := I + 1;
|
|---|
| 388 | end;
|
|---|
| 389 | end;
|
|---|
| 390 |
|
|---|
| 391 | procedure TGList.Sort(Compare: TSortCompare);
|
|---|
| 392 | begin
|
|---|
| 393 | if FCount > 1 then
|
|---|
| 394 | QuickSort(0, FCount - 1, Compare);
|
|---|
| 395 | end;
|
|---|
| 396 |
|
|---|
| 397 | procedure TGList.AddArray(Values: array of TGListItem);
|
|---|
| 398 | var
|
|---|
| 399 | I: TGListIndex;
|
|---|
| 400 | begin
|
|---|
| 401 | I := 0;
|
|---|
| 402 | while I <= High(Values) do begin
|
|---|
| 403 | Add(Values[I]);
|
|---|
| 404 | I := I + 1;
|
|---|
| 405 | end;
|
|---|
| 406 | end;
|
|---|
| 407 |
|
|---|
| 408 | procedure TGList.SetArray(Values: TItemArray);
|
|---|
| 409 | var
|
|---|
| 410 | I: TGListIndex;
|
|---|
| 411 | begin
|
|---|
| 412 | Clear;
|
|---|
| 413 | I := 0;
|
|---|
| 414 | while I <= High(Values) do begin
|
|---|
| 415 | Add(Values[I]);
|
|---|
| 416 | I := I + 1;
|
|---|
| 417 | end;
|
|---|
| 418 | end;
|
|---|
| 419 |
|
|---|
| 420 | procedure TGList.InsertArray(Index: TGListIndex; Values: array of TGListItem);
|
|---|
| 421 | var
|
|---|
| 422 | I: TGListIndex;
|
|---|
| 423 | begin
|
|---|
| 424 | I := 0;
|
|---|
| 425 | while I <= High(Values) do begin
|
|---|
| 426 | Insert(Index + I, Values[I]);
|
|---|
| 427 | I := I + 1;
|
|---|
| 428 | end;
|
|---|
| 429 | end;
|
|---|
| 430 |
|
|---|
| 431 | function TGList.Implode(Separator: string; Converter: TToStringConverter): string;
|
|---|
| 432 | var
|
|---|
| 433 | I: TGListIndex;
|
|---|
| 434 | begin
|
|---|
| 435 | Result := '';
|
|---|
| 436 | I := 0;
|
|---|
| 437 | while I < Count do begin
|
|---|
| 438 | Result := Result + Converter(FItems[I]);
|
|---|
| 439 | if I < (Count - 1) then
|
|---|
| 440 | Result := Result + Separator;
|
|---|
| 441 | I := I + 1;
|
|---|
| 442 | end;
|
|---|
| 443 | end;
|
|---|
| 444 |
|
|---|
| 445 | procedure TGList.Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
|
|---|
| 446 | begin
|
|---|
| 447 | Clear;
|
|---|
| 448 | while (Pos(Separator, Text) > 0) and
|
|---|
| 449 | ((Count < (SlicesCount - 1)) or (SlicesCount = -1)) do begin
|
|---|
| 450 | Add(Converter(Copy(Text, 1, Pos(Separator, Text) - 1)));
|
|---|
| 451 | System.Delete(Text, 1, Pos(Separator, Text) + Length(Separator) - 1);
|
|---|
| 452 | end;
|
|---|
| 453 | Add(Converter(Text));
|
|---|
| 454 | end;
|
|---|
| 455 |
|
|---|
| 456 | function TGList.Add(Item: TGListItem): TGListIndex;
|
|---|
| 457 | begin
|
|---|
| 458 | Count := Count + 1;
|
|---|
| 459 | Result := FCount - 1;
|
|---|
| 460 | FItems[Result] := Item;
|
|---|
| 461 | end;
|
|---|
| 462 |
|
|---|
| 463 | procedure TGList.AddList(List: TGList);
|
|---|
| 464 | var
|
|---|
| 465 | I: TGListIndex;
|
|---|
| 466 | begin
|
|---|
| 467 | I := 0;
|
|---|
| 468 | while I < List.Count do begin
|
|---|
| 469 | Add(List[I]);
|
|---|
| 470 | I := I + 1;
|
|---|
| 471 | end;
|
|---|
| 472 | end;
|
|---|
| 473 |
|
|---|
| 474 | procedure TGList.Clear;
|
|---|
| 475 | begin
|
|---|
| 476 | Count := 0;
|
|---|
| 477 | Capacity := 0;
|
|---|
| 478 | end;
|
|---|
| 479 |
|
|---|
| 480 | procedure TGList.Delete(Index: TGListIndex);
|
|---|
| 481 | begin
|
|---|
| 482 | if (Index < 0) or (Index >= FCount) then
|
|---|
| 483 | raise EListError.CreateFmt(SListIndexError, [Index]);
|
|---|
| 484 | FCount := FCount - 1;
|
|---|
| 485 | System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TGListItem));
|
|---|
| 486 | SetCapacityOptimized(Capacity - 1);
|
|---|
| 487 | end;
|
|---|
| 488 |
|
|---|
| 489 | procedure TGList.DeleteItems(Index, Count: TGListIndex);
|
|---|
| 490 | var
|
|---|
| 491 | I: TGListIndex;
|
|---|
| 492 | begin
|
|---|
| 493 | I := Index;
|
|---|
| 494 | while I < (Index + Count) do begin
|
|---|
| 495 | Delete(Index);
|
|---|
| 496 | I := I + 1;
|
|---|
| 497 | end;
|
|---|
| 498 | end;
|
|---|
| 499 |
|
|---|
| 500 | procedure TGList.Fill(Start, Count: TGListIndex; Value: TGListItem);
|
|---|
| 501 | var
|
|---|
| 502 | I: TGListIndex;
|
|---|
| 503 | begin
|
|---|
| 504 | I := Start;
|
|---|
| 505 | while I < Count do begin
|
|---|
| 506 | FItems[I] := Value;
|
|---|
| 507 | I := I + 1;
|
|---|
| 508 | end;
|
|---|
| 509 | end;
|
|---|
| 510 |
|
|---|
| 511 | procedure TGList.Exchange(Index1, Index2: TGListIndex);
|
|---|
| 512 | var
|
|---|
| 513 | Temp: TGListItem;
|
|---|
| 514 | begin
|
|---|
| 515 | if ((Index1 >= FCount) or (Index1 < 0)) then
|
|---|
| 516 | raise EListError.CreateFmt(SListIndexError, [Index1]);
|
|---|
| 517 | if ((Index2 >= FCount) or (Index2 < 0)) then
|
|---|
| 518 | raise EListError.CreateFmt(SListIndexError, [Index2]);
|
|---|
| 519 | Temp := FItems[Index1];
|
|---|
| 520 | FItems[Index1] := FItems[Index2];
|
|---|
| 521 | FItems[Index2] := Temp;
|
|---|
| 522 | end;
|
|---|
| 523 |
|
|---|
| 524 | {$UNDEF IMPLEMENTATION}
|
|---|
| 525 | {$ENDIF}
|
|---|