Ignore:
Timestamp:
Oct 31, 2010, 3:14:23 PM (14 years ago)
Author:
george
Message:
  • Modified: Thanks to compiler directives and simple macros specialized types was moved to one unit per base generic class. Directive $DEFINE is used to specify generic class template parameters which will be included to code. This approach enable to define more specialized types per unit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericDictionary.inc

    r83 r84  
    44
    55  TGPair = record
    6     Key: TDictionaryKey;
    7     Value: TDictionaryValue;
     6    Key: TGPairKey;
     7    Value: TGPairValue;
    88  end;
    99
    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'}
    1417
    15   // TGDictionary<TDictionaryIndex, TDictionaryKey, TDictionaryValue> = class(TGList)
     18  // TGDictionary<TGDictionaryIndex, TGPair<TGPairKey, TGPairValue>> = class(TGList)
    1619  TGDictionary = class(TGList)
    1720  private
    18     function GetKey(Index: TDictionaryIndex): TDictionaryKey;
    19     function GetValue(Key: TDictionaryKey): TDictionaryValue;
    20     procedure PutKey(Index: TDictionaryIndex; const AValue: TDictionaryKey);
    21     procedure PutValue(Key: TDictionaryKey; 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);
    2225  public
    23     function SearchKey(Key: TDictionaryKey): TDictionaryIndex;
    24     procedure Add(Key: TDictionaryKey; Value: TDictionaryValue);
    25     property Values[Index: TDictionaryKey]: TDictionaryValue
     26    function SearchKey(Key: TGPairKey): TGDictionaryIndex;
     27    procedure Add(Key: TGPairKey; Value: TGPairValue);
     28    property Values[Index: TGPairKey]: TGPairValue
    2629      read GetValue write PutValue;
    27     property Keys[Index: TDictionaryIndex]: TDictionaryKey
     30    property Keys[Index: TGDictionaryIndex]: TGPairKey
    2831      read GetKey write PutKey;
    2932  end;
     
    3437{$IFDEF IMPLEMENTATION}
    3538
     39{$UNDEF IMPLEMENTATION}
     40{$DEFINE IMPLEMENTATION_USES}
     41{$INCLUDE '..\Generic\GenericList.inc'}
    3642
     43{$DEFINE TGListIndex := TGDictionaryIndex}
     44{$DEFINE TGListItem := TGPair}
     45{$DEFINE TGList := TGDictionaryList}
     46{$DEFINE TGListSortCompare := TDictionarySortCompare}
     47{$DEFINE TGListStringConverter := TDictionaryStringConverter}
    3748{$DEFINE IMPLEMENTATION}
    3849{$INCLUDE 'GenericList.inc'}
    3950
    40 function TGDictionary.GetKey(Index: TDictionaryIndex): TDictionaryKey;
     51function TGDictionary.GetKey(Index: TGDictionaryIndex): TGPairKey;
    4152begin
    4253  Result := Items[Index].Key;
    4354end;
    4455
    45 function TGDictionary.GetValue(Key: TDictionaryKey): TDictionaryValue;
     56function TGDictionary.GetValue(Key: TGPairKey): TGPairValue;
    4657begin
    4758  Result := Items[SearchKey(Key)].Value;
    4859end;
    4960
    50 procedure TGDictionary.PutKey(Index: TDictionaryIndex;
    51   const AValue: TDictionaryKey);
     61procedure TGDictionary.PutKey(Index: TGDictionaryIndex;
     62  const AValue: TGPairKey);
    5263var
    5364  Item: TGPair;
     
    5970end;
    6071
    61 procedure TGDictionary.PutValue(Key: TDictionaryKey;
    62   const AValue: TDictionaryValue);
     72procedure TGDictionary.PutValue(Key: TGPairKey;
     73  const AValue: TGPairValue);
    6374var
    6475  Item: TGPair;
    65   Index: TDictionaryIndex;
     76  Index: TGDictionaryIndex;
    6677begin
    6778  //Items[SearchKey(Index)].Value := AValue;
     
    7283end;
    7384
    74 function TGDictionary.SearchKey(Key: TDictionaryKey): TDictionaryIndex;
     85function TGDictionary.SearchKey(Key: TGPairKey): TGDictionaryIndex;
    7586begin
    7687  Result := 0;
     
    8394end;
    8495
    85 procedure TGDictionary.Add(Key: TDictionaryKey; Value: TDictionaryValue);
     96procedure TGDictionary.Add(Key: TGPairKey; Value: TGPairValue);
    8697var
    8798  NewPair: TGPair;
     
    92103end;
    93104
     105{$UNDEF IMPLEMENTATION}
    94106{$ENDIF}
Note: See TracChangeset for help on using the changeset viewer.