Skip to main content

%Library.ListOfObjects

Class %Library.ListOfObjects Extends (%Collection.AbstractListOfObj, %SerialObject) [ ClassType = serial, OdbcType = VARCHAR, StorageStrategy = Custom, System = 2 ]

For information on this class, see Working with Collections.

The %ListOfObjects class represents a list of references to objects, each of which is associated with a numeric position in the list. The first element in the list is stored at position 1. The objects referred to must be registered. They can be either persistent objects or non-id objects.

Internally, a %ListOfObjects object contains two lists: one for holding the OID values for the objects referred to (or their serialized state in the case of a list of non-id objects); and another for holding the OREF values for any objects that have been explicitly referred to, and hence "swizzled" into memory. Swizzling (loading an object into memory and generating an OREF value for it) happens automatically whenever the user refers to an object within the list. For example, if list is an %ListOfObjects object containing a list of Doctor objects (that is a list of OID values for Doctor objects stored in the database) then the following code fragment will automatically load the Doctor object at location 7 in the list into memory and generate an OREF value referring to the in-memory version of the Doctor object. This OREF value can then be used to access the properties and methods of the Doctor object: Set doc=list.GetAt(7) Write doc.Name Alternatively, we could use cascading dot syntax: Set name=list.GetAt(7).Name When the %ListOfObjects object is closed (removed from memory) it will close (call %Close on) all the references it has swizzled into memory. These classes can be used 'standalone' to store a collection.

Parameters

CLASSNAMEINOID

Parameter CLASSNAMEINOID = 0;

This parameter determines how the collection object stores OID values. If this parameter is set to 0, then partially-formed OID values, containing only an ID number, are used. If this parameter is set to 1, then fully-formed OID values, containing both a class name and an ID number, are used.

ELEMENTTYPE

Parameter ELEMENTTYPE = "%RegisteredObject";

The type (class name) of the elements stored in the collection.

Properties

Oref

Property Oref As %RawString [ MultiDimensional ];

Private storage area used to hold OREF values.

ElementType

