Class TgoValueList

DescriptionHierarchyInternal TypesFieldsMethodsProperties

Unit

Declaration

type TgoValueList<T:record> = class(TObject)

Description

A light-weight list of value types (primitive types and records). Differs from TList<T> in the following regards:

  • You cannot store reference types (objects, interfaces, strings or dynamic arrays) in the list.

  • It is more light-weight since it doesn't support noticications, comparers and only checks bounds with assertions (which can be turned off).

  • When requesting an item (using Items, First, Last etc.), it returns a Pointer to the type instead of the actual type. This can be both more efficient, and it allows you to directly modify the item in the list.

  • It grows in increments of 16 instead of doubling its size.

The pointer is of type TgoPtr<T>.P. It may be easier to declare your own pointer type as in PFoo = TgoPtr<TFoo>.P.

Note that you should not cache these pointers for long-term use as they become invalid when you modify the list (add or remove items).

Hierarchy

  • TObject
  • TgoValueList

Overview

Internal Types

Public P = TgoPtr<T>.P;

Methods

Public constructor Create;
Public procedure Clear;
Public function Add(const AValue: T): Integer;
Public procedure Insert(const AIndex: Integer; const AValue: T);
Public procedure Delete(const AIndex: Integer);
Public procedure DeleteRange(const AIndex, ACount: Integer);
Public function First: P;
Public function Last: P;
Public function GetEnumerator: TEnumerator;

Properties

Public property Count: Integer read FCount write SetCount;
Public property Items[constAIndex:Integer]: P read GetItem;

Description

Internal Types

Public P = TgoPtr<T>.P;

The pointer type for referencing items in this list.

Methods

Public constructor Create;

Creates a new list. The list is initially emtpy and will grow in increments of 16 items.

Public procedure Clear;

Clears the list.

Public function Add(const AValue: T): Integer;

Adds an item to the end of the list.

Parameters
AValue
the item to add.
Returns

The index of the added item

Public procedure Insert(const AIndex: Integer; const AValue: T);

Inserts an item at a given index into the list.

Parameters
AIndex
the location to insert the item. An assertion is used when the index is out of bounds.
AValue
the item to add.
Public procedure Delete(const AIndex: Integer);

Deletes an item from the list.

Parameters
AIndex
the index of the item to delete. An assertion is used when the index is out of bounds.
Public procedure DeleteRange(const AIndex, ACount: Integer);

Deletes a range of items from the list.

Parameters
AIndex
the index of the first item to delete
ACount
the number of items to delete
Public function First: P;

Returns a pointer to the first item in the list. An assertion is used when the list is empty.

Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.

Public function Last: P;

Returns a pointer to the last item in the list. An assertion is used when the list is empty.

Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.

Public function GetEnumerator: TEnumerator;

Allows for for..in enumeration of the list. Since the enumerator returns pointers to the items, you use it like this:

      var
        Items: TgoValueList<TFoo>;
        Item: TgoPtr<TFoo>.P;
      begin
        // Initialize Items
        for Item in Items do...
      end;

Properties

Public property Count: Integer read FCount write SetCount;

The number of items in the list

Public property Items[constAIndex:Integer]: P read GetItem;

The items in the list. Returns a pointer to the requested item.

Note: You should not cache the returned pointer for long-term use as it is only valid as long as you don't modify the list.

Parameters
Index
the index of the requested item. An assertion is used when the index is out of bounds.

Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26