Home > Class Reference > ENSLIB namespace > %Library.ListOfObjects

%Library.ListOfObjects

serial class %Library.ListOfObjects extends %Collection.AbstractListOfObj, %Library.SerialObject

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 'stand alone' to store a collection.

Parameters

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.
parameter ELEMENTTYPE = %RegisteredObject;
The type (class name) of the elements stored in the collection.

Properties

property Data as %CacheString [ MultiDimensional ];
Data is a private property used to hold the contents of the list.
Property methods: DataGet(), DataIsValid(), DataSet()
property ElementType as %CacheString [ InitialExpression = ..#ELEMENTTYPE ];
The type (class name) of the elements stored in the collection.
Property methods: ElementTypeGet(), ElementTypeIsValid(), ElementTypeSet()
property Oref as %CacheString [ MultiDimensional ];
Private storage area used to hold OREF values.
Property methods: OrefGet(), OrefIsValid(), OrefSet()
property Size as %Integer [ InitialExpression = 0 ];
Size is the number of elements contained in the list.
Property methods: SizeDisplayToLogical(), SizeGet(), SizeIsValid(), SizeLogicalToDisplay(), SizeNormalize(), SizeSet()

Methods

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.
method %SerializeObject(ByRef serial As %Binary, partial As %Integer = 0) as %Status
Inherited description: This method retrieves all of the serial values for referenced objects and places them into the instance variables, Validates, Normalizes, and serializes the object (with a save of the persistent image if persistent).
This method is not meant to be called directly. It is called by %Save and by %GetSwizzleObject.
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.

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.

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.

final method Count() as %Integer
Returns the number of elements contained in the list.
method Find(element As %ObjectIdentity, key As %Integer) as %String
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.

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.

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.

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.

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.

final method GetObjectIdAt(key As %Integer, force As %Integer = 0) as %String
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.

final method GetObjectIdNext(ByRef key As %Integer) as %String
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.

final method GetObjectIdPrevious(ByRef key As %Integer) as %String
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.

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