Class TGenericStructList

DescriptionHierarchyInternal TypesFieldsMethodsProperties

Unit

Declaration

type generic TGenericStructList<T> = class(TFPSList)

Description

Generic list of types that are compared by CompareByte.

This is equivalent to TFPGList, except it doesn't override IndexOf, so your type doesn't need to have a "=" operator built-in inside FPC. When calling IndexOf or Remove, it will simply compare values using CompareByte, this is what TFPSList.IndexOf uses. This way it works to create lists of records, vectors (constant size arrays), old-style TP objects, and also is suitable to create a list of methods (since for methods, the "=" is broken, for Delphi compatibility, see http://bugs.freepascal.org/view.php?id=9228).

We also add some trivial helper methods like Add and L.

Hierarchy

  • TFPSList
  • TGenericStructList

Overview

Internal Types

Published TCompareFunc = function(const Item1, Item2: T): Integer;

Fields

Protected var FOnCompare: TCompareFunc;

Methods

Protected procedure CopyItem(Src, Dest: Pointer); override;
Protected procedure Deref(Item: Pointer); override;
Protected function Get(Index: Integer): T;
Protected function GetList: PTypeList;
Protected function ItemPtrCompare(Item1, Item2: Pointer): Integer;
Protected procedure Put(Index: Integer; const Item: T);
Public constructor Create;
Public function Add(const Item: T): Integer;
Public function Extract(const Item: T): T;
Public function First: T;
Public function IndexOf(const Item: T): Integer;
Public procedure Insert(Index: Integer; const Item: T);
Public function Last: T;
Public procedure Assign(Source: TGenericStructList);
Public function Remove(const Item: T): Integer;
Public procedure Sort(Compare: TCompareFunc);
Public function L: PT;
Public function Add: PT;

Properties

Public property Items[Index:Integer]: T read Get write Put;
Public property List: PTypeList read GetList;

Description

Internal Types

Published TCompareFunc = function(const Item1, Item2: T): Integer;
 

Fields

Protected var FOnCompare: TCompareFunc;
 

Methods

Protected procedure CopyItem(Src, Dest: Pointer); override;
 
Protected procedure Deref(Item: Pointer); override;
 
Protected function Get(Index: Integer): T;
 
Protected function GetList: PTypeList;
 
Protected function ItemPtrCompare(Item1, Item2: Pointer): Integer;
 
Protected procedure Put(Index: Integer; const Item: T);
 
Public constructor Create;
 
Public function Add(const Item: T): Integer;
 
Public function Extract(const Item: T): T;
 
Public function First: T;
 
Public function IndexOf(const Item: T): Integer;
 
Public procedure Insert(Index: Integer; const Item: T);
 
Public function Last: T;
 
Public procedure Assign(Source: TGenericStructList);
 
Public function Remove(const Item: T): Integer;
 
Public procedure Sort(Compare: TCompareFunc);
 
Public function L: PT;

Pointer to items. Exactly like List, but this points to a single item, which means you can access particular item by L[I] instead of Listˆ[I] in FPC objfpc mode.

This is just trivial shortcut, but we use direct access a lot for structures. Reasons: using Items[] default property means copying the structures, which is

  1. very dangerous (you can trivially easy modify a temporary result)

  2. slow (important for us, since these are used for vector arrays that are crucial for renderer and various processing).

Public function Add: PT;

Increase Count and return pointer to new item. Comfortable and efficient way to add a new item that you want to immediately initialize.

Properties

Public property Items[Index:Integer]: T read Get write Put;
 
Public property List: PTypeList read GetList;
 

Generated by PasDoc 0.13.0 on 2014-04-30 22:06:42