Difference between revisions of "ObjectType:index"

From Lavish Software Wiki
Jump to navigation Jump to search
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{ObjectType-Vitals|index|[[LavishScript]]|[[ObjectType:objectcontainer|objectcontainer]]|NULL|[[ObjectType:index|index]]|yes|LSIndex *}}
 
== Description ==
 
== Description ==
{{ObjectType-Vitals|index|[[LavishScript]]|[[ObjectType:objectcontainer|objectcontainer]]|NULL|[[ObjectType:index|index]]|yes|LSIndex *}}
 
 
An index is a dynamically-sized list of objects.  In contrast to [[ObjectType:array|arrays]], elements in an index are not created when the index is sized -- the elements do not exist until set.   
 
An index is a dynamically-sized list of objects.  In contrast to [[ObjectType:array|arrays]], elements in an index are not created when the index is sized -- the elements do not exist until set.   
  
Line 6: Line 6:
  
 
An Index cannot have multiple dimensions, but you can create an array of indexes.
 
An Index cannot have multiple dimensions, but you can create an array of indexes.
 +
  
 
== Members ==
 
== Members ==
Line 13: Line 14:
 
*[[ObjectType:mutablestring|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.
 
*[[ObjectType:mutablestring|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.
 
*[[ObjectType:mutablestring|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.
 
*[[ObjectType:mutablestring|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.
 +
*[[ObjectType:unistring|unistring]] '''AsJSON''': Returns a JSON array representation of this index, with each element converted by using its AsJSON member
 +
  
 
== Methods ==
 
== Methods ==
 +
* '''ForEach['''code''']''': For each element in the index, performs the specified code. The [[TLO:ForEach|ForEach Top-Level Object]] is used to access the Key or Value for each iteration
 
* '''Remove['''#''']''': Removes a single element from the index, by ID
 
* '''Remove['''#''']''': Removes a single element from the index, by ID
 
*'''RemoveByQuery['''uint query_id''']''': Erases any elements in the index matching the given [[LavishScript:Object_Queries|Query]]
 
*'''RemoveByQuery['''uint query_id''']''': Erases any elements in the index matching the given [[LavishScript:Object_Queries|Query]]
Line 23: Line 27:
 
* '''Swap['''#''','''#''']''': Swaps two positions in the index
 
* '''Swap['''#''','''#''']''': Swaps two positions 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.   
 
* '''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.   
 +
* '''Shift['''# position''','''# places''']''': Makes room for # places elements at # position, by shifting toward index.Size. The index will not be implicitly Resized, and elements at the end of the index may be destroyed.
 
* '''Resize['''#''']''': Resizes the index such that it will hold ''at least'' this number of elements.
 
* '''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.''
 
* '''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 ==
Line 34: Line 40:
 
  echo ${VarName.Get[2]} -- same as ${VarName[2]} because index supports it
 
  echo ${VarName.Get[2]} -- same as ${VarName[2]} because index supports it
 
  echo ${VarName.Get[3]} -- same as ${VarName[3]} because index supports it
 
  echo ${VarName.Get[3]} -- same as ${VarName[3]} because index supports it
 +
  
 
== See Also ==
 
== See Also ==
* [[LavishScript:Object Types|LavishScript Object Types]]
+
{{LavishScript:ObjectType}}
 
 
[[Category:LavishScript Object Types]]
 
[[Category:LavishScript]]
 

Revision as of 14:41, 14 October 2019

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

Description

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.

An Index cannot have multiple dimensions, but you can create an array of indexes.


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.
  • unistring AsJSON: Returns a JSON array representation of this index, with each element converted by using its AsJSON member


Methods

  • ForEach[code]: For each element in the index, performs the specified code. The ForEach Top-Level Object is used to access the Key or Value for each iteration
  • Remove[#]: Removes a single element from the index, by ID
  • RemoveByQuery[uint query_id]: Erases any elements in the index matching the given Query
  • RemoveByQuery[uint query_id,bool remove_MATCHES]: Erases any elements in the index that either match or do not match the given Query
  • 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 positions 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.
  • Shift[# position,# places]: Makes room for # places elements at # position, by shifting toward index.Size. The index will not be implicitly Resized, and elements at the end of the index may be destroyed.
  • 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]} -- same as ${VarName[1]} because index supports it
echo ${VarName.Get[2]} -- same as ${VarName[2]} because index supports it
echo ${VarName.Get[3]} -- same as ${VarName[3]} because index supports it


See Also

LavishScript Object Types