2018-12-29 16:05:19 -08:00
|
|
|
# Array
|
|
|
|
|
2019-02-02 18:06:35 -08:00
|
|
|
While ZScript does not have proper user-facing generics, `Array` is one such
|
2019-02-02 18:07:05 -08:00
|
|
|
type that does have a (hard-coded) type parameter. It mirrors the internal
|
|
|
|
`TArray` type exactly. Note that all Object types monomorphize to the same
|
|
|
|
implementation and structures cannot be stored in arrays due to no polymorphic
|
|
|
|
variant of `TArray` existing in the engine.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
```
|
|
|
|
struct Array<Type>
|
|
|
|
{
|
2019-02-02 18:07:05 -08:00
|
|
|
uint Max() const;
|
|
|
|
uint Size() const;
|
|
|
|
|
2018-12-29 16:05:19 -08:00
|
|
|
void Copy(array<Type> other);
|
2019-02-02 18:07:05 -08:00
|
|
|
void Move(array<Type> other);
|
|
|
|
|
|
|
|
void Clear();
|
2018-12-29 16:05:19 -08:00
|
|
|
void Delete(uint index, int deletecount = 1);
|
2019-02-02 18:07:05 -08:00
|
|
|
bool Pop();
|
|
|
|
|
2018-12-29 16:05:19 -08:00
|
|
|
uint Find(Type item) const;
|
|
|
|
void Grow(uint amount);
|
|
|
|
void Insert(uint index, Type item);
|
|
|
|
uint Push(Type item);
|
|
|
|
uint Reserve(uint amount);
|
|
|
|
void Resize(uint amount);
|
|
|
|
void ShrinkToFit();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Max`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Returns the amount of allocated objects in the array.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Size`
|
|
|
|
|
|
|
|
Returns the amount of constructed objects in the array.
|
|
|
|
|
|
|
|
- `Clear`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Clears out the entire array, possibly destroying all objects in it.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
- `Delete`
|
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Removes `count` objects starting at `index`, possibly destroying them. Moves
|
|
|
|
objects after `index + count` to the left.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Pop`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Removes the last item in the array, possibly destroying it. Returns `false`
|
|
|
|
if there are no items in the array to begin with.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Copy`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Value-copies another array's contents into this array. The contents of
|
|
|
|
`other` are preserved. This operation can be extremely taxing in some cases.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Move`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Moves another array's contents into this array. The contents of `other` are
|
|
|
|
left indeterminate and shall not be used. This operation is extremely fast
|
|
|
|
as it only copies pointers but must be used carefully to avoid error.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Find`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Finds the index of `item` in the array, or `Size` if it couldn't be found.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Grow`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Ensures the array can hold at least `amount` new members, growing the
|
|
|
|
allocated object amount if necessary.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
- `Insert`
|
2018-12-29 16:05:19 -08:00
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Inserts `item` at `index`. Moves objects after `index` to the right.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
- `Push`
|
|
|
|
|
|
|
|
Places `item` at the end of the array, calling `Grow` if necessary.
|
|
|
|
|
|
|
|
- `Reserve`
|
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Adds `amount` new empty-constructed objects at the end of the array,
|
|
|
|
increasing `Size` and calling `Grow` if necessary. Value types are
|
|
|
|
initialized to zero and reference types to `null`.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
- `Resize`
|
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Adds or removes objects based on `amount`. If it is less than `Size` then
|
|
|
|
objects are destroyed, if it is more then objects are empty-constructed. New
|
|
|
|
objects follow the same initialization rules as `Reserve`.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
- `ShrinkToFit`
|
|
|
|
|
2019-02-02 18:07:05 -08:00
|
|
|
Shrinks `Max` to `Size`. Does not mutate any objects in the array.
|
2018-12-29 16:05:19 -08:00
|
|
|
|
|
|
|
<!-- EOF -->
|