- Timestamp:
- Oct 27, 2010, 2:09:59 PM (14 years ago)
- Location:
- Generics/units
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/units/GenericList.pas
r37 r65 7 7 uses 8 8 Classes, SysUtils, fgl; 9 10 resourcestring 11 SNotImplemented = 'Not implememnted'; 9 12 10 13 type … … 48 51 property Capacity: TIndexType read GetCapacity write SetCapacity; 49 52 public 53 // All items 54 procedure Reverse; 55 procedure Clear; 56 procedure Expand; 57 procedure Sort(Compare: TGListSortCompare); 58 function Implode(Separator: string): string; 59 // Many items 60 procedure MoveItems(CurIndex, NewIndex, Count: TIndexType); 61 // One item 50 62 function Add(Item: TItemType): TIndexType; 51 function AddList(var Source): TIndexType;52 procedure Clear;53 63 procedure Delete(Index: TIndexType); 54 procedure DeleteItems(Index, Count: TIndexType);55 64 procedure Exchange(Index1, Index2: TIndexType); 56 procedure Expand;57 65 function Extract(Item: TItemType): TItemType; 58 function ExtractList(Item: TItemType; Count: TIndexType): TItemType;59 66 function First: TItemType; 60 67 function IndexOf(Item: TItemType): TIndexType; 61 68 procedure Insert(Index: TIndexType; Item: TItemType); 62 procedure InsertList(Index: TIndexType; var Source);63 69 function Last: TItemType; 64 70 procedure Move(CurIndex, NewIndex: TIndexType); 65 procedure MoveItems(CurIndex, NewIndex, Count: TIndexType);66 71 function Remove(Item: TItemType): TIndexType; 67 procedure Reverse;68 procedure Sort(Compare: TGListSortCompare);69 72 property Items[Index: TIndexType]: TItemType read Get write Put; default; 73 // List 74 function AddList(var Source): TIndexType; 75 procedure Assign(var List); 76 procedure DeleteItems(Index, Count: TIndexType); 77 function Equals(Obj: TObject): Boolean; override; 78 function ExtractList(Item: TItemType; Count: TIndexType): TItemType; 79 procedure InsertList(Index: TIndexType; var Source); 80 // Other 70 81 property Count: TIndexType read GetCount write SetCount; 82 // Additional 83 procedure SetArray(Values: array of TItemType); 71 84 end; 72 85 … … 157 170 P := FItems[ (L + R) div 2 ]; 158 171 repeat 159 while Compare(P, FItems[ i]) > 0 do172 while Compare(P, FItems[I]) > 0 do 160 173 I := I + 1; 161 174 while Compare(P, FItems[J]) < 0 do … … 176 189 end; 177 190 191 procedure TGList.Assign(var List); 192 var 193 I: Integer; 194 begin 195 (*Count := List.Count; 196 I := 0; 197 while I < Count do begin 198 Items[I] := List[I]; 199 end;*) 200 raise Exception.Create(SNotImplemented); 201 end; 202 178 203 procedure TGList.Expand; 179 204 var … … 191 216 function TGList.Extract(Item: TItemType): TItemType; 192 217 var 193 I: Integer;218 I: TIndexType; 194 219 begin 195 220 I := IndexOf(Item); … … 203 228 function TGList.ExtractList(Item: TItemType; Count: TIndexType): TItemType; 204 229 begin 205 230 raise Exception.Create(SNotImplemented); 206 231 end; 207 232 … … 243 268 end; 244 269 *) 270 raise Exception.Create(SNotImplemented); 245 271 end; 246 272 … … 268 294 procedure TGList.MoveItems(CurIndex, NewIndex, Count: TIndexType); 269 295 begin 270 296 raise Exception.Create(SNotImplemented); 271 297 end; 272 298 … … 278 304 end; 279 305 306 function TGList.Equals(Obj: TObject): Boolean; 307 var 308 I: TIndexType; 309 begin 310 (* Result := Count = List.Count; 311 if Result then begin 312 I := 0; 313 while I < Count do 314 if Items[I] <> List[I] then Result := False; 315 end; 316 *) 317 // Not implemented 318 raise Exception.Create(SNotImplemented); 319 Result := False; 320 end; 321 280 322 procedure TGList.Reverse; 281 323 begin 282 324 raise Exception.Create(SNotImplemented); 283 325 end; 284 326 … … 287 329 if FCount > 1 then 288 330 QuickSort(0, FCount - 1, Compare); 331 end; 332 333 procedure TGList.SetArray(Values: array of TItemType); 334 var 335 I: TIndexType; 336 begin 337 Clear; 338 I := 0; 339 while I <= High(Values) do begin 340 Add(Values[I]); 341 I := I + 1; 342 end; 343 end; 344 345 function TGList.Implode(Separator: string): string; 346 var 347 I: TIndexType; 348 begin 349 Result := ''; 350 I := 0; 351 while I < Count do begin 352 // Result := Result + string(Items[I]); 353 if I < (Count - 1) then 354 Result := Result + Separator; 355 I := I + 1; 356 end; 289 357 end; 290 358 … … 308 376 end; 309 377 *) 378 // Not implemented 379 Result := 0; 380 raise Exception.Create(SNotImplemented); 310 381 end; 311 382
Note:
See TracChangeset
for help on using the changeset viewer.