Home Units Hierarchy Routines All identifiers

Class unaList

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type unaList = class(unaObject)

Description

This is general purpose list of items. Multi-threaded safe.

Hierarchy

Overview

Methods

Public constructor create(dataType: unaListDataType = uldt_ptr; sorted: bool = false);
Public function add(item: int32): int; overload;
Public function add(item: pointer): int; overload;
Public function add(item: int64): int; overload;
Public function assign(list: unaList): int;
Public function asString(const delimiter: string; treatAsSigned: bool = true; base: unsigned = 10): string;
Public function checkDataEvent(): bool;
Public function copyFrom(list: pointer; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; overload;
Public function copyFrom(list: unaList; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; overload;
Public function copyTo(out list: pointer; includeZeroIndexCount: bool): int;
Public function get(index: int): pointer;
Public function getObject(index: int): tObject;
Public function indexOf(item: int32): int; overload;
Public function indexOf(item: pointer): int; overload;
Public function indexOf(item: int64): int; overload;
Public function insert(index: int; item: pointer): int; overload;
Public function insert(index: int; item: int32): int; overload;
Public function insert(index: int; item: int64): int; overload;
Public function lock(ro: bool; timeout: tTimeout = 100 ): bool;
Public function lockObject(index: int; ro: bool = true; timeout: tTimeout = 1000): unaObject;
Public function removeByIndex(index: int; doFree: unsigned = 2): bool; overload;
Public function removeFromEdge(removeFromBegining: bool = true): bool;
Public function removeItem(item: pointer; doFree: unsigned = 2): bool; overload;
Public function removeItem(item: int64): bool; overload;
Public function removeItem(item: int32): bool; overload;
Public function setItem(itemToReplace: pointer; newItem: pointer; doFree: unsigned = 2): unsigned; overload;
Public function sort(): bool;
Public function waitForData(timeout: tTimeout = 100): bool;
Protected function compare(a, b: pointer): int; virtual;
Protected function doAdd(item: pointer): int; overload; virtual;
Protected function doCopyFrom(list: pointer; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; virtual;
Protected function doInsert(index: int; item: pointer; brokeSorted: bool = true): int; virtual;
Protected function isEmpty(): bool;
Protected function mapDoFree(doFree: unsigned): bool;
Public procedure BeforeDestruction(); override;
Public procedure clear(doFree: unsigned = 2; force: bool = false);
Public procedure reverse();
Public procedure setCapacity(value: unsigned);
Public procedure setItem(index: int; item: int32); overload;
Public procedure setItem(index: int; item: pointer; doFree: unsigned = 2); overload;
Public procedure setItem(index: int; item: int64); overload;
Public procedure unlockRO();
Public procedure unlockWO();
Protected procedure doReverse(); virtual;
Protected procedure doSetCapacity(value: unsigned; force: bool = false); virtual;
Protected procedure doSetItem(index: int; item: pointer; brokeSorted: bool = true; doFree: unsigned = 2); overload; virtual;
Protected procedure notifyBeforeRemove(index: int); virtual;
Protected procedure releaseItem(index: int; doFree: unsigned); virtual;

Properties

Public property autoFree: bool read f_autoFree write f_autoFree;
Public property count: int read f_count;
Protected property dataItemSize: int read f_dataItemSize;
Public property dataType: unaListDataType read getDT;
Public property item[index:int]: pointer read get write internalSetItem;
Protected property list: unaListStorage read f_list;
Protected property listPtr: pointer read getListPtr;
Protected property listPtrAt[index:int]: pointer read getListPtrAt;
Public property onItemBeforeRemove: unaListOnItemBeforeRemoveEvent read f_onItemBeforeRemove write f_onItemBeforeRemove;
Public property onItemRelease: unaListOnItemReleaseEvent read f_onItemRelease write f_onItemRelease;
Public property singleThreaded: bool read f_singleThreaded write f_singleThreaded;
Public property sorted: bool read f_sorted;
Public property timeout: tTimeout read f_timeout write f_timeout default 1000;

Description

Methods

Public constructor create(dataType: unaListDataType = uldt_ptr; sorted: bool = false);

NOTE: default value for dataType is now uldt_ptr!

Public function add(item: int32): int; overload;

Adds item to the end of the list. Returns list index of inserted item (usually count - 1).

Public function add(item: pointer): int; overload;
 
Public function add(item: int64): int; overload;
 
Public function assign(list: unaList): int;

Returns number of items copied.

Public function asString(const delimiter: string; treatAsSigned: bool = true; base: unsigned = 10): string;
 
Public function checkDataEvent(): bool;
 
Public function copyFrom(list: pointer; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; overload;

Returns number of items processed. If listSize is -1 list has "zero index count", i.e. number of items is stored as first item of the list.

Public function copyFrom(list: unaList; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; overload;
 
Public function copyTo(out list: pointer; includeZeroIndexCount: bool): int;

Creates a array and copies list items into it. If includeZeroIndexCount is true, the first elemet of array will contain number of items in it.

Returns

size of created array (in bytes).

Public function get(index: int): pointer;

Returns item from the list. index specifies the index of item to be returned.

Public function getObject(index: int): tObject;

Returns item with specified index as object.

Public function indexOf(item: int32): int; overload;

Searches the list for specified item value. Returns -1 if no item was found.

Public function indexOf(item: pointer): int; overload;
 
Public function indexOf(item: int64): int; overload;
 
Public function insert(index: int; item: pointer): int; overload;
 
Public function insert(index: int; item: int32): int; overload;

Inserts an item at specified position (index parameter) in the list. Does nothing if index is bigger than count. Returns index.

Public function insert(index: int; item: int64): int; overload;
 
Public function lock(ro: bool; timeout: tTimeout = 100 ): bool;

Locks the list for read-only (RO) or write-only (WO) access.

Parameters
ro
Request read-only (True) or write-only (False) access
timeout
Timeout, if 0 is passed (default), timeOut property will be used instead
Returns

false if lock cannot be set in a timeout period

Public function lockObject(index: int; ro: bool = true; timeout: tTimeout = 1000): unaObject;

Locks an object in the list. Don't forget to release the object.

Returns

nil if object was not found or was not locked.

Public function removeByIndex(index: int; doFree: unsigned = 2): bool; overload;

Removes item with specified index from the list. Returns true if item was removed, or false otherwise.

Public function removeFromEdge(removeFromBegining: bool = true): bool;

Removes first (removeFirst = true) or last (removeFirst = false) item from the list (if it presents). Returns true if item was removed, or false otherwise.

Public function removeItem(item: pointer; doFree: unsigned = 2): bool; overload;
 
Public function removeItem(item: int64): bool; overload;
 
Public function removeItem(item: int32): bool; overload;

Removes specifed item from the list. Returns true if item was removed, or false otherwise.

Public function setItem(itemToReplace: pointer; newItem: pointer; doFree: unsigned = 2): unsigned; overload;
 
Public function sort(): bool;

Sorts the list. Override compare() method for custom sorting. By default list knows how to sort int32, int64 and string values.

Public function waitForData(timeout: tTimeout = 100): bool;
 
Protected function compare(a, b: pointer): int; virtual;

Should return -1 if a < b, +1 if a > b and 0 otherwise.

Protected function doAdd(item: pointer): int; overload; virtual;
 
Protected function doCopyFrom(list: pointer; listSize: int = -1; copyOperation: unaListCopyOpEnum = unaco_add; startIndex: int = 0): int; virtual;
 
Protected function doInsert(index: int; item: pointer; brokeSorted: bool = true): int; virtual;
 
Protected function isEmpty(): bool;

Returns true if there are no items in the list. Note, that due to multi-threading issues returned result may be not accurate. Use for quick checks only, like status update.

Protected function mapDoFree(doFree: unsigned): bool;
 
Public procedure BeforeDestruction(); override;
 
Public procedure clear(doFree: unsigned = 2; force: bool = false);

Clears the list. All items will be removed and count will be reset to 0.

Public procedure reverse();

Reverses items in the list.

Public procedure setCapacity(value: unsigned);

Allocates resources for new capacity.

Public procedure setItem(index: int; item: int32); overload;

Sets item value in the list. index specifies the index of item to be set. item is value of item. Old item will be freed. If old item is object, doFree parameter specifies the action should be taken.

Public procedure setItem(index: int; item: pointer; doFree: unsigned = 2); overload;
 
Public procedure setItem(index: int; item: int64); overload;
 
Public procedure unlockRO();

Unlocks the list after read-only lock. Must be called after each successful lock(true)

Public procedure unlockWO();

Unlocks the list after write-only lock. Must be called after each successful lock(false)

Protected procedure doReverse(); virtual;
 
Protected procedure doSetCapacity(value: unsigned; force: bool = false); virtual;
 
Protected procedure doSetItem(index: int; item: pointer; brokeSorted: bool = true; doFree: unsigned = 2); overload; virtual;
 
Protected procedure notifyBeforeRemove(index: int); virtual;
 
Protected procedure releaseItem(index: int; doFree: unsigned); virtual;

Disposes the item.

Properties

Public property autoFree: bool read f_autoFree write f_autoFree;

Set this property to true for lists which know how to free own items, to allow items to be freed by the list.

Public property count: int read f_count;

Number of items in the list.

Protected property dataItemSize: int read f_dataItemSize;
 
Public property dataType: unaListDataType read getDT;
 
Public property item[index:int]: pointer read get write internalSetItem;

Returns list item by it index.

Protected property list: unaListStorage read f_list;
 
Protected property listPtr: pointer read getListPtr;
 
Protected property listPtrAt[index:int]: pointer read getListPtrAt;
 
Public property onItemBeforeRemove: unaListOnItemBeforeRemoveEvent read f_onItemBeforeRemove write f_onItemBeforeRemove;

Fires when list item is about to be removed from the list.

Public property onItemRelease: unaListOnItemReleaseEvent read f_onItemRelease write f_onItemRelease;

Fires when list item is needed to be released. NOTE: item[index] could be nil.

Public property singleThreaded: bool read f_singleThreaded write f_singleThreaded;

When this property is true list will not use gate to protect internal data in multi-threading access. This may increase performance a little.

Public property sorted: bool read f_sorted;
 
Public property timeout: tTimeout read f_timeout write f_timeout default 1000;

Default timeout.

(c) 2012 Lake of Soft


Generated by PasDoc 0.12.1 on 2012-10-09