|
GLG Toolkit, JavaScript Library
Version 4.6
|
This group contains methods for accessing elements inside GLG container objects. More...
This group contains methods for accessing elements inside GLG container objects.
Container Methods of the Extended API can be used to add or delete objects from the container at run time.
GLG Container objects include ARRAY (Dynamic Array), LIST and VECTOR objects.
The following composite objects are also containers and may be used with Container Methods:
When a container object is created, one of the creation parameters is the type of elements it will contain (see GlgContainerType for more information):
There are three types of containers:
There are two flavors of container methods:
The Extended API provides additional methods for adding and deleting elements of a container.
Functions | |
| boolean | ContainsObject (Object object) |
| Checks if object belongs to the container. More... | |
| Object | GetElement (int index) |
| Returns element at the specified position in the container. More... | |
| int | GetIndex (Object object) |
| Returns index of the first occurrence of an object in the container. More... | |
| GlgObject | GetNamedObject (String name) |
| Finds an object with the specified name inside the container of GLG objects and returns it. More... | |
| int | GetSize () |
| Returns size of the container object. More... | |
| int | GetStringIndex (String search_string) |
| Returns index of the first occurrence of a string in the container of the STRING type. More... | |
| void | Inverse () |
| Inverses the order of elements inside the container object. More... | |
| boolean | IsAt (GlgPositionType position) |
| Checks the position of the iteration pointer (the current element of the container). More... | |
| Object | Iterate () |
| Traverses the container object's elements in the forward direction. More... | |
| Object | IterateBack () |
| Traverses the container object's elements in the backward direction. More... | |
| boolean | ReorderElement (int current_index, int new_index) |
| Changes an element's position inside the container. More... | |
| void | SetEnd () |
| Initializes the container object for the backward traversing. More... | |
| void | SetStart () |
| Initializes the container object for the forward traversing. More... | |
| boolean ContainsObject | ( | Object | object | ) |
Checks if object belongs to the container.
| object | The object to search for. |
| Object GetElement | ( | int | index | ) |
Returns element at the specified position in the container.
| index | The element's position inside the container. |
If the specified index is invalid, an error message is generated and null is returned.
While the method provides the Intermediate API functionality, it is also available in the Standard API when used with a group object returned by CreateTagList.
| int GetIndex | ( | Object | object | ) |
Returns index of the first occurrence of an object in the container.
| object | The object to search for. |
| GlgObject GetNamedObject | ( | String | name | ) |
Finds an object with the specified name inside the container of GLG objects and returns it.
| name | The object's name. |
| int GetSize | ( | ) |
Returns size of the container object.
For a viewport or group object, the size is the number of objects in the viewport or group. For a polygon, the size is the number of vertices.
While the method provides the Intermediate API functionality, it is also available in the Standard API when used with a group object returned by CreateTagList.
| int GetStringIndex | ( | String | search_string | ) |
| void Inverse | ( | ) |
Inverses the order of elements inside the container object.
| boolean IsAt | ( | GlgPositionType | position | ) |
Checks the position of the iteration pointer (the current element of the container).
| position | The position that is being checked. |
true if the container's current position pointer matches the specified position:
| Object Iterate | ( | ) |
Traverses the container object's elements in the forward direction.
Iterate advances the iteration pointer and returns the next element of the container.
SetStart must be used to initialize the container for iterating before Iterate is invoked the first time. The add, delete and search operations affect the iteration state and should not be performed on the container while it is being iterated.
To perform a safe iteration that is not affected by the add and delete operations, a copy of the container can be created using the CloneObject method with the SHALLOW_CLONE clone type. The shallow copy will return a new container with a list of objects that can be safely iterated while objects are added or deleted from the original container.
Alternatively, GetElement can be used to traverse elements of the container using an element index, which is not affected by the search operations on the container.
The following coding example shows how to iterate all objects in a container using Iterate:
| Object IterateBack | ( | ) |
Traverses the container object's elements in the backward direction.
IterateBack decrements the iteration pointer and returns the previous element of the container.
SetEnd must be used to initialize the container for backward iteration before IterateBack is invoked the first time. The add, delete and search operations affect the iteration state and should not be performed on the container while it is being iterated.
To perform a safe iteration that is not affected by the add and delete operations, a copy of the container can be created using the CloneObject method with the SHALLOW_CLONE clone type. The shallow copy will return a new container with a list of objects that can be safely iterated while objects are added or deleted from the original container.
Alternatively, GetElement can be used to traverse elements of the container using an element index, which is not affected by the search operations on the container.
The following coding example shows how to iterate all objects in a container in the backward direction using IterateBack:
| boolean ReorderElement | ( | int | current_index, |
| int | new_index | ||
| ) |
Changes an element's position inside the container.
| current_index | The index of an element to be reordered. |
| new_index | A new element position. |
This method moves the element at the old_index to the new_index position inside the container. It generates an error message and returns false if indexes are out of range.
| void SetEnd | ( | ) |
Initializes the container object for the backward traversing.
The method sets the current position pointer past the last element of the container, preparing the container object for the backward traversing with IterateBack.
| void SetStart | ( | ) |
Initializes the container object for the forward traversing.
The method sets the current position pointer before the first element of the container, preparing the container object for the forward traversing with Iterate.