Class APointerList

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type APointerList = class(ALinkedList)

Description

This class represents a list of one or more pointers. It extends ALinkedList to allow pointer values to be stored within the list. As with ALinkedList, APointerList may be accessed as though it was an indexed array, or it may be used like a stack (LIFO).

Hierarchy

Overview

Methods

Public constructor withReferences(const references: array of pointer); virtual;
Public constructor from(const thisList: string; const thisDelimiter: string = ''); virtual;
Public function add(const thisReference: pointer): TIndexAbsolute; virtual;
Public function addSeveral(const references: array of pointer): TCensus; virtual;
Public function explode(thisList: string; delimiter: string = ''): TCensus; override;
Public procedure push(const thisReference: pointer); virtual;
Public procedure pushSeveral(const references: array of pointer); virtual;
Public function pop: pointer; virtual;
Public procedure insertAt(const index: TIndexRelative; const thisReference: pointer); virtual;
Public function hasReference(const thisReference: pointer): boolean; virtual; overload;
Public function indexOf(const thisReference: pointer; const afterIndex: TIndexRelative = 0): TIndexRelative; virtual;
Public function item(const thisIndex: TIndexRelative): pointer; virtual;
Public function setItem(const thisIndex: TIndexRelative; const thisReference: pointer): pointer; virtual;

Description

Methods

Public constructor withReferences(const references: array of pointer); virtual;

Construct a new pointer list that contains the specified values.

This method calls APointerList.pushSeveral to insert the values in references into the list after the new instance has been constructed and initialized. If references is empty, then an empty list is created by this routine.

Public constructor from(const thisList: string; const thisDelimiter: string = ''); virtual;

Construct a new pointer list by expanding the values provided in thisList.

thisList must be a list of numeric values separated by thisDelimiter. The numeric values are assumed to be valid pointer references.

If thisDelimiter is provided by the caller, then it is used to split the values provided in thisList; otherwise, the delimiter specified by llstDefaultDelimiter is used. See APointerList.explode for more information.

If thisList is an empty string, then an empty list is created by this routine.

Public function add(const thisReference: pointer): TIndexAbsolute; virtual;

Adds thisReference to the end of the list.

This method constructs a new instance of APointerListItem and then calls ALinkedList.addItem to add the item to the list.

Returns

The index of the new item. This index is not guaranteed to remain the same for this item if other items are added or removed at locations PRIOR to the index returned.

Public function addSeveral(const references: array of pointer): TCensus; virtual;

Add several items to the end of the list.

This method iterates through each item in references and calls APointerList.add to add each item to the list.

Returns

The total number of items added to the list.

Public function explode(thisList: string; delimiter: string = ''): TCensus; override;

Add the items specified in thisList to the list.

This method assumes that thisList contains one or more numeric values that are separated by a delimiter of some kind (e.g., a comma). It uses the value of delimiter to split the string into its component values; these values are then added as individual items to the list. If delimiter is not supplied, or if it is an empty string, then the value of llstDefaultDelimiter is used. The assumption is that the numeric values in the list represent valid pointer values. USE THIS METHOD WITH CARE – or don't use it at all. It is defined merely for the sake of completeness.

Returns

The total number of items added to the list.

Public procedure push(const thisReference: pointer); virtual;

Pushes the specified pointer value onto the list, as the last item in the list. Calling APointerList.pop immediately after this routine will return thisReference.

This method constructs a new instance of APointerListItem and then calls ALinkedList.pushItem to push the item onto the list.

Public procedure pushSeveral(const references: array of pointer); virtual;

Push several items onto the list.

This method iterates through each item in references and calls APointerList.push to push each string value onto the list.

Public function pop: pointer; virtual;

Pops the last item from the list. This will be the reference most recently added to the list by a call to APointerList.add or APointerList.push.

If the list is empty, this routine returns Nil.

Public procedure insertAt(const index: TIndexRelative; const thisReference: pointer); virtual;

Inserts the specified pointer value at the given index. If an item already exists at that index, it is "bumped aside" in favor of the new item.

This method constructs a new instance of APointerListItem and then calls ALinkedList.insertItemAt to insert the item into the list.

The first item in the list is always at index zero (0). The last item in the list is always at index (ALinkedList.census -1). If index specifies a value that is greater than the number of items in the list, then thisReference is inserted at the end of the list.

Public function hasReference(const thisReference: pointer): boolean; virtual; overload;

Performs a recursive search to determine whether or not the specified value exists within the list. For very large lists, this search can be inefficient (and can cause stack overflows, due to the recursive nature of the search).

This method calls APointerListItem.find on the last item in the list, which causes the entire list to be searched recursively.

Returns

True if thisReference is found in the list; False if not.

Public function indexOf(const thisReference: pointer; const afterIndex: TIndexRelative = 0): TIndexRelative; virtual;

Performs a linear search to find the index of the specified value. The search will begin at afterIndex.

Because this method performs a linear search, it can be inefficient on very large lists.

Returns

The index of the specified pointer value, if found; -1 otherwise. The index returned by this routine will always be an offset relative to the beginning of the list (i.e., a positive integer) if the pointer value is found.

Public function item(const thisIndex: TIndexRelative): pointer; virtual;

Retrieve the value of the item at the specified index.

This method calls ALinkedList.itemAt to retrieve the APointerListItem instance at the specified index; it then returns the value of APointerListItem.reference.

Index zero (0) represents the first node in the list, while index (ALinkedList.census - 1) represents the last node in the list. If index specifies a value that is greater than the number of nodes in the list, then this routine will remove the last item in the list.

If an invalid index is passed to this routine, it will return Nil.

Public function setItem(const thisIndex: TIndexRelative; const thisReference: pointer): pointer; virtual;

Set the value of the item at the specified index.

This method calls ALinkedList.itemAt to retrieve the APointerListItem instance at the specified index; it then calls APointerListItem.setReference on that instance.

If index specifies an index that is greater than or equal to the value of Self.census, then this method will insert a new item that contains thisReference into the list.

Returns

The previous value of the string stored at the specified index, if any. Nil will be returned if an invalid index is passed to this routine.


Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11