Ignore:
Timestamp:
Oct 27, 2010, 9:28:58 PM (14 years ago)
Author:
george
Message:
  • Added: Demo application.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/List/GenericListImplementation.tpl

    r68 r69  
    1010{ TGList }
    1111
    12 function TGList.GetCapacity: TIndexType;
     12function TGList.GetCapacity: TListIndex;
    1313begin
    1414  Result := Length(FItems);
    1515end;
    1616
    17 procedure TGList.SetCapacity(const AValue: TIndexType);
     17procedure TGList.SetCapacity(const AValue: TListIndex);
    1818begin
    1919  SetLength(FItems, AValue);
    2020end;
    2121
    22 function TGList.Get(Index: TIndexType): TItemType;
     22function TGList.Get(Index: TListIndex): TListItem;
    2323begin
    2424  Result := FItems[Index];
    2525end;
    2626
    27 function TGList.GetCount: TIndexType;
     27function TGList.GetCount: TListIndex;
    2828begin
    2929  Result := FCount;
    3030end;
    3131
    32 procedure TGList.Put(Index: TIndexType; const AValue: TItemType);
     32procedure TGList.Put(Index: TListIndex; const AValue: TListItem);
    3333begin
    3434  FItems[Index] := AValue;
    3535end;
    3636
    37 procedure TGList.SetCount(const AValue: TIndexType);
     37procedure TGList.SetCount(const AValue: TListIndex);
    3838begin
    3939  SetLength(FItems, AValue);
     
    4141end;
    4242
    43 procedure TGList.QuickSort(L, R: TIndexType; Compare: TGListSortCompare);
    44 var
    45   I, J: TIndexType;
    46   P, Q: TItemType;
     43procedure TGList.QuickSort(L, R: TListIndex; Compare: TGListSortCompare);
     44var
     45  I, J: TListIndex;
     46  P, Q: TListItem;
    4747begin
    4848 repeat
     
    8484procedure TGList.Expand;
    8585var
    86   IncSize: TIndexType;
     86  IncSize: TListIndex;
    8787begin
    8888  if FCount = Capacity then begin
     
    9595end;
    9696
    97 function TGList.Extract(Item: TItemType): TItemType;
    98 var
    99   I: TIndexType;
     97function TGList.Extract(Item: TListItem): TListItem;
     98var
     99  I: TListIndex;
    100100begin
    101101  I := IndexOf(Item);
     
    107107end;
    108108
    109 function TGList.ExtractList(Item: TItemType; Count: TIndexType): TItemType;
     109function TGList.ExtractList(Item: TListItem; Count: TListIndex): TListItem;
    110110begin
    111111  raise Exception.Create(SNotImplemented);
    112112end;
    113113
    114 function TGList.First: TItemType;
     114function TGList.First: TListItem;
    115115begin
    116116  if FCount = 0 then
     
    120120end;
    121121
    122 function TGList.IndexOf(Item: TItemType): TIndexType;
     122function TGList.IndexOf(Item: TListItem): TListIndex;
    123123begin
    124124  Result := 0;
     
    128128end;
    129129
    130 procedure TGList.Insert(Index: TIndexType; Item: TItemType);
     130procedure TGList.Insert(Index: TListIndex; Item: TListItem);
    131131begin
    132132  if (Index < 0) or (Index > FCount ) then
     
    134134  if FCount = Capacity then Expand;
    135135  if Index < FCount then
    136     SystemMove(FItems[Index], FItems[Index + 1], (FCount - Index) * SizeOf(TItemType));
     136    SystemMove(FItems[Index], FItems[Index + 1], (FCount - Index) * SizeOf(TListItem));
    137137  FItems[Index] := Item;
    138138  FCount := FCount + 1;
    139139end;
    140140
    141 procedure TGList.InsertList(Index: TIndexType; List: TGList);
    142 var
    143   I: TIndexType;
     141procedure TGList.InsertList(Index: TListIndex; List: TGList);
     142var
     143  I: TListIndex;
    144144begin
    145145  I := 0;
     
    150150end;
    151151
    152 function TGList.Last: TItemType;
     152function TGList.Last: TListItem;
    153153begin
    154154  if FCount = 0 then
     
    158158end;
    159159
    160 procedure TGList.Move(CurIndex, NewIndex: TIndexType);
    161 var
    162   Temp: TItemType;
     160procedure TGList.Move(CurIndex, NewIndex: TListIndex);
     161var
     162  Temp: TListItem;
    163163begin
    164164  if ((CurIndex < 0) or (CurIndex > Count - 1)) then
     
    171171end;
    172172
    173 procedure TGList.MoveItems(CurIndex, NewIndex, Count: TIndexType);
     173procedure TGList.MoveItems(CurIndex, NewIndex, Count: TListIndex);
    174174begin
    175175  raise Exception.Create(SNotImplemented);
    176176end;
    177177
    178 function TGList.Remove(Item: TItemType): TIndexType;
     178procedure TGList.Swap(Index1, Index2: TListIndex);
     179var
     180  Temp: TListItem;
     181begin
     182  Temp := Items[Index1];
     183  Items[Index1] := Items[Index2];
     184  Items[Index2] := Temp;
     185end;
     186
     187function TGList.Remove(Item: TListItem): TListIndex;
    179188begin
    180189  Result := IndexOf(Item);
     
    183192end;
    184193
    185 function TGList.Equals(Obj: TObject): Boolean;
    186 var
    187   I: TIndexType;
     194(*function TGList.Equals(Obj: TObject): Boolean;
     195var
     196  I: TListIndex;
    188197begin
    189198  Result := Count = (Obj as TGList).Count;
     
    198207    end;
    199208  end;
    200 end;
     209end;*)
    201210
    202211procedure TGList.Reverse;
    203 begin
    204   raise Exception.Create(SNotImplemented);
     212var
     213  I: TListIndex;
     214begin
     215  I := 0;
     216  while I < (Count div 2) do begin
     217    Swap(I, Count - 1 - I);
     218    I := I + 1;
     219  end;
    205220end;
    206221
     
    211226end;
    212227
    213 procedure TGList.SetArray(Values: array of TItemType);
    214 var
    215   I: TIndexType;
     228procedure TGList.SetArray(Values: array of TListItem);
     229var
     230  I: TListIndex;
    216231begin
    217232  Clear;
     
    223238end;
    224239
    225 function TGList.Implode(Separator: string): string;
    226 var
    227   I: TIndexType;
     240function TGList.Implode(Separator: string; Converter: TGListStringConverter): string;
     241var
     242  I: TListIndex;
    228243begin
    229244  Result := '';
    230245  I := 0;
    231246  while I < Count do begin
    232     Result := Result + string(Items[I]);
     247    Result := Result + Converter(Items[I]);
    233248    if I < (Count - 1) then
    234249      Result := Result + Separator;
     
    237252end;
    238253
    239 function TGList.Add(Item: TItemType): TIndexType;
     254function TGList.Add(Item: TListItem): TListIndex;
    240255begin
    241256  if FCount = Capacity then
     
    248263procedure TGList.AddList(List: TGList);
    249264var
    250   I: TIndexType;
     265  I: TListIndex;
    251266begin
    252267  I := 0;
     
    263278end;
    264279
    265 procedure TGList.Delete(Index: TIndexType);
     280procedure TGList.Delete(Index: TListIndex);
    266281begin
    267282  if (Index < 0) or (Index >= FCount) then
    268283    raise EListError.CreateFmt(SListIndexError, [Index]);
    269284  FCount := FCount - 1;
    270   SystemMove(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TItemType));
     285  SystemMove(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem));
    271286  // Shrink the list if appropriate
    272287  if (Capacity > 256) and (FCount < Capacity shr 2) then
     
    276291end;
    277292
    278 procedure TGList.DeleteItems(Index, Count: TIndexType);
    279 var
    280   I: TIndexType;
     293procedure TGList.DeleteItems(Index, Count: TListIndex);
     294var
     295  I: TListIndex;
    281296begin
    282297  I := 0;
     
    287302end;
    288303
    289 procedure TGList.Exchange(Index1, Index2: TIndexType);
    290 var
    291   Temp: TItemType;
     304procedure TGList.Exchange(Index1, Index2: TListIndex);
     305var
     306  Temp: TListItem;
    292307begin
    293308  if ((Index1 >= FCount) or (Index1 < 0)) then
Note: See TracChangeset for help on using the changeset viewer.