About
maxon::BaseArray is a generic array class template used to stored any kind of data. It is based on maxon::BaseCollection and maxon::Collection.
- Note
- One should always use maxon::BaseArray or other array classes of the MAXON API ALIASES instead of low level C-arrays. For an overview see Arrays Manual.
Create
A new maxon::BaseArray can simply be created on the stack.
- Note
- See also maxon::ArrayFactory for some utility functions.
A maxon::BaseArray can be cleared with:
Data Access
A maxon::BaseArray holds a certain amount of memory to store an array of elements. The amount of allocated memory (capacity) may be bigger than the memory needed to hold the currently stored element (count).
if (baseArray.GetCapacityCount() < targetCnt)
{
}
New elements can be added to the array with:
- Warning
- Avoid to use references to array elements while the array is resized since resizing the array invalidates any reference to its elements.
The elements stored in the array are easily accessed with:
- Note
- maxon::BaseArray::GetFirst() is typically used if a function asks for the start address of a simple C-array.
Elements can be removed from the array with:
Iterate
It is simple to iterate over all elements stored in a maxon::BaseArray:
if (count >= 2)
{
itEnd--;
baseArray.
Swap(itBegin, itEnd);
}
Copy
A maxon::BaseArray can simply be copied with:
Memory
The internal memory of the maxon::BaseArray is accessed with these functions. A third-party developer should typically not have to use these functions.
For special allocators see Allocators.
Classes
A class that should be used with a maxon::BaseArray must provide some functionality:
When elements are added or removed from the array, the maxon::BaseArray will copy or move elements around. To support this, a data type class that should be used with a maxon::BaseArray must provide certain functionality:
- The class may not be copyable, but then it has to support std::move.
- The class may not support the copy constructor and operator, but CopyFrom().
- The class may not support std::move, but then copy has to be available.
class SimpleClass
{
public:
};
SimpleClass& exampleElement = exampleArray[0];
class CopyClass
{
public:
CopyClass() { };
CopyClass(
const CopyClass&
src) : _value(
src._value) { }
private:
};
CopyClass exampleElement(1);
class CopyFromClass
{
public:
CopyFromClass() { };
CopyFromClass(
maxon::Int value) : _value(value) { }
CopyFromClass(CopyFromClass&&
src) =
default;
{
}
private:
};
const CopyFromClass exampleElement(1);
class MoveClass
{
public:
MoveClass() { };
MoveClass(MoveClass&&
src)
{
}
private:
};
Further Reading