Class TStructList

Unit

Declaration

type generic TStructList<T> = class(specialize TList<T>)

Description

List of structures. This is just TList class from Generics.Collections, with some useful helpers.

Hierarchy

Overview

Nested Types

Public PtrT = ˆT;
Public PTypeList = ˆTTypeList;
Public TTypeList = array [0 .. MaxInt div SizeOf(T) - 1] of T;

Methods

Public function List: PTypeList;
Public function L: PtrT;
Public function Add: PtrT; overload;
Public function Ptr(const I: TListSize): PtrT;
Public procedure Assign(const Source: TStructList ); overload;
Public procedure Assign(const A: array of T); overload;
Public function ItemSize: TListSize;
Public procedure AddSubRange(const Source: TStructList ; const Index, AddCount: TListSize);
Public procedure AssignLerpRange(const Fraction: Single; const V1, V2: TStructList ; const Index1, Index2, ACount: TListSize); virtual;
Public procedure AssignLerp(const Fraction: Single; const V1, V2: TStructList );
Public function PerfectlyEquals( const SecondValue: TStructList): Boolean;
Public procedure AddArray(const A: array of T); deprecated 'use AddRange';
Public procedure AddList(const Source: TStructList ); deprecated 'use AddRange';
Public procedure AssignArray(const A: array of T); deprecated 'use Assign';

Description

Nested Types

Public PtrT = ˆT;
 
Public PTypeList = ˆTTypeList;
 
Public TTypeList = array [0 .. MaxInt div SizeOf(T) - 1] of T;

TODO: Can we calculate better size on Delphi? Now we just assume that T has max size 16 * 16. This declaration will fail if you try to use TStructList with larger T. Note: we cannot declare list size too small, or using it may fail with range check error (e.g. Delphi, in IndexedPolygons_TrianglesCount, testcase: build_3d_object_by_code_2_tunnel.

Methods

Public function List: PTypeList;

Access the list contents directly through a pointer.

This is useful if you have a list of records and you would like to set their fields. This will not work correctly:

type
  TMyRecord = record MyField: Integer; end;
  TMyRecordList = specialize TGenericStructList<TMyRecord>;
var
  MyList: TMyRecordList;
begin
  // ...
  MyList[I].MyField := 123;

(It will not work OK because you would modify only a temporary record returned by the MyList[I] getter.) Instead, setting by

MyList.Listˆ[I].MyField := 123;

will work OK. Or you can use (only in FPC ObjFpc mode) even shorter this:

MyList.L[I].MyField := 123;

See also
L
Access the list contents directly through a pointer to T structure.
Public function L: PtrT;

Access the list contents directly through a pointer to T structure.

This is exactly the same pointer as List, but the type is different: this points to a single item. This is useful if you have a list of records and you would like to set their fields. This allows to use L[I] instead of Listˆ[I] (only in FPC ObjFpc mode).

See the List description for a more detailed explanation and example.

See also
List
Access the list contents directly through a pointer.
Public function Add: PtrT; overload;

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

Public function Ptr(const I: TListSize): PtrT;

Pointer to ith item.

Public procedure Assign(const Source: TStructList ); overload;
 
Public procedure Assign(const A: array of T); overload;
 
Public function ItemSize: TListSize;
 
Public procedure AddSubRange(const Source: TStructList ; const Index, AddCount: TListSize);

Add a subrange of another list here.

This method may ignore the OnNotify mechanism, for the sake of fast execution.

Public procedure AssignLerpRange(const Fraction: Single; const V1, V2: TStructList ; const Index1, Index2, ACount: TListSize); virtual;

Assign here a linear interpolation of two other arrays. We take ACount items, from V1[Index1 ... Index1 + ACount - 1] and V2[Index2 ... Index2 + ACount - 1], and interpolate between them.

It's Ok for both V1 and V2 to be the same objects. But their ranges should not overlap, for future optimizations.

Exceptions raised
ELinearInterpolationImpossible
On classes where linear interpolation is not possible, e.g. we cannot linearly interpolate lists of strings.
Public procedure AssignLerp(const Fraction: Single; const V1, V2: TStructList );

Assign linear interpolation between two other arrays.

Exceptions raised
EListsDifferentCount
If V1 and V2 have different count.
ELinearInterpolationImpossible
On classes where linear interpolation is not possible, e.g. we cannot linearly interpolate lists of strings.
Public function PerfectlyEquals( const SecondValue: TStructList): Boolean;

Does the SecondValue have equal type, length and content. The values are compared perfectly, without any tolerance for difference.

Public procedure AddArray(const A: array of T); deprecated 'use AddRange';

Warning: this symbol is deprecated: use AddRange

 
Public procedure AddList(const Source: TStructList ); deprecated 'use AddRange';

Warning: this symbol is deprecated: use AddRange

 
Public procedure AssignArray(const A: array of T); deprecated 'use Assign';

Warning: this symbol is deprecated: use Assign

 

Generated by PasDoc 0.16.0.