classwork.ppIntroduction Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers Classes hierarchy graph
|
Class AnObjectList
Unit
classwork
Declaration
type AnObjectList = class(ALinkedList)
Description
This class represents a list of one or more objects. It extends ALinkedList to allow instances of TObject and its descendants to be stored within the list. As with ALinkedList , AnObjectList may be accessed as though it was an indexed array, or it may be used like a stack (LIFO).
Hierarchy
Overview
Fields
Methods
|
constructor withReferences(const References: array of TObject; const takeOwnershipOfReferences: boolean = false); virtual; |
|
constructor from(const thisList: string; const thisDelimiter: string = ''; const takeOwnershipOfReferences: boolean = false); virtual; |
|
function init: boolean; override; |
|
function add(const ThisReference: TObject): TIndexAbsolute; virtual; |
|
function addSeveral(const References: array of TObject): TCensus; virtual; |
|
function explode(thisList: string; delimiter: string = ''): TCensus; override; |
|
procedure push(const ThisReference: TObject); virtual; |
|
procedure pushSeveral(const References: array of TObject); virtual; |
|
function Pop: TObject; virtual; |
|
procedure insertAt(const index: TIndexRelative; const ThisReference: TObject); virtual; |
|
function hasReference(const ThisReference: TObject): boolean; virtual; |
|
function indexOf(const ThisReference: TObject; const afterIndex: TIndexRelative = 0): TIndexRelative; virtual; |
|
function Item(const thisIndex: TIndexRelative): TObject; virtual; |
|
function SetItem(const thisIndex: TIndexRelative; const ThisReference: TObject): TObject; virtual; |
|
function ownsReferences: boolean; virtual; |
|
function setOwnsReferences(const flag: boolean): boolean; virtual; |
Description
Fields
|
myOwnReferences: boolean; |
Indicate whether or not the list owns its objects
|
Methods
|
constructor withReferences(const References: array of TObject; const takeOwnershipOfReferences: boolean = false); virtual; |
Construct a new pointer list that contains the specified values.
This method calls AnObjectList.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.
If takeOwnershipOfReferences is True , then the list will assume ownership of the objects in References and they will be freed when the list itself is freed. The value of takeOwnershipOfReferences is assigned to Self.ownsReferences.
|
|
constructor from(const thisList: string; const thisDelimiter: string = ''; const takeOwnershipOfReferences: boolean = false); virtual; |
Construct a new object 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 AnObjectList.explode for more information.
If thisList is an empty string, then an empty list is created by this routine.
If takeOwnershipOfReferences is True , then the list will assume ownership of the objects in thisList and they will be freed when the list itself is freed. The value of takeOwnershipOfReferences is assigned to Self.ownsReferences.
|
|
function init: boolean; override; |
Initializer
|
|
function add(const ThisReference: TObject): TIndexAbsolute; virtual; |
Adds ThisReference to the end of the list.
This method constructs a new instance of AnObjectListItem 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. |
|
function addSeveral(const References: array of TObject): TCensus; virtual; |
Add several items to the end of the list.
This method iterates through each item in References and calls AnObjectList.add to add each item to the list.
Returns
The total number of items added to the list. |
|
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. |
|
procedure push(const ThisReference: TObject); virtual; |
Pushes the specified pointer value onto the list, as the last item in the list. Calling AnObjectList.pop immediately after this routine will return ThisReference .
This method constructs a new instance of AnObjectListItem and then calls ALinkedList.pushItem to push the item onto the list.
|
|
procedure pushSeveral(const References: array of TObject); virtual; |
Push several items onto the list.
This method iterates through each item in References and calls AnObjectList.push to push each string value onto the list.
|
|
function Pop: TObject; virtual; |
Pops the last item from the list. This will be the reference most recently added to the list by a call to AnObjectList.add or AnObjectList.push.
If the list is empty, this routine returns Nil .
|
|
procedure insertAt(const index: TIndexRelative; const ThisReference: TObject); virtual; |
Inserts the specified object reference 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 AnObjectListItem 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.
|
|
function hasReference(const ThisReference: TObject): boolean; virtual; |
Performs a recursive search to determine whether or not the specified object 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 AnObjectListItem.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.
|
|
function indexOf(const ThisReference: TObject; const afterIndex: TIndexRelative = 0): TIndexRelative; virtual; |
Performs a linear search to find the index of the specified object. 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 object reference, 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. |
|
function Item(const thisIndex: TIndexRelative): TObject; virtual; |
Retrieve the value of the item at the specified index.
This method calls ALinkedList.itemAt to retrieve the AnObjectListItem instance at the specified index; it then returns the value of AnObjectListItem.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 .
|
|
function SetItem(const thisIndex: TIndexRelative; const ThisReference: TObject): TObject; virtual; |
Set the value of the item at the specified index.
This method calls ALinkedList.itemAt to retrieve the AnObjectListItem instance at the specified index; it then calls AnObjectListItem.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. |
|
function ownsReferences: boolean; virtual; |
Determine whether or not the list assumes ownership of the objects that it contains.
If this function returns True , then the list will free all of the objects that it contains when the list itself is destroyed. To change this behavior, call AnObjectList.setOwnsReferences.
|
|
function setOwnsReferences(const flag: boolean): boolean; virtual; |
Set whether or not the list assumes ownership of the objects that it contains.
If flag is True , then the list will free all of the objects that it contains when the list itself is destroyed. Otherwise, they are not freed.
Returns
The previous value of AnObjectList.ownsReferences. |
Generated by PasDoc 0.13.0 on 2015-06-23 19:40:11
|