![]() |
Murl Engine API
Version 2018.3
|
A generic array template class for moveable objects eg. structs or fundamental data types like UInt32, Real, etc. More...
#include <murl_array.h>
A generic array template class for moveable objects eg. structs or fundamental data types like UInt32, Real, etc.
The array class works for moveable objects only, use ObjectArray class for storing non-moveable objects.
This class is based on the NTL Vector container, see http://www.ultimatepp.org
DataType | The value's data type of the array. |
Public Types | |
typedef DataType | ValueType |
The template parameter value type. More... | |
typedef const DataType * | ConstIterator |
Definition of the const iterator. | |
typedef DataType * | Iterator |
Definition of the iterator. | |
Public Member Functions | |
Array () | |
Construct an empty array. | |
Array (const DataType &item) | |
Construct an array containing a single item. More... | |
Array (const DataType &item1, const DataType &item2) | |
Construct an array containing two items. More... | |
Array (const DataType &item1, const DataType &item2, const DataType &item3) | |
Construct an array containing three items. More... | |
Array (const Array &other) | |
Construct an array from an already existing one, performing a deep copy. More... | |
~Array () | |
Destroy the array and all of its contents. | |
void | operator= (const Array &other) |
Assign the content of another array to this one, performing a deep copy. More... | |
void | Clear () |
Clear the array and remove the underlying storage. | |
void | Empty () |
Empty the array, but keep the underlying storage. | |
void | Shrink () |
Shrink the array so that the underlying storage is only as large as necessary. | |
Bool | Trim (SInt32 n) |
Reduce the array to a given number of items. More... | |
Bool | Drop (SInt32 n=1) |
Reduce the array by removing a given number of items from the end. More... | |
void | Reserve (SInt32 n) |
Reserve storage space. More... | |
Bool | SetCount (SInt32 n) |
Set the actual number of items in the array. More... | |
Bool | SetCount (SInt32 n, const DataType &item) |
Set the actual number of items in the array. More... | |
Bool | SetCountAndReserve (SInt32 n) |
Set the actual number of items in the array and reserve extra storage space. More... | |
Bool | SetCountAndReserve (SInt32 n, const DataType &item) |
Set the actual number of items in the array and reserve extra storage space. More... | |
DataType & | Set (SInt32 index, const DataType &item) |
Initialize an item with a given item. More... | |
Bool | Set (SInt32 index, const DataType &item, SInt32 count) |
Initialize a range of items with a given item. More... | |
void | Fill (const DataType &item) |
Fill all items with a given item. More... | |
void | Swap (SInt32 index1, SInt32 index2) |
Swap two array items. More... | |
DataType & | Add () |
Add a new item at the end of the array. More... | |
DataType & | Add (const DataType &item) |
Add a given item at the end of the array. More... | |
void | AddN (SInt32 count) |
Add a given number of new items at the end of the array. More... | |
Bool | Add (const Array &other) |
Add a given array of items at the end of the array. More... | |
Bool | Add (const Array &other, int offset, int count) |
Add a subset of given array of items at the end of the array. More... | |
DataType & | Insert (SInt32 index) |
Insert a new item at a given position. More... | |
DataType & | Insert (SInt32 index, const DataType &item) |
Insert a given item at a given position. More... | |
Bool | Insert (SInt32 index, const DataType &item, SInt32 count) |
Insert a number of copies of a given item at a given position. More... | |
Bool | InsertN (SInt32 index, SInt32 count=1) |
Insert a given number of new items at a given position. More... | |
Bool | Insert (SInt32 index, const Array &other) |
Insert a given array of items at a given position. More... | |
Bool | Insert (SInt32 index, const Array &other, SInt32 offset, SInt32 count) |
Insert a subset of given array of items at a given position. More... | |
DataType | RemoveGet (SInt32 index) |
Remove (and destroy) an item at a given position and get a copy of the item. More... | |
Bool | Remove (SInt32 index, SInt32 count=1) |
Remove (and destroy) a number of items at a given position. More... | |
void | Remove (const SInt32 *sortedIndices, SInt32 count) |
Remove (and destroy) a number of items at given positions. More... | |
void | Remove (const SInt32Array &sortedIndices) |
Remove (and destroy) a number of items at given positions. More... | |
SInt32 | Find (const DataType &item) const |
Find the first occurrence of a given item in the array. More... | |
SInt32 | Find (const DataType &item, SInt32 firstIndex) const |
Find the first occurrence of a given item in the array. More... | |
SInt32 | FindLast (const DataType &item) const |
Find the last occurrence of a given item in the array. More... | |
SInt32 | FindLast (const DataType &item, SInt32 lastIndex) const |
Find the last occurrence of a given item in the array. More... | |
DataType & | Bottom () |
Retrieve the first item from the array. More... | |
const DataType & | Bottom () const |
Retrieve the first item from the array. More... | |
DataType & | Top () |
Retrieve the last item from the array. More... | |
const DataType & | Top () const |
Retrieve the last item from the array. More... | |
DataType | Pop () |
Remove the last item from the array. More... | |
DataType & | At (SInt32 index) |
Retrieve the item at a given position from the array. More... | |
DataType & | At (SInt32 index, const DataType &item) |
Retrieve the item at a given position from the array. More... | |
SInt32 | GetCount () const |
Get the number of items in the array. More... | |
Bool | IsEmpty () const |
Check if the array is empty. More... | |
SInt32 | GetAlloc () const |
Get the number of actually allocated items. More... | |
Bool | IsEqual (const Array &other) const |
Compare the array to another one. More... | |
bool | operator== (const Array &rhs) const |
The "equal to" comparison operator, calls IsEqual(). More... | |
bool | operator!= (const Array &rhs) const |
The "not equal to" comparison operator, calls IsEqual(). More... | |
Bool | IsIndexValid (SInt32 index) const |
Check if a given index is a valid index. More... | |
DataType & | operator[] (SInt32 index) |
Retrieve the item at a given position from the array. More... | |
const DataType & | operator[] (SInt32 index) const |
Retrieve the item at a given position from the array. More... | |
DataType & | Get (SInt32 index) |
Get the item at a given position from the array. More... | |
const DataType & | Get (SInt32 index) const |
Get the item at a given position from the array. More... | |
operator DataType * () | |
Conversion operator to the underlying raw array. More... | |
operator const DataType * () const | |
Conversion operator to the underlying raw array. More... | |
UInt32 | GetByteSize () const |
Get the number of bytes of the underlying raw array. More... | |
ConstIterator | Begin () const |
Get the const iterator to the first item. More... | |
ConstIterator | End () const |
Get the const iterator next to the last item. More... | |
ConstIterator | GetIter (SInt32 index) const |
Get the const iterator of a specified index. More... | |
SInt32 | GetIterIndex (ConstIterator iterator) const |
Get the item index by iterator. More... | |
void | Swap (Array &other) |
Exchange the content of the array with a given second one. More... | |
Iterator | Begin () |
Get the iterator to the first item. More... | |
Iterator | End () |
Get the iterator next to the last item. More... | |
Iterator | GetIter (SInt32 index) |
Get the iterator of a specified index. More... | |
typedef DataType Murl::Array< DataType >::ValueType |
The template parameter value type.
|
inline |
Construct an array containing a single item.
item | The item. |
|
inline |
Construct an array containing two items.
item1 | The first item. |
item2 | The second item. |
|
inline |
Construct an array containing three items.
item1 | The first item. |
item2 | The second item. |
item3 | The third item. |
|
inline |
Construct an array from an already existing one, performing a deep copy.
other | The array to copy. |
|
inline |
Assign the content of another array to this one, performing a deep copy.
other | The source array. |
|
inline |
Reduce the array to a given number of items.
n | The new number of items in the array, must be smaller than the current item count. |
|
inline |
Reduce the array by removing a given number of items from the end.
n | The number of items to remove from the end. |
|
inline |
Reserve storage space.
If the given size is less than the actual size, nothing is done.
n | The number of items the underlying storage should hold. |
|
inline |
Set the actual number of items in the array.
If the given number is smaller than the current size, the array is trimmed, and existing items beyond the new size are destroyed. If the given number is higher, new items are initialized via the value type's default constructor. If the given number is also higher than the underlying storage's capacity, the storage is enlarged to hold exactly the requested number of items.
n | The new number of items in the array. |
|
inline |
Set the actual number of items in the array.
If the given number is smaller than the current size, the array is trimmed, and existing items beyond the new size are destroyed. If the given number is higher, new items are initialized via the given value's copy constructor. If the given number is also higher than the underlying storage's capacity, the storage is enlarged to hold exactly the requested number of items.
n | The new number of items in the array. |
item | The value to initialize any newly added items with. |
|
inline |
Set the actual number of items in the array and reserve extra storage space.
If the given number is smaller than the current size, the array is trimmed, and existing items beyond the new size are destroyed. If the given number is higher, new items are initialized via the value type's default constructor. If the given number is also higher than the underlying storage's capacity, the storage is enlarged and some extra capacity is added.
n | The new number of items in the array. |
|
inline |
Set the actual number of items in the array and reserve extra storage space.
If the given number is smaller than the current size, the array is trimmed, and existing items beyond the new size are destroyed. If the given number is higher, new items are initialized via the given value's copy constructor. If the given number is also higher than the underlying storage's capacity, the storage is enlarged and some extra capacity is added.
n | The new number of items in the array. |
item | The value to initialize any newly added items with. |
|
inline |
Initialize an item with a given item.
If the given index is greater than the actual array size, the array is enlarged as needed.
index | The index of the item to set. |
item | The source item to copy. |
|
inline |
Initialize a range of items with a given item.
If the given index plus the count is greater than the actual array size, the array is enlarged as needed.
index | The index of the first item to set. |
item | The source item to copy. |
count | The number of items to set. |
|
inline |
Fill all items with a given item.
item | The source item to copy. |
|
inline |
Swap two array items.
index1 | The index of the first item. |
index2 | The index of the second item. |
|
inline |
Add a new item at the end of the array.
The new item entry is initialized using the value type's default constructor.
|
inline |
Add a given item at the end of the array.
The new item entry is initialized using the given item's copy constructor.
item | The given item to be inserted at the end of the array. |
|
inline |
Add a given number of new items at the end of the array.
The new item entries are initialized using the value type's default constructor.
count | The number of new items to be inserted at the end of the array. |
|
inline |
Add a given array of items at the end of the array.
The new item entries are initialized using the original items' copy constructors.
other | The given item array to be inserted. |
|
inline |
Add a subset of given array of items at the end of the array.
The new item entries are initialized using the original items' copy constructors.
other | The given source item array. |
offset | The index into the source array specifying the first item to copy. |
count | The number of source array items to copy. |
|
inline |
Insert a new item at a given position.
The new item entry is initialized using the value type's default constructor.
index | the zero-based index where the new item should be inserted. |
|
inline |
Insert a given item at a given position.
The new item is initialized using the given item's copy constructor.
index | the zero-based index where the new item should be inserted. |
item | The given item to be inserted. |
|
inline |
Insert a number of copies of a given item at a given position.
The new item entries are initialized using the given item's copy constructor.
index | the zero-based index where the new items should be inserted. |
item | The given item to be inserted. |
count | The number of copies of the given item to insert. |
|
inline |
Insert a given number of new items at a given position.
The new item entries are initialized using the value type's default constructor.
index | the zero-based index where the new items should be inserted. |
count | The number of new items to be inserted. |
|
inline |
Insert a given array of items at a given position.
The new item entries are initialized using the original items' copy constructors.
index | the zero-based index where the new items should be inserted. |
other | The given item array to be inserted. |
|
inline |
Insert a subset of given array of items at a given position.
The new item entries are initialized using the original items' copy constructors.
index | the zero-based index where the new items should be inserted. |
other | The given source item array. |
offset | The index into the source array specifying the first item to copy. |
count | The number of source array items to copy. |
|
inline |
Remove (and destroy) an item at a given position and get a copy of the item.
index | The zero-based index from where to remove the item. |
|
inline |
Remove (and destroy) a number of items at a given position.
index | The zero-based index from where to remove the items. |
count | The number of items to remove. |
|
inline |
Remove (and destroy) a number of items at given positions.
sortedIndices | A pointer to sorted indices where to remove the items. |
count | The number of items to remove, i.e. the number of indices. |
|
inline |
Remove (and destroy) a number of items at given positions.
sortedIndices | A sorted array of indices where to remove the items. |
|
inline |
Find the first occurrence of a given item in the array.
item | The item to find. |
|
inline |
Find the first occurrence of a given item in the array.
item | The item to find. |
firstIndex | The index where to start searching. |
|
inline |
Find the last occurrence of a given item in the array.
item | The item to find. |
|
inline |
Find the last occurrence of a given item in the array.
item | The item to find. |
lastIndex | The index where to start searching. |
|
inline |
Retrieve the first item from the array.
|
inline |
Retrieve the first item from the array.
|
inline |
Retrieve the last item from the array.
|
inline |
Retrieve the last item from the array.
|
inline |
Remove the last item from the array.
|
inline |
Retrieve the item at a given position from the array.
If the given index is greater than the actual array size, the array is enlarged as needed, using the value type's default constructor for initializing.
index | The zero-based index of the item to retrieve. |
|
inline |
Retrieve the item at a given position from the array.
If the given index is greater than the actual array size, the array is enlarged as needed, using the given reference item's copy constructor for initializing.
index | The zero-based index of the item to retrieve. |
item | The reference item used for initialization. |
|
inline |
Get the number of items in the array.
|
inline |
Check if the array is empty.
|
inline |
Get the number of actually allocated items.
|
inline |
Compare the array to another one.
other | The array to compare. |
|
inline |
The "equal to" comparison operator, calls IsEqual().
rhs | The right hand side array to compare. |
|
inline |
The "not equal to" comparison operator, calls IsEqual().
rhs | The right hand side array to compare. |
|
inline |
Check if a given index is a valid index.
index | The index to check. |
|
inline |
Retrieve the item at a given position from the array.
index | The zero-based index of the item to retrieve. |
|
inline |
Retrieve the item at a given position from the array.
index | The zero-based index of the item to retrieve. |
|
inline |
Get the item at a given position from the array.
index | The zero-based index of the item to retrieve. |
|
inline |
Get the item at a given position from the array.
index | The zero-based index of the item to retrieve. |
|
inline |
Conversion operator to the underlying raw array.
|
inline |
Conversion operator to the underlying raw array.
|
inline |
Get the number of bytes of the underlying raw array.
|
inline |
Get the const iterator to the first item.
|
inline |
Get the const iterator next to the last item.
|
inline |
Get the const iterator of a specified index.
index | The index for the iterator. |
|
inline |
Get the item index by iterator.
(!) Adding or removing items will invalidate iterators.
iterator | The iterator of the item. |
|
inline |
Exchange the content of the array with a given second one.
other | The second array. |
|
inline |
Get the iterator to the first item.
|
inline |
Get the iterator next to the last item.
|
inline |
Get the iterator of a specified index.
index | The index for the iterator. |