Changeset 320 for Generics/NativeGenerics/Units
- Timestamp:
- Feb 7, 2012, 2:03:20 PM (13 years ago)
- Location:
- Generics/NativeGenerics/Units
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified Generics/NativeGenerics/Units/GenericDictionary.pas ¶
r132 r320 14 14 end; 15 15 16 TGDictionary<T Pair> = class(TGList<TPair>)16 TGDictionary<TKey, TValue> = class 17 17 private 18 18 type 19 TGDictionaryIndex = Integer; 19 TIndex = NativeInt; 20 TDictionaryPair = TGPair<TKey, TValue>; 20 21 var 21 function GetKey(Index: TGDictionaryIndex): TPair.TKey; 22 function GetValue(Key: TPair.TKey): TPair.TValue; 23 procedure PutKey(Index: TGDictionaryIndex; const AValue: TPair.TKey); 24 procedure PutValue(Key: TPair.TKey; const AValue: TPair.TValue); 22 FList: TGList<TDictionaryPair>; 23 function GetKey(Index: TIndex): TKey; 24 function GetValue(Key: TKey): TValue; 25 procedure PutKey(Index: TIndex; const AValue: TKey); 26 procedure PutValue(Key: TKey; const AValue: TValue); 25 27 public 26 function SearchKey(Key: TPair.TKey): TGDictionaryIndex; 27 procedure Add(Key: TPair.TKey; Value: TPair.TValue); 28 property Values[Index: TPair.TKey]: TPair.TValue 28 constructor Create; 29 destructor Destroy; override; 30 function SearchKey(Key: TKey): TIndex; 31 procedure Add(Key: TKey; Value: TValue); 32 property Values[Index: TKey]: TValue 29 33 read GetValue write PutValue; 30 property Keys[Index: T GDictionaryIndex]: TPair.TKey34 property Keys[Index: TIndex]: TKey 31 35 read GetKey write PutKey; 36 property List: TGList<TDictionaryPair> read FList; 32 37 end; 33 38 … … 35 40 36 41 37 function TGDictionary<TPair>.GetKey(Index: TGDictionaryIndex): TPair.TKey;42 constructor TGDictionary<TKey, TValue>.Create; 38 43 begin 39 Result := Items[Index].Key;44 FList := TGList<TDictionaryPair>.Create; 40 45 end; 41 46 42 function TGDictionary<TPair>.GetValue(Key: TPair.TKey): TPair.TValue;47 destructor TGDictionary<TKey, TValue>.Destroy; 43 48 begin 44 Result := Items[SearchKey(Key)].Value;49 FList.Free; 45 50 end; 46 51 47 procedure TGDictionary<TPair>.PutKey(Index: TGDictionaryIndex; 48 const AValue: TPair.TKey); 52 function TGDictionary<TKey, TValue>.GetKey(Index: TIndex): TKey; 53 begin 54 Result := FList.Items[Index].Key; 55 end; 56 57 function TGDictionary<TKey, TValue>.GetValue(Key: TKey): TValue; 58 begin 59 Result := FList.Items[SearchKey(Key)].Value; 60 end; 61 62 procedure TGDictionary<TKey, TValue>.PutKey(Index: TIndex; 63 const AValue: TKey); 49 64 var 50 Item: T Pair;65 Item: TDictionaryPair; 51 66 begin 52 67 //Items[Index].Key := AValue; 53 Item := Items[Index];68 Item := FList.Items[Index]; 54 69 Item.Key := AValue; 55 Items[Index] := Item;70 FList.Items[Index] := Item; 56 71 end; 57 72 58 procedure TGDictionary<T Pair>.PutValue(Key: TPair.TKey;59 const AValue: T Pair.TValue);73 procedure TGDictionary<TKey, TValue>.PutValue(Key: TKey; 74 const AValue: TValue); 60 75 var 61 Item: T Pair;62 Index: T GDictionaryIndex;76 Item: TDictionaryPair; 77 Index: TIndex; 63 78 begin 64 79 //Items[SearchKey(Index)].Value := AValue; 65 80 Index := SearchKey(Key); 66 Item := Items[Index];81 Item := FList.Items[Index]; 67 82 Item.Value := AValue; 68 Items[Index] := Item;83 FList.Items[Index] := Item; 69 84 end; 70 85 71 function TGDictionary<T Pair>.SearchKey(Key: TPair.TKey): TGDictionaryIndex;86 function TGDictionary<TKey, TValue>.SearchKey(Key: TKey): TIndex; 72 87 begin 73 88 Result := 0; 74 while Result < Count do begin75 if Items[Result].Key = Key then begin89 while Result < FList.Count do begin 90 if FList.Items[Result].Key = Key then begin 76 91 Break; 77 92 end; … … 80 95 end; 81 96 82 procedure TGDictionary<T Pair>.Add(Key: TPair.TKey; Value: TPair.TValue);97 procedure TGDictionary<TKey, TValue>.Add(Key: TKey; Value: TValue); 83 98 var 84 NewPair: T Pair;99 NewPair: TDictionaryPair; 85 100 begin 86 101 NewPair.Key := Key; 87 102 NewPair.Value := Value; 88 inheritedAdd(NewPair);103 FList.Add(NewPair); 89 104 end; 90 105 -
TabularUnified Generics/NativeGenerics/Units/GenericList.pas ¶
r313 r320 34 34 function Add(Item: TItem): TIndex; 35 35 procedure AddArray(Values: array of TItem); 36 procedure AddList(List: TGList );37 procedure Assign(Source: TGList ); virtual;36 procedure AddList(List: TGList<TItem>); 37 procedure Assign(Source: TGList<TItem>); virtual; 38 38 procedure Clear; virtual; 39 39 procedure Delete(Index: TIndex); virtual; 40 40 procedure DeleteItems(Index, Count: TIndex); 41 function EqualTo(List: TGList ): Boolean;41 function EqualTo(List: TGList<TItem>): Boolean; 42 42 procedure Exchange(Index1, Index2: TIndex); 43 43 procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); … … 48 48 function Implode(Separator: string; Converter: TToStringConverter): string; 49 49 function IndexOf(Item: TItem; Start: TIndex = 0): TIndex; 50 function IndexOfList(List: TGList ; Start: TIndex = 0): TIndex;50 function IndexOfList(List: TGList<TItem>; Start: TIndex = 0): TIndex; 51 51 procedure Insert(Index: TIndex; Item: TItem); 52 procedure InsertList(Index: TIndex; List: TGList );52 procedure InsertList(Index: TIndex; List: TGList<TItem>); 53 53 procedure InsertArray(Index: TIndex; Values: array of TItem); 54 54 procedure Move(CurIndex, NewIndex: TIndex); … … 64 64 end; 65 65 66 T GListObject<TItem> = class(TGList<TItem>)66 TListObject<TItem> = class(TGList<TItem>) 67 67 private 68 68 procedure Put(Index: Integer; const AValue: TItem); override; … … 76 76 end; 77 77 78 T GListString<TItem> = class(TGList<TItem>)78 TListString<TItem> = class(TGList<TItem>) 79 79 private 80 80 public … … 93 93 RtlConsts; 94 94 95 { TGList }95 { TGList<TItem> } 96 96 97 97 function TGList<TItem>.GetCapacity: TIndex; … … 195 195 end; 196 196 197 procedure TGList<TItem>.Assign(Source: TGList );197 procedure TGList<TItem>.Assign(Source: TGList<TItem>); 198 198 var 199 199 I: TIndex; … … 239 239 end; 240 240 241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList );241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList<TItem>); 242 242 var 243 243 I: TIndex; … … 250 250 end; 251 251 252 function TGList<TItem>.IndexOfList(List: TGList ; Start: TIndex): TIndex;252 function TGList<TItem>.IndexOfList(List: TGList<TItem>; Start: TIndex): TIndex; 253 253 var 254 254 I: TIndex; … … 353 353 end; 354 354 355 function TGList<TItem>.EqualTo(List: TGList ): Boolean;355 function TGList<TItem>.EqualTo(List: TGList<TItem>): Boolean; 356 356 var 357 357 I: TIndex; … … 453 453 end; 454 454 455 procedure TGList<TItem>.AddList(List: TGList );455 procedure TGList<TItem>.AddList(List: TGList<TItem>); 456 456 var 457 457 I: TIndex; … … 514 514 end; 515 515 516 { T GListObject }517 518 procedure T GListObject<TItem>.Assign(Source: TGList<TItem>);516 { TListObject } 517 518 procedure TListObject<TItem>.Assign(Source: TGList<TItem>); 519 519 begin 520 520 Clear; … … 523 523 end; 524 524 525 procedure T GListObject<TItem>.Put(Index: Integer; const AValue: TItem);525 procedure TListObject<TItem>.Put(Index: Integer; const AValue: TItem); 526 526 begin 527 527 if OwnsObjects then FItems[Index].Free; … … 529 529 end; 530 530 531 procedure T GListObject<TItem>.Delete(Index: Integer);531 procedure TListObject<TItem>.Delete(Index: Integer); 532 532 begin 533 533 if OwnsObjects then FItems[Index].Free; … … 535 535 end; 536 536 537 procedure T GListObject<TItem>.Clear;537 procedure TListObject<TItem>.Clear; 538 538 var 539 539 I: Integer; … … 549 549 end; 550 550 551 constructor T GListObject<TItem>.Create;551 constructor TListObject<TItem>.Create; 552 552 begin 553 553 inherited; … … 555 555 end; 556 556 557 destructor T GListObject<TItem>.Destroy;557 destructor TListObject<TItem>.Destroy; 558 558 begin 559 559 Clear; … … 561 561 end; 562 562 563 { T GListString }564 565 procedure T GListString<TItem>.Assign(Source: TGList<TItem>);563 { TListString } 564 565 procedure TListString<TItem>.Assign(Source: TGList<TItem>); 566 566 begin 567 567 Clear; … … 569 569 end; 570 570 571 procedure T GListString<TItem>.Delete(Index: Integer);571 procedure TListString<TItem>.Delete(Index: Integer); 572 572 begin 573 573 FItems[Index] := ''; … … 575 575 end; 576 576 577 procedure T GListString<TItem>.Clear;577 procedure TListString<TItem>.Clear; 578 578 var 579 579 I: Integer; … … 587 587 end; 588 588 589 constructor T GListString<TItem>.Create;589 constructor TListString<TItem>.Create; 590 590 begin 591 591 inherited; 592 592 end; 593 593 594 destructor T GListString<TItem>.Destroy;594 destructor TListString<TItem>.Destroy; 595 595 begin 596 596 Clear; -
TabularUnified Generics/NativeGenerics/Units/GenericQueue.pas ¶
r132 r320 11 11 TGQueue<TItem> = class 12 12 private 13 type14 TGQueueList = TGList<TItem>;15 13 var 16 FList: TG QueueList;14 FList: TGList<TItem>; 17 15 public 18 16 procedure Enqueue(Value: TItem); … … 21 19 constructor Create; 22 20 destructor Destroy; override; 23 property List: TG QueueListread FList;21 property List: TGList<TItem> read FList; 24 22 end; 25 23 … … 40 38 constructor TGQueue<TItem>.Create; 41 39 begin 42 FList := TGList .Create;40 FList := TGList<TItem>.Create; 43 41 end; 44 42 -
TabularUnified Generics/NativeGenerics/Units/GenericSet.pas ¶
r132 r320 11 11 TGSet<TItem> = class 12 12 private 13 type14 TGSetList = TGList<TItem>;15 13 var 16 FList: TG SetList;14 FList: TGList<TItem>; 17 15 public 18 16 function IsIn(Item: TItem): Boolean; 19 17 constructor Create; 20 18 destructor Destroy; override; 21 property List: TG SetListread FList;19 property List: TGList<TItem> read FList; 22 20 end; 23 21 … … 33 31 constructor TGSet<TItem>.Create; 34 32 begin 35 FList := TGList .Create;33 FList := TGList<TItem>.Create; 36 34 end; 37 35 -
TabularUnified Generics/NativeGenerics/Units/GenericStack.pas ¶
r132 r320 11 11 TGStack<TItem> = class 12 12 private 13 type14 TGStackList = TGList<TItem>;15 13 var 16 FList: TG StackList;14 FList: TGList<TItem>; 17 15 public 18 16 procedure Push(Value: TItem); … … 20 18 constructor Create; 21 19 destructor Destroy; override; 22 property List: TG StackListread FList;20 property List: TGList<TItem> read FList; 23 21 end; 24 22 … … 38 36 constructor TGStack<TItem>.Create; 39 37 begin 40 FList := TGList .Create;38 FList := TGList<TItem>.Create; 41 39 end; 42 40 -
TabularUnified Generics/NativeGenerics/Units/GenericStream.pas ¶
r313 r320 1 1 unit GenericStream; 2 2 3 {$mode Delphi}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils;8 SysUtils, Classes, GenericList; 9 9 10 10 type 11 11 TGStream<TItem> = class 12 public 13 type 14 TIndex = NativeInt; 15 TItemArray = array of TItem; 16 TSeekOrigin = (soBeginning, soCurrent, soEnd); 17 private 18 procedure SetSize(AValue: TIndex); 19 function GetSize: TIndex; 20 procedure SetPosition(AValue: TIndex); 21 function GetPosition: TIndex; 22 public 23 procedure Assign(Source: TGStream<TItem>); virtual; 24 procedure Write(Item: TItem); virtual; abstract; 25 procedure WriteArray(Item: array of TItem); virtual; abstract; 26 function Read: TItem; virtual; abstract; 27 function ReadArray(Count: TIndex): TItemArray; virtual; abstract; 28 function Insert(Count: TIndex): TIndex; virtual; abstract; 29 function Remove(Count: TIndex): TIndex; virtual; abstract; 30 function Seek(Offset: TIndex; Origin: TSeekOrigin = soCurrent): 31 TIndex; virtual; abstract; 32 constructor Create; virtual; 33 property Position: TIndex read GetPosition write SetPosition; 34 property Size: TIndex read GetSize write SetSize; 35 end; 12 36 13 end;14 37 15 38 implementation 16 39 40 41 procedure TGStream<TItem>.Assign(Source: TGStream<TItem>); 42 begin 43 end; 44 45 procedure TGStream<TItem>.SetPosition(AValue: TIndex); 46 begin 47 Seek(AValue, soBeginning); 48 end; 49 50 function TGStream<TItem>.GetPosition: TIndex; 51 begin 52 Result := Seek(0, soCurrent); 53 end; 54 55 procedure TGStream<TItem>.SetSize(AValue: TIndex); 56 var 57 StreamSize: TIndex; 58 OldPosition: TIndex; 59 begin 60 OldPosition := Seek(0, soCurrent); 61 StreamSize := Size; 62 if AValue > StreamSize then begin 63 Seek(StreamSize, soBeginning); 64 Insert(AValue - StreamSize); 65 end else 66 if AValue < StreamSize then begin 67 Seek(AValue, soBeginning); 68 Remove(StreamSize - AValue); 69 end; 70 Position := OldPosition; 71 end; 72 73 function TGStream<TItem>.GetSize: TIndex; 74 var 75 OldPosition: Integer; 76 begin 77 OldPosition := Position; 78 Result := Seek(0, soEnd); 79 Position := OldPosition; 80 end; 81 82 constructor TGStream<TItem>.Create; 83 begin 84 inherited; 85 end; 86 17 87 end. 18
Note:
See TracChangeset
for help on using the changeset viewer.