Ignore:
Timestamp:
Feb 7, 2012, 2:03:20 PM (13 years ago)
Author:
chronos
Message:
Location:
Generics/NativeGenerics/Units
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified Generics/NativeGenerics/Units/GenericDictionary.pas

    r132 r320  
    1414  end;
    1515
    16   TGDictionary<TPair> = class(TGList<TPair>)
     16  TGDictionary<TKey, TValue> = class
    1717  private
    1818  type
    19     TGDictionaryIndex = Integer;
     19    TIndex = NativeInt;
     20    TDictionaryPair = TGPair<TKey, TValue>;
    2021  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);
    2527  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
    2933      read GetValue write PutValue;
    30     property Keys[Index: TGDictionaryIndex]: TPair.TKey
     34    property Keys[Index: TIndex]: TKey
    3135      read GetKey write PutKey;
     36    property List: TGList<TDictionaryPair> read FList;
    3237  end;
    3338
     
    3540
    3641
    37 function TGDictionary<TPair>.GetKey(Index: TGDictionaryIndex): TPair.TKey;
     42constructor TGDictionary<TKey, TValue>.Create;
    3843begin
    39   Result := Items[Index].Key;
     44  FList := TGList<TDictionaryPair>.Create;
    4045end;
    4146
    42 function TGDictionary<TPair>.GetValue(Key: TPair.TKey): TPair.TValue;
     47destructor TGDictionary<TKey, TValue>.Destroy;
    4348begin
    44   Result := Items[SearchKey(Key)].Value;
     49  FList.Free;
    4550end;
    4651
    47 procedure TGDictionary<TPair>.PutKey(Index: TGDictionaryIndex;
    48   const AValue: TPair.TKey);
     52function TGDictionary<TKey, TValue>.GetKey(Index: TIndex): TKey;
     53begin
     54  Result := FList.Items[Index].Key;
     55end;
     56
     57function TGDictionary<TKey, TValue>.GetValue(Key: TKey): TValue;
     58begin
     59  Result := FList.Items[SearchKey(Key)].Value;
     60end;
     61
     62procedure TGDictionary<TKey, TValue>.PutKey(Index: TIndex;
     63  const AValue: TKey);
    4964var
    50   Item: TPair;
     65  Item: TDictionaryPair;
    5166begin
    5267  //Items[Index].Key := AValue;
    53   Item := Items[Index];
     68  Item := FList.Items[Index];
    5469  Item.Key := AValue;
    55   Items[Index] := Item;
     70  FList.Items[Index] := Item;
    5671end;
    5772
    58 procedure TGDictionary<TPair>.PutValue(Key: TPair.TKey;
    59   const AValue: TPair.TValue);
     73procedure TGDictionary<TKey, TValue>.PutValue(Key: TKey;
     74  const AValue: TValue);
    6075var
    61   Item: TPair;
    62   Index: TGDictionaryIndex;
     76  Item: TDictionaryPair;
     77  Index: TIndex;
    6378begin
    6479  //Items[SearchKey(Index)].Value := AValue;
    6580  Index := SearchKey(Key);
    66   Item := Items[Index];
     81  Item := FList.Items[Index];
    6782  Item.Value := AValue;
    68   Items[Index] := Item;
     83  FList.Items[Index] := Item;
    6984end;
    7085
    71 function TGDictionary<TPair>.SearchKey(Key: TPair.TKey): TGDictionaryIndex;
     86function TGDictionary<TKey, TValue>.SearchKey(Key: TKey): TIndex;
    7287begin
    7388  Result := 0;
    74   while Result < Count do begin
    75     if Items[Result].Key = Key then begin
     89  while Result < FList.Count do begin
     90    if FList.Items[Result].Key = Key then begin
    7691      Break;
    7792    end;
     
    8095end;
    8196
    82 procedure TGDictionary<TPair>.Add(Key: TPair.TKey; Value: TPair.TValue);
     97procedure TGDictionary<TKey, TValue>.Add(Key: TKey; Value: TValue);
    8398var
    84   NewPair: TPair;
     99  NewPair: TDictionaryPair;
    85100begin
    86101  NewPair.Key := Key;
    87102  NewPair.Value := Value;
    88   inherited Add(NewPair);
     103  FList.Add(NewPair);
    89104end;
    90105
  • TabularUnified Generics/NativeGenerics/Units/GenericList.pas

    r313 r320  
    3434    function Add(Item: TItem): TIndex;
    3535    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;
    3838    procedure Clear; virtual;
    3939    procedure Delete(Index: TIndex); virtual;
    4040    procedure DeleteItems(Index, Count: TIndex);
    41     function EqualTo(List: TGList): Boolean;
     41    function EqualTo(List: TGList<TItem>): Boolean;
    4242    procedure Exchange(Index1, Index2: TIndex);
    4343    procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1);
     
    4848    function Implode(Separator: string; Converter: TToStringConverter): string;
    4949    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;
    5151    procedure Insert(Index: TIndex; Item: TItem);
    52     procedure InsertList(Index: TIndex; List: TGList);
     52    procedure InsertList(Index: TIndex; List: TGList<TItem>);
    5353    procedure InsertArray(Index: TIndex; Values: array of TItem);
    5454    procedure Move(CurIndex, NewIndex: TIndex);
     
    6464  end;
    6565
    66   TGListObject<TItem> = class(TGList<TItem>)
     66  TListObject<TItem> = class(TGList<TItem>)
    6767  private
    6868    procedure Put(Index: Integer; const AValue: TItem); override;
     
    7676  end;
    7777
    78   TGListString<TItem> = class(TGList<TItem>)
     78  TListString<TItem> = class(TGList<TItem>)
    7979  private
    8080  public
     
    9393  RtlConsts;
    9494
    95 { TGList }
     95{ TGList<TItem> }
    9696
    9797function TGList<TItem>.GetCapacity: TIndex;
     
    195195end;
    196196
    197 procedure TGList<TItem>.Assign(Source: TGList);
     197procedure TGList<TItem>.Assign(Source: TGList<TItem>);
    198198var
    199199  I: TIndex;
     
    239239end;
    240240
    241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList);
     241procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList<TItem>);
    242242var
    243243  I: TIndex;
     
    250250end;
    251251
    252 function TGList<TItem>.IndexOfList(List: TGList; Start: TIndex): TIndex;
     252function TGList<TItem>.IndexOfList(List: TGList<TItem>; Start: TIndex): TIndex;
    253253var
    254254  I: TIndex;
     
    353353end;
    354354
    355 function TGList<TItem>.EqualTo(List: TGList): Boolean;
     355function TGList<TItem>.EqualTo(List: TGList<TItem>): Boolean;
    356356var
    357357  I: TIndex;
     
    453453end;
    454454
    455 procedure TGList<TItem>.AddList(List: TGList);
     455procedure TGList<TItem>.AddList(List: TGList<TItem>);
    456456var
    457457  I: TIndex;
     
    514514end;
    515515
    516 { TGListObject }
    517 
    518 procedure TGListObject<TItem>.Assign(Source: TGList<TItem>);
     516{ TListObject }
     517
     518procedure TListObject<TItem>.Assign(Source: TGList<TItem>);
    519519begin
    520520  Clear;
     
    523523end;
    524524
    525 procedure TGListObject<TItem>.Put(Index: Integer; const AValue: TItem);
     525procedure TListObject<TItem>.Put(Index: Integer; const AValue: TItem);
    526526begin
    527527  if OwnsObjects then FItems[Index].Free;
     
    529529end;
    530530
    531 procedure TGListObject<TItem>.Delete(Index: Integer);
     531procedure TListObject<TItem>.Delete(Index: Integer);
    532532begin
    533533  if OwnsObjects then FItems[Index].Free;
     
    535535end;
    536536
    537 procedure TGListObject<TItem>.Clear;
     537procedure TListObject<TItem>.Clear;
    538538var
    539539  I: Integer;
     
    549549end;
    550550
    551 constructor TGListObject<TItem>.Create;
     551constructor TListObject<TItem>.Create;
    552552begin
    553553  inherited;
     
    555555end;
    556556
    557 destructor TGListObject<TItem>.Destroy;
     557destructor TListObject<TItem>.Destroy;
    558558begin
    559559  Clear;
     
    561561end;
    562562
    563 { TGListString }
    564 
    565 procedure TGListString<TItem>.Assign(Source: TGList<TItem>);
     563{ TListString }
     564
     565procedure TListString<TItem>.Assign(Source: TGList<TItem>);
    566566begin
    567567  Clear;
     
    569569end;
    570570
    571 procedure TGListString<TItem>.Delete(Index: Integer);
     571procedure TListString<TItem>.Delete(Index: Integer);
    572572begin
    573573  FItems[Index] := '';
     
    575575end;
    576576
    577 procedure TGListString<TItem>.Clear;
     577procedure TListString<TItem>.Clear;
    578578var
    579579  I: Integer;
     
    587587end;
    588588
    589 constructor TGListString<TItem>.Create;
     589constructor TListString<TItem>.Create;
    590590begin
    591591  inherited;
    592592end;
    593593
    594 destructor TGListString<TItem>.Destroy;
     594destructor TListString<TItem>.Destroy;
    595595begin
    596596  Clear;
  • TabularUnified Generics/NativeGenerics/Units/GenericQueue.pas

    r132 r320  
    1111  TGQueue<TItem> = class
    1212  private
    13   type
    14     TGQueueList = TGList<TItem>;
    1513  var
    16     FList: TGQueueList;
     14    FList: TGList<TItem>;
    1715  public
    1816    procedure Enqueue(Value: TItem);
     
    2119    constructor Create;
    2220    destructor Destroy; override;
    23     property List: TGQueueList read FList;
     21    property List: TGList<TItem> read FList;
    2422  end;
    2523
     
    4038constructor TGQueue<TItem>.Create;
    4139begin
    42   FList := TGList.Create;
     40  FList := TGList<TItem>.Create;
    4341end;
    4442
  • TabularUnified Generics/NativeGenerics/Units/GenericSet.pas

    r132 r320  
    1111  TGSet<TItem> = class
    1212  private
    13   type
    14     TGSetList = TGList<TItem>;
    1513  var
    16     FList: TGSetList;
     14    FList: TGList<TItem>;
    1715  public
    1816    function IsIn(Item: TItem): Boolean;
    1917    constructor Create;
    2018    destructor Destroy; override;
    21     property List: TGSetList read FList;
     19    property List: TGList<TItem> read FList;
    2220  end;
    2321
     
    3331constructor TGSet<TItem>.Create;
    3432begin
    35   FList := TGList.Create;
     33  FList := TGList<TItem>.Create;
    3634end;
    3735
  • TabularUnified Generics/NativeGenerics/Units/GenericStack.pas

    r132 r320  
    1111  TGStack<TItem> = class
    1212  private
    13   type
    14     TGStackList = TGList<TItem>;
    1513  var
    16     FList: TGStackList;
     14    FList: TGList<TItem>;
    1715  public
    1816    procedure Push(Value: TItem);
     
    2018    constructor Create;
    2119    destructor Destroy; override;
    22     property List: TGStackList read FList;
     20    property List: TGList<TItem> read FList;
    2321  end;
    2422
     
    3836constructor TGStack<TItem>.Create;
    3937begin
    40   FList := TGList.Create;
     38  FList := TGList<TItem>.Create;
    4139end;
    4240
  • TabularUnified Generics/NativeGenerics/Units/GenericStream.pas

    r313 r320  
    11unit GenericStream;
    22
    3 {$mode Delphi}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
    66
    77uses
    8   Classes, SysUtils;
     8  SysUtils, Classes, GenericList;
    99
    1010type
    1111  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;
    1236
    13   end;
    1437
    1538implementation
    1639
     40
     41procedure TGStream<TItem>.Assign(Source: TGStream<TItem>);
     42begin
     43end;
     44
     45procedure TGStream<TItem>.SetPosition(AValue: TIndex);
     46begin
     47  Seek(AValue, soBeginning);
     48end;
     49
     50function TGStream<TItem>.GetPosition: TIndex;
     51begin
     52  Result := Seek(0, soCurrent);
     53end;
     54
     55procedure TGStream<TItem>.SetSize(AValue: TIndex);
     56var
     57  StreamSize: TIndex;
     58  OldPosition: TIndex;
     59begin
     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;
     71end;
     72
     73function TGStream<TItem>.GetSize: TIndex;
     74var
     75  OldPosition: Integer;
     76begin
     77  OldPosition := Position;
     78  Result := Seek(0, soEnd);
     79  Position := OldPosition;
     80end;
     81
     82constructor TGStream<TItem>.Create;
     83begin
     84  inherited;
     85end;
     86
    1787end.
    18 
Note: See TracChangeset for help on using the changeset viewer.