Changeset 84 for Generics/TemplateGenerics/Generic/GenericDictionary.inc
- Timestamp:
- Oct 31, 2010, 3:14:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/GenericDictionary.inc
r83 r84 4 4 5 5 TGPair = record 6 Key: T DictionaryKey;7 Value: T DictionaryValue;6 Key: TGPairKey; 7 Value: TGPairValue; 8 8 end; 9 9 10 TListIndex = TDictionaryIndex; 11 TListItem = TGPair; 12 {$DEFINE INTERFACE} 13 {$INCLUDE 'GenericList.inc'} 10 {$DEFINE TGListIndex := TGDictionaryIndex} 11 {$DEFINE TGListItem := TGPair} 12 {$DEFINE TGList := TGDictionaryList} 13 {$DEFINE TGListSortCompare := TDictionarySortCompare} 14 {$DEFINE TGListStringConverter := TDictionaryStringConverter} 15 {$DEFINE INTERFACE} 16 {$INCLUDE 'GenericList.inc'} 14 17 15 // TGDictionary<T DictionaryIndex, TDictionaryKey, TDictionaryValue> = class(TGList)18 // TGDictionary<TGDictionaryIndex, TGPair<TGPairKey, TGPairValue>> = class(TGList) 16 19 TGDictionary = class(TGList) 17 20 private 18 function GetKey(Index: T DictionaryIndex): TDictionaryKey;19 function GetValue(Key: T DictionaryKey): TDictionaryValue;20 procedure PutKey(Index: T DictionaryIndex; const AValue: TDictionaryKey);21 procedure PutValue(Key: T DictionaryKey; const AValue: TDictionaryValue);21 function GetKey(Index: TGDictionaryIndex): TGPairKey; 22 function GetValue(Key: TGPairKey): TGPairValue; 23 procedure PutKey(Index: TGDictionaryIndex; const AValue: TGPairKey); 24 procedure PutValue(Key: TGPairKey; const AValue: TGPairValue); 22 25 public 23 function SearchKey(Key: T DictionaryKey): TDictionaryIndex;24 procedure Add(Key: T DictionaryKey; Value: TDictionaryValue);25 property Values[Index: T DictionaryKey]: TDictionaryValue26 function SearchKey(Key: TGPairKey): TGDictionaryIndex; 27 procedure Add(Key: TGPairKey; Value: TGPairValue); 28 property Values[Index: TGPairKey]: TGPairValue 26 29 read GetValue write PutValue; 27 property Keys[Index: T DictionaryIndex]: TDictionaryKey30 property Keys[Index: TGDictionaryIndex]: TGPairKey 28 31 read GetKey write PutKey; 29 32 end; … … 34 37 {$IFDEF IMPLEMENTATION} 35 38 39 {$UNDEF IMPLEMENTATION} 40 {$DEFINE IMPLEMENTATION_USES} 41 {$INCLUDE '..\Generic\GenericList.inc'} 36 42 43 {$DEFINE TGListIndex := TGDictionaryIndex} 44 {$DEFINE TGListItem := TGPair} 45 {$DEFINE TGList := TGDictionaryList} 46 {$DEFINE TGListSortCompare := TDictionarySortCompare} 47 {$DEFINE TGListStringConverter := TDictionaryStringConverter} 37 48 {$DEFINE IMPLEMENTATION} 38 49 {$INCLUDE 'GenericList.inc'} 39 50 40 function TGDictionary.GetKey(Index: T DictionaryIndex): TDictionaryKey;51 function TGDictionary.GetKey(Index: TGDictionaryIndex): TGPairKey; 41 52 begin 42 53 Result := Items[Index].Key; 43 54 end; 44 55 45 function TGDictionary.GetValue(Key: T DictionaryKey): TDictionaryValue;56 function TGDictionary.GetValue(Key: TGPairKey): TGPairValue; 46 57 begin 47 58 Result := Items[SearchKey(Key)].Value; 48 59 end; 49 60 50 procedure TGDictionary.PutKey(Index: T DictionaryIndex;51 const AValue: T DictionaryKey);61 procedure TGDictionary.PutKey(Index: TGDictionaryIndex; 62 const AValue: TGPairKey); 52 63 var 53 64 Item: TGPair; … … 59 70 end; 60 71 61 procedure TGDictionary.PutValue(Key: T DictionaryKey;62 const AValue: T DictionaryValue);72 procedure TGDictionary.PutValue(Key: TGPairKey; 73 const AValue: TGPairValue); 63 74 var 64 75 Item: TGPair; 65 Index: T DictionaryIndex;76 Index: TGDictionaryIndex; 66 77 begin 67 78 //Items[SearchKey(Index)].Value := AValue; … … 72 83 end; 73 84 74 function TGDictionary.SearchKey(Key: T DictionaryKey): TDictionaryIndex;85 function TGDictionary.SearchKey(Key: TGPairKey): TGDictionaryIndex; 75 86 begin 76 87 Result := 0; … … 83 94 end; 84 95 85 procedure TGDictionary.Add(Key: T DictionaryKey; Value: TDictionaryValue);96 procedure TGDictionary.Add(Key: TGPairKey; Value: TGPairValue); 86 97 var 87 98 NewPair: TGPair; … … 92 103 end; 93 104 105 {$UNDEF IMPLEMENTATION} 94 106 {$ENDIF}
Note:
See TracChangeset
for help on using the changeset viewer.