Class Array
Template for dynamic array with variable capacity.
Inheritance
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Core/Collections/Array.h
Syntax
public class Array<T, AllocationType>
Type Parameters
T
The type of elements in the array. |
AllocationType
The type of memory allocator. |
Constructors
~Array()
Array(Array&& other)
Initializes Array by moving the content of the other collection.
Declaration
public Array(Array&& other) noexcept
Parameters
Array
other
The other collection to move. |
Array(const Array<Other, OtherAllocationType>& other)
Initializes Array by copying the elements from the other collection.
Declaration
public Array(const Array<Other, OtherAllocationType>& other) noexcept
Parameters
Array<Other, OtherAllocationType>
other
The other collection to copy. |
Type Parameters
typename Other
|
typename OtherAllocationType
|
Array(const T* data, const int32 length)
Initializes Array by copying elements.
Declaration
public Array(const T* data, const int32 length)
Parameters
T
data
The initial data. |
int32
length
The amount of items. |
Methods
Add(const Array<Other, OtherAllocationType>& other)
Adds the other collection to the collection.
Declaration
public void Add(const Array<Other, OtherAllocationType>& other)
Parameters
Array<Other, OtherAllocationType>
other
The other collection to add. |
Returns
void
|
Type Parameters
typename Other
|
typename OtherAllocationType
|
Add(const T& item)
Adds the specified item to the collection.
Declaration
public void Add(const T& item)
Parameters
T
item
The item to add. |
Add(const T* items, const int32 count)
Adds the specified item to the collection.
Declaration
public void Add(const T* items, const int32 count)
Parameters
T
items
The items to add. |
int32
count
The items count. |
Add(T&& item)
Adds the specified item to the collection.
Declaration
public void Add(T&& item)
Parameters
T
item
The item to add. |
AddDefault(const int32 count=1)
Adds the given amount of items to the collection.
Declaration
public void AddDefault(const int32 count=1)
Parameters
int32
count
The items count. |
Returns
void
|
AddOne()
Adds the one item to the collection and returns the reference to it.
Declaration
public T AddOne()
Returns
T
The reference to the added item. |
AddUninitialized(const int32 count=1)
Adds the given amount of uninitialized items to the collection without calling the constructor.
Declaration
public void AddUninitialized(const int32 count=1)
Parameters
int32
count
The items count. |
Returns
void
|
AddUnique(const T& item)
Adds the unique item to the collection if it doesn't exist.
Declaration
public void AddUnique(const T& item)
Parameters
T
item
The item to add. |
Returns
void
|
AddZeroed(const int32 count=1)
Adds the new items to the end of the collection, possibly reallocating the whole collection to fit. The new items will be zeroed.
Warning! AddZeroed() will create items without calling the constructor and this is not appropriate for item types that require a constructor to function properly.
Declaration
public void AddZeroed(const int32 count=1)
Parameters
int32
count
The number of new items to add. |
Array()
Initializes an empty Array without reserving any space.
Declaration
public Array()
Returns
FORCE_INLINE
|
Array(const Array& other)
Initializes Array by copying the elements from the other collection.
Declaration
public Array(const Array& other)
Parameters
Array
other
The other collection to copy. |
Returns
FORCE_INLINE
|
Array(const int32 capacity)
Initializes Array by reserving space.
Declaration
public Array(const int32 capacity)
Parameters
int32
capacity
The number of elements that can be added without a need to allocate more memory. |
Returns
FORCE_INLINE
|
Array(std::initializer_list<T> initList)
Initializes Array by copying listed elements.
Declaration
public Array(std::initializer_list<T> initList)
Parameters
std::initializer_list<T>
initList
The initial values defined in the array. |
Returns
FORCE_INLINE
|
At(const int32 index)
Gets item at the given index.
Declaration
public T At(const int32 index)
Parameters
int32
index
|
Returns
T
The reference to the item. |
begin()
Declaration
public T* begin()
Returns
T
|
Begin()
Gets iterator for beginning of the collection.
Declaration
public Iterator Begin() const
Returns
Iterator
|
Capacity()
Gets the amount of the items that can be contained by collection without resizing.
Declaration
public int32 Capacity() const
Returns
int32
|
Clear()
Clear the collection without changing its capacity.
Declaration
public void Clear()
ClearDelete()
Clears the collection without changing its capacity. Deletes all not null items. Note: collection must contain pointers to the objects that have public destructor and be allocated using New method.
Declaration
public void ClearDelete()
Contains(const Other& item)
Determines whether the collection contains the specified item.
Declaration
public bool Contains(const Other& item) const
Parameters
Other
item
The item to check. |
Returns
bool
True if item has been found in the collection, otherwise false. |
Type Parameters
typename Other
|
Count()
Gets the amount of the items in the collection.
Declaration
public int32 Count() const
Returns
int32
|
Dequeue()
Performs dequeue from queue operation (queue head is in the beginning of queue).
Declaration
public T Dequeue()
Returns
T
The item. |
end()
Declaration
public T* end()
Returns
T
|
End()
Gets iterator for ending of the collection.
Declaration
public Iterator End() const
Returns
Iterator
|
Enqueue(const T& item)
Performs enqueue to queue operation (queue head is in the beginning of queue).
Declaration
public void Enqueue(const T& item)
Parameters
T
item
The item to append. |
Enqueue(T&& item)
Performs enqueue to queue operation (queue head is in the beginning of queue).
Declaration
public void Enqueue(T&& item)
Parameters
T
item
The item to append. |
EnsureCapacity(const int32 minCapacity, const bool preserveContents=true)
Ensures the collection has given capacity (or more).
Declaration
public void EnsureCapacity(const int32 minCapacity, const bool preserveContents=true)
Parameters
int32
minCapacity
The minimum capacity. |
bool
preserveContents
True if preserve collection data when changing its size, otherwise collection after resize will be empty. |
Find(const ComparableType& item)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection.
Declaration
public int32 Find(const ComparableType& item) const
Parameters
ComparableType
item
The item to find. |
Returns
int32
The zero-based index of the first occurrence of itm within the entire collection, if found; otherwise, -1. |
Type Parameters
typename ComparableType
|
Find(const ComparableType& item, int32& index)
Searches for the given item within the entire collection.
Declaration
public bool Find(const ComparableType& item, int32& index) const
Parameters
ComparableType
item
The item to look for. |
int32
index
The found item index, -1 if missing. |
Returns
bool
True if found, otherwise false. |
Type Parameters
typename ComparableType
|
FindLast(const ComparableType& item)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection starting from the end.
Declaration
public int32 FindLast(const ComparableType& item) const
Parameters
ComparableType
item
The item to find. |
Returns
int32
The zero-based index of the first occurrence of itm within the entire collection, if found; otherwise, -1. |
Type Parameters
typename ComparableType
|
FindLast(const ComparableType& item, int& index)
Searches for the given item within the entire collection starting from the end.
Declaration
public bool FindLast(const ComparableType& item, int& index) const
Parameters
ComparableType
item
The item to look for. |
int
index
The found item index, -1 if missing. |
Returns
bool
True if found, otherwise false. |
Type Parameters
typename ComparableType
|
First()
Gets the first item.
Declaration
public T First()
Returns
T
|
Get()
Gets the pointer to the first item in the collection (linear allocation).
Declaration
public T* Get()
Returns
T
|
HasItems()
Returns true if collection isn't empty.
Declaration
public bool HasItems() const
Returns
bool
|
Insert(const int32 index)
Insert the given item at specified index with keeping items order.
Declaration
public void Insert(const int32 index)
Parameters
int32
index
The zero-based index at which item should be inserted. |
Insert(const int32 index, const T& item)
Insert the given item at specified index with keeping items order.
Declaration
public void Insert(const int32 index, const T& item)
Parameters
int32
index
The zero-based index at which item should be inserted. |
T
item
The item to be inserted by copying. |
Insert(const int32 index, T&& item)
Insert the given item at specified index with keeping items order.
Declaration
public void Insert(const int32 index, T&& item)
Parameters
int32
index
The zero-based index at which item should be inserted. |
T
item
The item to inserted by moving. |
IsEmpty()
Returns true if collection is empty.
Declaration
public bool IsEmpty() const
Returns
bool
|
IsValidIndex(const int32 index)
Determines if given index is valid.
Declaration
public bool IsValidIndex(const int32 index) const
Parameters
int32
index
The index. |
Returns
bool
|
Last()
Gets the last item.
Declaration
public T Last()
Returns
T
|
operator!=(const Array<Other, OtherAllocationType>& other)
Declaration
public bool operator!=(const Array<Other, OtherAllocationType>& other) const
Parameters
Array<Other, OtherAllocationType>
other
|
Returns
bool
|
Type Parameters
typename Other
|
typename OtherAllocationType
|
operator[](const int32 index)
Gets or sets the item at the given index.
Declaration
public T operator[](const int32 index)
Parameters
int32
index
|
Returns
T
The reference to the item. |
operator=(Array&& other)
The move assignment operator that deletes the current collection of items and the moves items from the other array.
Declaration
public Array operator=(Array&& other) noexcept
Parameters
Array
other
The other collection to move. |
Returns
Array
The reference to this. |
operator=(const Array& other)
The assignment operator that deletes the current collection of items and the copies items from the other array.
Declaration
public Array operator=(const Array& other) noexcept
Parameters
Array
other
The other collection to copy. |
Returns
Array
The reference to this. |
operator=(std::initializer_list<T> initList)
The assignment operator that deletes the current collection of items and the copies items from the initializer list.
Declaration
public Array operator=(std::initializer_list<T> initList) noexcept
Parameters
std::initializer_list<T>
initList
The other collection to copy. |
Returns
Array
The reference to this. |
operator==(const Array<Other, OtherAllocationType>& other)
Declaration
public bool operator==(const Array<Other, OtherAllocationType>& other) const
Parameters
Array<Other, OtherAllocationType>
other
|
Returns
bool
|
Type Parameters
typename Other
|
typename OtherAllocationType
|
Peek()
Peeks items which is at the top of the stack (stack grows at the end of the collection).
Declaration
public T Peek()
Returns
T
|
Pop()
Performs pop from stack operation (stack grows at the end of the collection).
Declaration
public T Pop()
Returns
T
|
Push(const T& item)
Performs push on stack operation (stack grows at the end of the collection).
Declaration
public void Push(const T& item)
Parameters
T
item
The item to append. |
Returns
void
|
Remove(const T& item)
Removes the first occurrence of a specific object from the collection.
Declaration
public bool Remove(const T& item)
Parameters
T
item
The item to remove. |
Returns
bool
True if cannot remove item from the collection because cannot find it, otherwise false. |
RemoveAll(const T& item)
Removes all occurrence of a specific object from the collection.
Declaration
public void RemoveAll(const T& item)
Parameters
T
item
The item to remove. |
RemoveAllKeepOrder(const T& item)
Removes all occurrence of a specific object from the collection and keeps order of the items in the collection.
Declaration
public void RemoveAllKeepOrder(const T& item)
Parameters
T
item
The item to remove. |
RemoveAt(const int32 index)
Removes the item at the specified index of the collection.
Declaration
public void RemoveAt(const int32 index)
Parameters
int32
index
The zero-based index of the item to remove. |
RemoveAtKeepOrder(const int32 index)
Removes the item at the specified index of the collection and keeps order of the items in the collection.
Declaration
public void RemoveAtKeepOrder(const int32 index)
Parameters
int32
index
The zero-based index of the item to remove. |
RemoveKeepOrder(const T& item)
Removes the first occurrence of a specific object from the collection and keeps order of the items in the collection.
Declaration
public bool RemoveKeepOrder(const T& item)
Parameters
T
item
The item to remove. |
Returns
bool
True if cannot remove item from the collection because cannot find it, otherwise false. |
RemoveLast()
Removes the last items from the collection.
Declaration
public void RemoveLast()
Resize(const int32 size, const bool preserveContents=true)
Resizes the collection to the specified size. If the size is equal or less to the current capacity no additional memory reallocation in performed.
Declaration
public void Resize(const int32 size, const bool preserveContents=true)
Parameters
int32
size
The new collection size. |
bool
preserveContents
True if preserve collection data when changing its size, otherwise collection after resize might not contain the previous data. |
Reverse()
Reverses the order of the added items in the collection.
Declaration
public void Reverse()
Set(const T* data, const int32 count)
Sets the collection data.
Declaration
public void Set(const T* data, const int32 count)
Parameters
T
data
The data. |
int32
count
The amount of items. |
SetAll(const T& value)
Sets all items to the given value
Declaration
public void SetAll(const T& value)
Parameters
T
value
The value to assign to all the collection items. |
SetCapacity(const int32 capacity, const bool preserveContents=true)
Changes the capacity of the collection.
Declaration
public void SetCapacity(const int32 capacity, const bool preserveContents=true)
Parameters
int32
capacity
The new capacity. |
bool
preserveContents
True if preserve collection data when changing its size, otherwise collection after resize will be empty. |
Swap(Array& other)
Swaps the contents of collection with the other object without copy operation. Performs fast internal data exchange.
Declaration
public void Swap(Array& other)
Parameters
Array
other
The other collection. |