Difference between revisions of "ObjectType:index"

From Lavish Software Wiki
Jump to navigation Jump to search
Line 21: Line 21:
 
* '''Insert['''...''']''': Inserts an element in the index.  The parameters will be passed to the object initialization routine for the index sub-type, and an object will be created.  ''The index will be resized to fit the new object if necessary.''
 
* '''Insert['''...''']''': Inserts an element in the index.  The parameters will be passed to the object initialization routine for the index sub-type, and an object will be created.  ''The index will be resized to fit the new object if necessary.''
 
== Examples ==
 
== Examples ==
 +
 
variable index:string VarName
 
variable index:string VarName
  
 
VarName:Insert[one]
 
VarName:Insert[one]
 +
 
VarName:Insert[two]
 
VarName:Insert[two]
 +
 
VarName:Insert[three]
 
VarName:Insert[three]
  
 
echo ${VarName.Get[1]}
 
echo ${VarName.Get[1]}
 +
 
echo ${VarName.Get[2]}
 
echo ${VarName.Get[2]}
 +
 
echo ${VarName.Get[3]}
 
echo ${VarName.Get[3]}
  

Revision as of 10:33, 24 January 2008

Description

Object Type Vitals
index
Defined By LavishScript
Inherits objectcontainer
Reduces To NULL
Variable Object Type index
Uses Sub-Types yes
C/C++ Type LSIndex *

An index is a dynamically-sized list of objects. In contrast to arrays, elements in an index are not created when the index is sized -- the elements do not exist until set.

The index position used by any operation must exist at the time of usage for the operation to be successful (see Resize). The index is not automatically resized for any operation except for Insert.

Members

  • uint Next[#]: Retrieves the ID of the next valid element in the index, given an ID number
  • sub-type Get[#]: Retrieves the #th element in the index
  • uint Insert[...]: Inserts an element in the index. The parameters will be passed to the object initialization routine for the index sub-type, and an object will be created. The returned value is the ID of the new element. The index will be resized to fit the new object if necessary.
  • mutablestring Expand[begin #,length]: Retrieves the text representation of each existing object in the index as quoted parameters, separated by spaces. If no parameters are given to Expand, the entire index will be used. If only the begin # is used, the rest of the index, beginning with the element # specified, will be used. If the length is additionally given, that number of elements from the index will be used, beginning with the element # specified as the beginning.
  • mutablestring ExpandComma[begin #,length]: Retrieves the text representation of each existing object in the index as quoted parameters, separated by commas. If no parameters are given to Expand, the entire index will be used. If only the begin # is used, the rest of the index, beginning with the element # specified, will be used. If the length is additionally given, that number of elements from the index will be used, beginning with the element # specified as the beginning.

Methods

  • Remove[#]: Removes a single element from the index, by ID
  • Collapse: Removes gaps in the index (from removal of elements) by shifting elements toward 1
  • Move[#,#]: Moves an element to a new position in the index, by ID numbers. If an element exists in the new position, it is destroyed
  • Swap[#,#]: Swaps two positiosn in the index
  • Set[#,...]: Creates a new element in the index at the given position (destroying the previous element, if it existed). The additional parameters will be passed to the object initialization routine for the index sub-type, and an object will be created.
  • Resize[#]: Resizes the index such that it will hold at least this number of elements.
  • Insert[...]: Inserts an element in the index. The parameters will be passed to the object initialization routine for the index sub-type, and an object will be created. The index will be resized to fit the new object if necessary.

Examples

variable index:string VarName

VarName:Insert[one]

VarName:Insert[two]

VarName:Insert[three]

echo ${VarName.Get[1]}

echo ${VarName.Get[2]}

echo ${VarName.Get[3]}

See Also