Property ElementType As %RawString [ InitialExpression = {..#ELEMENTTYPE} ];

The type (class name) of the elements stored in the collection.

Data

Property Data As %RawString [ MultiDimensional ];

Data is a private property used to hold the contents of the list.

Size

Property Size As %Integer [ InitialExpression = 0 ];

Size is the number of elements contained in the list.

Methods

SizeSet

Method SizeSet(newvalue As %Integer) As %Status [ Private ]

Count

Method Count() As %Integer [ CodeMode = expression, Final ]

Returns the number of elements contained in the list.

InsertList

Method InsertList(inslist As %RawString) As %Status

Inserts a list with value inslist at the end of the list.

Returns a %Status value indicating success or failure.

InsertOrdered

Method InsertOrdered(element As %RawString) As %Status

Inserts an element with value element into the list at the correct ordered position. The elements in the list are shifted to accommodate the new element as necessary.

Returns a %Status value indicating success or failure.

Next

Method Next(key As %Integer = 0) As %Integer [ CodeMode = expression, Final ]

Finds and returns the index value of the element at the location following key in the list. If key is a null string (""), then Next returns the position of the first element in the list (1).

Previous

Method Previous(key As %Integer = 0) As %Integer [ CodeMode = expression, Final ]

Finds and returns the index value of the element at the location preceding key in the list. If key is a null string (""), then Next returns the position of the last element in the list.

BuildValueArray

ClassMethod BuildValueArray(serialized As %Binary, array As %Binary) As %Status

Constructs array(key)=value for each element in the serialval value.

Returns a %Status value indicating success or failure.

Clear

Method Clear() As %Status

Clears the contents of the array. Both the OID and OREF values are cleared.

Returns a %Status value indicating success or failure.

Find

Method Find(element As %ObjectIdentity, key As %Integer) As %String [ CodeMode = generator ]

Starting from, but not including, position key, Find finds the next element in the list whose OID value equals element. If key is a null string, Find starts at the beginning of the list.

Find returns the position of the found element or null string ("") if no element was found.

FindObjectId

Method FindObjectId(id As %String, key As %Integer) As %String

Starting from, but not including, position key, FindObjectId finds the next element in the list whose ObjectId equals id. If key is a null string, Find starts at the beginning of the list.

Find returns the position of the found element or null string ("") if no element was found.

GetAt

Method GetAt(key As %Integer) As %RegisteredObject

Finds and returns the OREF value referring to the object at position key in the list.

GetAt returns the value of the element at location key or null string ("") if no element is found.

GetObjectAt

Method GetObjectAt(key As %Integer, force As %Integer = 0) As %ObjectIdentity

Finds and returns the OID value referring to the object at position key in the list.

Returns the value of the element at location key or null string ("") if no element is found.

GetObjectIdAt

Method GetObjectIdAt(key As %Integer, force As %Integer = 0) As %String [ CodeMode = expression, Final ]

Finds and returns the ID value referring to the object at position key in the list.

Returns the value of the element at location key or null string ("") if no element is found.

GetNext

Method GetNext(ByRef key As %Integer) As %RegisteredObject

Finds and returns the OREF value referring to the object at the position after key in the list. If key is a null string (""), it returns the OREF value of the first element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the end of the list.

GetObjectNext

Method GetObjectNext(ByRef key As %Integer) As %ObjectIdentity

Finds and returns the OID value referring to the object at the position after key in the list. If key is a null string (""), it returns the OID value of the first element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the end of the list.

GetObjectIdNext

Method GetObjectIdNext(ByRef key As %Integer) As %String [ CodeMode = expression, Final ]

Finds and returns the ID value referring to the object at the position after key in the list. If key is a null string (""), it returns the ID value of the first element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the end of the list.

GetPrevious

Method GetPrevious(ByRef key As %Integer) As %RegisteredObject

Finds and returns the OREF value referring to the object at the position before key in the list. If key is a null string (""), it returns the OREF value of the last element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the beginning of the list.

GetObjectPrevious

Method GetObjectPrevious(ByRef key As %Integer) As %ObjectIdentity

Finds and returns the OID value referring to the object at the position before key in the list. If key is a null string (""), it returns the OID value of the last element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the beginning of the list.

GetObjectIdPrevious

Method GetObjectIdPrevious(ByRef key As %Integer) As %String [ CodeMode = expression, Final ]

Finds and returns the ID value referring to the object at the position before key in the list. If key is a null string (""), it returns the ID value of the last element in the list.

The value of key, which is passed by reference, is updated to the position value of the returned element or null string ("") if key is at the beginning of the list.

Insert

Method Insert(oref As %RegisteredObject) As %Status

Inserts an element with OREF value oref at the end of the list.

Returns a %Status value indicating success or failure.

InsertObject

Method InsertObject(oid As %ObjectIdentity) As %Status

Inserts an element with OID value oid at the end of the list.

Returns a %Status value indicating success or failure.

InsertObjectId

Method InsertObjectId(id As %String) As %Status [ CodeMode = expression, Final ]

Inserts an element with ID value id at the end of the list.

Returns a %Status value indicating success or failure.

InsertAt

Method InsertAt(oref As %RegisteredObject, key As %Integer) As %Status

Inserts an element with OREF value oref at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:

1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.

InsertObjectAt

Method InsertObjectAt(oid As %ObjectIdentity, key As %Integer) As %Status

Inserts an element with OID value oid at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:

1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.

InsertObjectIdAt

Method InsertObjectIdAt(id As %String, key As %Integer) As %Status [ CodeMode = expression, Final ]

Inserts an element with ID value id at position key.

To make room for the new element, the elements previously at or following position key are moved up by one position.

key must be in the following range:

1 <= index <= Count() + 1

Returns a %Status value indicating success or failure.

RemoveAt

Method RemoveAt(key As %Integer, Output success As %Boolean) As %ObjectIdentity

Removes the element at position key in the list. The elements following position key are moved to fill in the resulting gap.

RemoveAt returns the OID value of the removed element or null string ("") if no element was removed. It also has a success output argument that returns true if the item was removed and false if it was not.

SetAt

Method SetAt(oref As %RegisteredObject, key As %Integer) As %Status

Sets the OREF value of the element at position key to oref.

Returns a %Status value indicating success or failure.

SetObjectAt

Method SetObjectAt(oid As %ObjectIdentity, key As %Integer) As %Status

Sets the OID value of the element at position key to oid.

Returns a %Status value indicating success or failure.

SetObjectIdAt

Method SetObjectIdAt(id As %String, key As %Integer) As %Status [ CodeMode = expression, Final ]

Sets the ID value of the element at position key to id.

Returns a %Status value indicating success or failure.

%AddToSaveSet

Method %AddToSaveSet(force As %Integer = 0, refresh As %Integer = 0) As %Status

Overrides %SerialObject implementation. Scans objects for modifications in the related list (Element) and the terminated relationship list (DeleteOref). Modified/Scheduled to delete objects are added to the save graph.

%SerializeObject

Method %SerializeObject(ByRef serial As %Binary, partial As %Integer = 0) As %Status

%UnSwizzleAt

Method %UnSwizzleAt(key As %Integer, force As %Integer = 0) As %Status

Unswizzles (removes from memory) the individual element at position key in the list.

Returns a %Status value indicating success or failure.

%GetSerial

Method %GetSerial(force As %Integer = 0) As %String [ CodeMode = generator, Private ]

%SetSerial

Method %SetSerial(serialized As %String) As %Status [ Private ]

%OnConstructClone

Method %OnConstructClone(oref As %RegisteredObject, deep As %Boolean = 0, ByRef cloned As %String) As %Status [ Private ]

%OnNew

Method %OnNew(initvalue As %String) As %Status [ Private ]