Turok
 
Loading...
Searching...
No Matches
array< T > Class Template Reference

Public Member Functions

void insertAt (uint index, const T &in value)
 Inserts a new element into the array at the specified index.
 
void insertAt (uint index, const T[]&inout arr)
 Inserts another array of elements into the array at the specified index.
 
void insertLast (const T &in value)
 Appends an element at the end of the array.
 
void removeAt (uint index)
 Removes the element at the specified index.
 
void removeLast ()
 Removes the last element of the array.
 
void removeRange (uint start, uint count)
 Removes count elements starting from start.
 
uint length () const
 Returns the length of the array.
 
void reserve (uint length)
 
void resize (uint length)
 Sets the new length of the array.
 
void sortAsc ()
 Sorts the elements in the array in ascending order. For object types, this will use the type's opCmp method.
 
void sortAsc (uint startAt, uint count)
 Sorts only the elements starting at index startAt and the following count elements in the array in ascending order. For object types, this will use the type's opCmp method.
 
void sortDesc ()
 Sorts the elements in the array in descending order. For object types, this will use the type's opCmp method.
 
void sortDesc (uint startAt, uint count)
 Sorts only the elements starting at index startAt and the following count elements in the array in descending order. For object types, this will use the type's opCmp method.
 
void reverse ()
 Reverses the order of the elements in the array.
 
int find (const T &in value) const
 Returns the index of the first element that has the same value as the wanted value. For object types, this will use the type's opEquals or opCmp method to compare the value. For arrays of handles any null handle will be skipped. If no match is found will return a negative value.
 
int find (uint startAt, const T &in value) const
 Returns the index of the first element that has the same value as the wanted value. For object types, this will use the type's opEquals or opCmp method to compare the value. For arrays of handles any null handle will be skipped. If no match is found will return a negative value.
 
int findByRef (const T &in value) const
 Searches for a matching address. These are especially useful for arrays of handles where specific instances of objects are desired, and not just objects that happen to have equal value. If no match is found will return a negative value.
 
int findByRef (uint startAt, const T &in value) const
 Searches for a matching address. These are especially useful for arrays of handles where specific instances of objects are desired, and not just objects that happen to have equal value. If no match is found will return a negative value.
 
bool isEmpty () const
 
T & opIndex (uint index)
 
const T & opIndex (uint index) const
 
T &[] opAssign (const T[]&in)
 
bool opEquals (const T[]&in) const
 
funcdef bool less (const ?&in a, const ?&in b)
 sorting function for sort
 
void sort (less &in, uint startAt=0, uint count=uint(- 1))
 sorts array using the passed in less function
 

Detailed Description

template<class T>
class array< T >

It is possible to declare array variables with the array identifier followed by the type of the elements within angle brackets.

Example:

@code{.cpp}
  array<int> a, b, c;
  array<Foo@> d;
@endcode  

a, b, and c are now arrays of integers, and d is an array of handles to objects of the Foo type.

When declaring arrays it is possible to define the initial size of the array by passing the length as a parameter to the constructor. The elements can also be individually initialized by specifying an initialization list. Example:

@code{.cpp}
  array<int> a;           // A zero-length array of integers
  array<int> b(3);        // An array of integers with 3 elements
  array<int> c(3, 1);     // An array of integers with 3 elements, all set to 1 by default
  array<int> d = {5,6,7}; // An array of integers with 3 elements with specific values
@endcode  

Multidimensional arrays are supported as arrays of arrays, for example:

@code{.cpp}
  array<array<int>> a;                     // An empty array of arrays of integers
  array<array<int>> b = {{1,2},{3,4}}      // A 2 by 2 array with initialized values
  array<array<int>> c(10, array<int>(10)); // A 10 by 10 array of integers with uninitialized values
@endcode  

Each element in the array is accessed with the indexing operator. The indices are zero based, i.e. the range of valid indices are from 0 to length - 1.

@code{.cpp}
    a[0] = some_value;
@endcode  

When the array stores handles the elements are assigned using the handle assignment.

@code{.cpp}
  // Declare an array with initial length 1
  array<Foo@> arr(1);
@endcode  

