#include <basearray.h>
Classes | |
class | IteratorTemplate |
Public Types | |
typedef T | ValueType |
typedef ALLOCATOR | AllocatorType |
typedef IteratorTemplate< false > | Iterator |
typedef IteratorTemplate< true > | ConstIterator |
Public Member Functions | |
BaseArray () | |
BaseArray (const ALLOCATOR &a) | |
~BaseArray () | |
BaseArray (BaseArray &&src) | |
BaseArray & | operator= (BaseArray &&src) |
void | Reset () |
void | Flush () |
Int | GetCount () const |
Bool | IsEmpty () const |
Int | GetCapacityCount () const |
const T & | operator[] (Int idx) const |
T & | operator[] (Int idx) |
T * | Append () |
T * | Append (const T &x) |
T * | Append (T &&x) |
T * | Insert (Int position) |
Iterator | Insert (Iterator position) |
T * | Insert (Int position, const T &x) |
Iterator | Insert (Iterator position, const T &x) |
T * | Insert (Int position, T &&x) |
Iterator | Insert (Iterator position, T &&x) |
T * | Insert (Int position, const T *x, Int insertCnt) |
Iterator | Insert (Iterator position, const T *x, Int insertCnt) |
T * | Erase (Int position, Int eraseCnt=1) |
Iterator | Erase (Iterator position, Int eraseCnt=1) |
const T * | GetFirst () const |
T * | GetFirst () |
const T * | GetLast () const |
T * | GetLast () |
Bool | Resize (Int newCnt, BASEARRAYRESIZEFLAGS resizeFlags=BASEARRAYRESIZEFLAGS_DEFAULT) |
Bool | Pop (T *dst=nullptr) |
Int | GetIndex (const T &x) const |
Bool | EnsureCapacity (Int requestedCapacity) |
template<typename SourceArray > | |
Bool | CopyFrom (const SourceArray &src, Bool fitToSize=true) |
Bool | CopyFrom (const BaseArray &src, Bool fitToSize) |
Bool | CopyFrom (const BaseArray &src) |
void | Swap (Iterator a, Iterator b) |
ConstIterator | Begin () const |
Iterator | Begin () |
ConstIterator | End () const |
Iterator | End () |
Bool | MoveAndShrink (BaseArray< T, MINCHUNKSIZE, MEMFLAGS, ALLOCATOR > &dst, Int position, Int moveCnt) |
T * | Disconnect (Int *dst=nullptr) |
ALLOCATOR & | GetAllocator () |
T * | AppendWithoutConstructor (Int increment=1) |
T * | InsertWithoutConstructor (Int idx, Int increment=1) |
Protected Member Functions | |
Bool | FitToSize (Int newCapacity) |
Protected Attributes | |
T * | _ptr |
Int | _cnt |
Int | _capacity |
Private Types | |
typedef BaseArrayHelper< T, ALLOCATOR, MEMFLAGS==BASEARRAYFLAGS_MOVEANDCOPYOBJECTS > | Helper |
Private Member Functions | |
BaseArray (const BaseArray &) | |
void | operator= (const BaseArray &) |
Additional Inherited Members | |
Static Protected Member Functions inherited from DefaultAllocator | |
static Int | ComputeArraySize (Int current_size, Int increment, Int min_chunk_size) |
static void * | Alloc (Int32 s) |
static void * | Alloc (Int64 s) |
static void * | AllocClear (Int32 s) |
static void * | AllocClear (Int64 s) |
static void * | Realloc (void *p, Int n) |
template<class T > | |
static void | Free (T *&p) |
Basic array template. The array consists of one continuous block of memory. The block will have a minimum size of MINCHUNKSIZE elements of type T as soon as the first element is added.
The elements may be copied and change their memory address when the array grows. If your objects cannot be copied or need a constant address use the BlockArray template.
If you need a specific alignment you may have to use a non-default allocator. C4D's allocators align on a 8 byte boundary for 32 bit code and on a 16 byte boundary for 64 bit code. If you need a different alignment or custom resize behaviour (default is grow rate of 1.5) you may use your own allocator instead.
T | Type of the array elements. |
MINCHUNKSIZE | The minimum number of elements upon array creation. |
MEMFLAGS | Use BASEARRAYFLAGS_0 unless you know the object can be moved and/or copied. |
ALLOCATOR | Class for memory allocation. |
|
private |
typedef T ValueType |
typedef ALLOCATOR AllocatorType |
typedef IteratorTemplate<false> Iterator |
Iterator allows read and write access to array elements.
typedef IteratorTemplate<true> ConstIterator |
Iterator for read-only access to array elements.
BaseArray | ( | ) |
|
explicit |
this constructor has to be used if an array should use a custom allocator with member variables
~BaseArray | ( | ) |
|
private |
move assignment operator
void Reset | ( | ) |
Deletes all elements (calls destructors and frees memory)
void Flush | ( | ) |
Deletes all elements, but doesn't free memory (calls destructors though)
Int GetCount | ( | ) | const |
Gets the number of array elements.
Bool IsEmpty | ( | ) | const |
Checks if the array is empty. This is the same as GetCount() == 0
Int GetCapacityCount | ( | ) | const |
Gets the number of elements for which memory has been allocated (this is usually bigger than GetCount())
const T& operator[] | ( | Int | idx | ) | const |
Array (subscript) operator for const objects.
[in] | idx | Element index (if it's out of bounds you will get an error in debug code only, otherwise it will crash) |
T& operator[] | ( | Int | idx | ) |
Array (subscript) operator for non-const objects.
[in] | idx | Element index (if it's out of bounds you will get an error in debug code only, otherwise it will crash) |
T* Append | ( | ) |
Adds a new element at the end of the array.
T* Append | ( | const T & | x | ) |
Adds a new element at the end of the array and initializes it with a copy of x.
[in] | x | Value to be copied. |
T* Append | ( | T && | x | ) |
Adds a new element at the end of the array and moves the content of x to it.
[in] | x | Value to be moved. |
T* Insert | ( | Int | position | ) |
Inserts a new default element at index position.
[in] | position | Insert index (the array size will increase and the existing elements are moved) |
Inserts a new default element at iterator position.
[in] | position | Insert position. |
T* Insert | ( | Int | position, |
const T & | x | ||
) |
Inserts a new element at index position and initializes it with a copy of x.
[in] | position | Insert index (the array size will increase and the existing elements are moved) |
[in] | x | Value to be copied. |
Inserts a new element at iterator position and initializes it with a copy of x.
[in] | position | Insert position. |
[in] | x | Value to be copied. |
T* Insert | ( | Int | position, |
T && | x | ||
) |
Inserts a new element at index position and moves the content of x to it.
[in] | position | Insert index (the array size will increase and the existing elements are moved) |
[in] | x | Value to be moved. |
Inserts a new element at iterator position and moves the content of x to it.
[in] | position | Insert position. |
[in] | x | Value to be moved. |
Inserts new elements at index position (all elements from position on are moved by insertCnt)
[in] | position | Insert index (the array size will increase and the existing elements are moved) |
[in] | x | Array with values to be copied or nullptr (in this case you have to call the constructor manually) |
[in] | insertCnt | Number of elements to be inserted. |
Inserts new elements at iterator position (all elements from position on are moved by insertCnt)
[in] | position | Insert position. |
[in] | x | Array with values to be copied or nullptr (in this case you have to call the constructor manually) |
[in] | insertCnt | Number of elements to be inserted. |
Erases (removes and deletes) elements.
[in] | position | Erase index (Erase() will fail if out of bounds and return nullptr) |
[in] | eraseCnt | Number of elements to be erased (if eraseCnt is higher than what is available at position Erase() will succeed, but remove only the number of available elements) |
Erases (removes and deletes) elements.
[in] | position | Erase position. |
[in] | eraseCnt | Number of elements to be erased (if eraseCnt is higher than what is available at position Erase() will succeed, but remove only the number of available elements) |
const T* GetFirst | ( | ) | const |
Returns the first element of the array.
T* GetFirst | ( | ) |
Returns the first element of the array.
const T* GetLast | ( | ) | const |
Returns the last element of the array.
T* GetLast | ( | ) |
Returns the last element of the array.
Bool Resize | ( | Int | newCnt, |
BASEARRAYRESIZEFLAGS | resizeFlags = BASEARRAYRESIZEFLAGS_DEFAULT |
||
) |
Resizes the array to contain newCnt elements If newCnt is smaller than GetCount() all extra elements are being deleted. If it is greater the array is expanded and the default constructor is called for new elements.
[in] | newCnt | New array size. |
[in] | resizeFlags | BaseArray specific: see BASEARRAYRESIZEFLAGS. |
Bool Pop | ( | T * | dst = nullptr | ) |
Deletes the last element.
[out] | dst | Nullptr or pointer to return value. |
Int GetIndex | ( | const T & | x | ) | const |
Gets the index of the element. The element must be part of the array, otherwise (e.g. if x is a copy of an array element) InvalidArrayIndex will be returned.
Increases the internal capacity of this array (if necessary) so that it can hold at least the given number of elements without further memory allocations.
[in] | requestedCapacity | The desired internal capacity. |
Copies an array.
[in] | src | Source array. |
[in] | fitToSize | If true the array will be copied to a new memory block that is as small as possible to hold the data. |
Copies an array: specialization for BaseArray.
[in] | src | Source array. |
[in] | fitToSize | If true the array will be copied to a new memory block that is as small as possible to hold the data. |
Swaps elements a and b (equivalent to global Swap(array[a], array[b])
[in] | a | Position of element to be swapped. |
[in] | b | Position of element to be swapped. |
ConstIterator Begin | ( | ) | const |
Iterator Begin | ( | ) |
ConstIterator End | ( | ) | const |
Iterator End | ( | ) |
Bool MoveAndShrink | ( | BaseArray< T, MINCHUNKSIZE, MEMFLAGS, ALLOCATOR > & | dst, |
Int | position, | ||
Int | moveCnt | ||
) |
T* Disconnect | ( | Int * | dst = nullptr | ) |
Disconnects the array's memory buffer and returns its address and size.
[out] | dst | Nullptr or pointer to return value. |
ALLOCATOR& GetAllocator | ( | ) |
Returns the allocator as reference. Typically this is used by the arrays and other base classes when multiple of them are "stitched" together as one big object all shall use one main allocator.
T* AppendWithoutConstructor | ( | Int | increment = 1 | ) |
BaseArray specific: Appends uninitialized element(s) at the end of the array. This does not call the constructor! Use Append() unless you deal with PODs that shall not be initialized for a very good reason!
[in] | increment | Number of elements to be appended. |
BaseArray specific: Inserts uninitialized element(s) at the specified index. This does not call the constructor! Use Insert() unless you deal with PODs that shall not be initialized for a very good reason!
[in] | idx | Index at which elements shall be inserted (0 <= idx <= cnt) |
[in] | increment | Number of elements to be inserted. |
|
protected |
|
protected |
|
protected |