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/GenericListInterface.tpl

    r68 r69  
    44
    55type
    6   TGListSortCompare = function(const Item1, Item2: TItemType): Integer;
     6  TGListSortCompare = function(const Item1, Item2: TListItem): Integer of object;
     7  TGListStringConverter = function(Item: TListItem): string;
    78  //TGListNotification = (lnAdded, lnExtracted, lnDeleted);
    89
    9   // TGList<TIndexType, TItemType> = class
     10  // TGList<TListIndex, TListItem> = class
    1011  TGList = class
    1112  private
    12     FItems: array of TItemType;
    13     FCount: TIndexType;
    14     function Get(Index: TIndexType): TItemType;
    15     function GetCount: TIndexType;
    16     function GetCapacity: TIndexType;
    17     procedure SetCapacity(const AValue: TIndexType);
    18     procedure Put(Index: TIndexType; const AValue: TItemType);
    19     procedure SetCount(const AValue: TIndexType);
    20     procedure QuickSort(L, R : TIndexType; Compare: TGListSortCompare);
    21     property Capacity: TIndexType read GetCapacity write SetCapacity;
     13    FItems: array of TListItem;
     14    FCount: TListIndex;
     15    function Get(Index: TListIndex): TListItem;
     16    function GetCount: TListIndex;
     17    function GetCapacity: TListIndex;
     18    procedure SetCapacity(const AValue: TListIndex);
     19    procedure Put(Index: TListIndex; const AValue: TListItem);
     20    procedure SetCount(const AValue: TListIndex);
     21    procedure QuickSort(L, R : TListIndex; Compare: TGListSortCompare);
     22    property Capacity: TListIndex read GetCapacity write SetCapacity;
    2223  public
    2324    // All items
     
    2627    procedure Expand;
    2728    procedure Sort(Compare: TGListSortCompare);
    28     function Implode(Separator: string): string;
     29    function Implode(Separator: string; Converter: TGListStringConverter): string;
    2930    // Many items
    30     procedure MoveItems(CurIndex, NewIndex, Count: TIndexType);
     31    procedure MoveItems(CurIndex, NewIndex, Count: TListIndex);
     32    procedure Swap(Index1, Index2: TListIndex);
    3133    // One item
    32     function Add(Item: TItemType): TIndexType;
    33     procedure Delete(Index: TIndexType);
    34     procedure Exchange(Index1, Index2: TIndexType);
    35     function Extract(Item: TItemType): TItemType;
    36     function First: TItemType;
    37     function IndexOf(Item: TItemType): TIndexType;
    38     procedure Insert(Index: TIndexType; Item: TItemType);
    39     function Last: TItemType;
    40     procedure Move(CurIndex, NewIndex: TIndexType);
    41     function Remove(Item: TItemType): TIndexType;
    42     property Items[Index: TIndexType]: TItemType read Get write Put; default;
     34    function Add(Item: TListItem): TListIndex;
     35    procedure Delete(Index: TListIndex);
     36    procedure Exchange(Index1, Index2: TListIndex);
     37    function Extract(Item: TListItem): TListItem;
     38    function First: TListItem;
     39    function IndexOf(Item: TListItem): TListIndex;
     40    procedure Insert(Index: TListIndex; Item: TListItem);
     41    function Last: TListItem;
     42    procedure Move(CurIndex, NewIndex: TListIndex);
     43    function Remove(Item: TListItem): TListIndex;
     44    property Items[Index: TListIndex]: TListItem read Get write Put; default;
    4345    // List
    4446    procedure AddList(List: TGList);
    4547    procedure Assign(List: TGList);
    46     procedure DeleteItems(Index, Count: TIndexType);
    47     function Equals(Obj: TObject): Boolean; override;
    48     function ExtractList(Item: TItemType; Count: TIndexType): TItemType;
    49     procedure InsertList(Index: TIndexType; List: TGList);
     48    procedure DeleteItems(Index, Count: TListIndex);
     49    //function Equals(Obj: TObject): Boolean; override;
     50    function ExtractList(Item: TListItem; Count: TListIndex): TListItem;
     51    procedure InsertList(Index: TListIndex; List: TGList);
    5052    // Other
    51     property Count: TIndexType read GetCount write SetCount;
     53    property Count: TListIndex read GetCount write SetCount;
    5254    // Additional
    53     procedure SetArray(Values: array of TItemType);
     55    procedure SetArray(Values: array of TListItem);
    5456  end;
Note: See TracChangeset for help on using the changeset viewer.