@code{.cpp}
    // Set the first element to point to a new instance of Foo
    @arr[0] = Foo();
@endcode  

Arrays can also be created and initialized within expressions as anonymous objects.

@code{.cpp}
  // Call a function that expects an array of integers as input
  foo(array<int> = {1,2,3,4});
@endcode  

Definition at line 540 of file t1_scriptAPI.cpp.

Member Function Documentation

◆ find() [1/2]

template<class T>
int array< T >::find ( const T &in value) const

Returns the index of the first element that has the same value as the wanted value. For object types, this will use the type's opEquals or opCmp method to compare the value. For arrays of handles any null handle will be skipped. If no match is found will return a negative value.

◆ find() [2/2]

template<class T>
int array< T >::find ( uint startAt,
const T &in value ) const

Returns the index of the first element that has the same value as the wanted value. For object types, this will use the type's opEquals or opCmp method to compare the value. For arrays of handles any null handle will be skipped. If no match is found will return a negative value.

◆ findByRef() [1/2]

template<class T>
int array< T >::findByRef ( const T &in value) const

Searches for a matching address. These are especially useful for arrays of handles where specific instances of objects are desired, and not just objects that happen to have equal value. If no match is found will return a negative value.

◆ findByRef() [2/2]

template<class T>
int array< T >::findByRef ( uint startAt,
const T &in value ) const

Searches for a matching address. These are especially useful for arrays of handles where specific instances of objects are desired, and not just objects that happen to have equal value. If no match is found will return a negative value.

◆ insertAt() [1/2]

template<class T>
void array< T >::insertAt ( uint index,
const T &in value )

Inserts a new element into the array at the specified index.

◆ insertAt() [2/2]

template<class T>
void array< T >::insertAt ( uint index,
const T &[]inout arr )

Inserts another array of elements into the array at the specified index.

◆ insertLast()

template<class T>
void array< T >::insertLast ( const T &in value)

Appends an element at the end of the array.

◆ isEmpty()

template<class T>
bool array< T >::isEmpty ( ) const

◆ length()

template<class T>
uint array< T >::length ( ) const

Returns the length of the array.

◆ less()

template<class T>
funcdef bool array< T >::less ( const ?&in a,
const ?&in b )

sorting function for sort

◆ opAssign()

template<class T>
T &[] array< T >::opAssign ( const T &[] in)

◆ opEquals()

template<class T>
bool array< T >::opEquals ( const T &[] in) const

◆ opIndex() [1/2]

template<class T>
T & array< T >::opIndex ( uint index)

◆ opIndex() [2/2]

template<class T>
const T & array< T >::opIndex ( uint index) const

◆ removeAt()

template<class T>
void array< T >::removeAt ( uint index)

Removes the element at the specified index.

◆ removeLast()

template<class T>
void array< T >::removeLast ( )

Removes the last element of the array.

◆ removeRange()

template<class T>
void array< T >::removeRange ( uint start,
uint count )

Removes count elements starting from start.

◆ reserve()

template<class T>
void array< T >::reserve ( uint length)

◆ resize()

template<class T>
void array< T >::resize ( uint length)

Sets the new length of the array.

◆ reverse()

template<class T>
void array< T >::reverse ( )

Reverses the order of the elements in the array.

◆ sort()

template<class T>
void array< T >::sort ( less & in,
uint startAt = 0,
uint count = uint(- 1) )

sorts array using the passed in less function

◆ sortAsc() [1/2]

template<class T>
void array< T >::sortAsc ( )

Sorts the elements in the array in ascending order. For object types, this will use the type's opCmp method.

◆ sortAsc() [2/2]

template<class T>
void array< T >::sortAsc ( uint startAt,
uint count )

Sorts only the elements starting at index startAt and the following count elements in the array in ascending order. For object types, this will use the type's opCmp method.

◆ sortDesc() [1/2]

template<class T>
void array< T >::sortDesc ( )

Sorts the elements in the array in descending order. For object types, this will use the type's opCmp method.

◆ sortDesc() [2/2]

template<class T>
void array< T >::sortDesc ( uint startAt,
uint count )

Sorts only the elements starting at index startAt and the following count elements in the array in descending order. For object types, this will use the type's opCmp method.