Class DataObjectListInMemory

Class Hierarchy

DataObjectListInMemory is a data object class instantiated for Lua arrays defined in the DataObject definition schema. This class is intended to be used in simulation scripts by storing data entirely in-memory, unlike general DataObjectList, which can retrieve data from external sources.

Example
names = DataObjectListInMemory:create("list")

names:addItem(DataObjectString:create("1", "Ricky"))
names:addItem(DataObjectString:create("2", "Rob"))
assertEq(names:itemCount(), 2)

-- Indexes start with zero.
names:removeItem(0)

-- `getItem` is specific to in-memory list data object.
-- For generic lists `acquireItem` should be used instead.
assertEq(names:getItem(0):getValue(), "Rob")

Inherits properties and message types from DataObjectListInMemoryMetadata.

See also DataObject

Synopsis

Methods
create()

Creates an instance of DataObjectListInMemory

addItem()

Adds an item to the end of a list

insertItem()

Adds an item to a list at the given index

removeItem()

Removes an item from a list at the given index

removeAllItems()

Removes all list items

getItem()

Gets an item at the given index

iterateItems()

Returns an iterator that you can use to iterate over items of a data object list

DataObjectListInMemory.DataObjectListInMemory:create(objectName, items)

Creates an instance of DataObjectListInMemory.

Parameters
objectName (string)

The name of the object.

items (DataObject[])

List of items to insert.

DataObjectListInMemory.DataObjectListInMemory:addItem(item)

Adds an item to the end of a list.

Parameters
item (DataObject)

An item to add.

DataObjectListInMemory.DataObjectListInMemory:insertItem(index, item)

Adds an item to a list at the given index.

Parameters
index (number)

Index of the item.

item (DataObject)

An item to insert.

DataObjectListInMemory.DataObjectListInMemory:removeItem(index)

Removes an item from a list at the given index.

Parameters
index (number)

Index of the item.

DataObjectListInMemory.DataObjectListInMemory:removeAllItems()

Removes all list items.

DataObjectListInMemory.DataObjectListInMemory:getItem(index)

Gets an item at the given index.

Unlike acquireItem, this function is specific to in-memory lists, and its semantics do not require managing resources. When writing generic code over lists acquireItem and releaseItem should be used instead.

Parameters
index (number)

Index of the item.

Return Values
(DataObject)
DataObjectListInMemory.DataObjectListInMemory:iterateItems()

Returns an iterator that you can use to iterate over items of a data object list.