Array

Array<T> inherits Object

Construction: Array<T> newObj = Array<T>();
Clone: Array<T> newObj = Array<T>(other);
Container

Overview

Array<T> is a templated container type that is similar to the C++ STL vector. The template type T specifies the type of the elements stored in the array (e.g., Array<int> is an array of integers).

Methods

int Size()

Returns the current number of elements in the array.

bool Empty()

Returns true if there are no elements in the array.

bool Erase(T aData)

Erases the specified array element. The array gets traversed and only the first array element matching the input argument gets erased.

bool EraseAt(int aIndex)

Erases the element at the specified index. aIndex should be in the range [0 – size-1). If the index is out of range, the method returns ‘false’

T Get(int aIndex)

Returns the element located at the specified index. You can use the bracket operator ‘[ ]’ instead of Get (e.g., myArray[0] instead of myArray.Get(0))

void Set(int aIndex, T aData)

Sets the element at the given index to the given value. You can use the bracket operator ‘[ ]’ instead of Set (e.g., myArray[0] = ‘hello’ instead of myArray.Set(0, ‘hello’))

void PushBack(T aData)

Adds the given data to the back of the array.

void Insert(int aIndex, T aVal, [T… vals])

Extends the array by inserting one or more new elements before the element at the specified aIndex, which should be in the range [0, Size()]. For example, an index of 0 will insert at the beginning of the array, an index of Size() will insert at the end of the array (equivalent to PushBack), and any other valid index will insert into the middle of the array. An invalid index will generate a script exception and no elements will be inserted.

void PopBack()

Removes the last element from the array.

void Reverse()

Reverses the array’s elements.

void Sort(bool aAscending)

Sorts the contents of the array. If the parameter is true, it is sorted in ascending order. Otherwise, it is sorted in descending order. Warning: this method is only useful for arrays of variables with homogeneous types that are less-than-comparable.

void Clear()

Clears the array.

T Front()

Returns the first element in the array.

T Back()

Returns the last element in the array.

ArrayIterator GetIterator()

Return an iterator that points to the beginning of the array. This is used by the script language to support the foreach command but may also be used directly.