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 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.
Definition: basearray.h:415
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Appends a new element at the end of the array and constructs it using the forwarded value.
Definition: basearray.h:627
#define iferr_return
Definition: resultbase.h:1531
A maxon::BaseArray can be cleared with:
baseArray.Reset();
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
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.
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Insert(Int position, ARG &&x)
Inserts a new element at index position and constructs it using the forwarded value.
Definition: basearray.h:820
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.
{
}
Py_ssize_t i
Definition: abstract.h:645
PyObject * value
Definition: abstract.h:715
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Gets the number of array elements.
Definition: basearray.h:585
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:187
Elements can be removed from the array with:
ResultMem SwapErase(Int position, Int eraseCnt=1)
Erases elements within the array and moves elements from the end to the erased gap....
Definition: basearray.h:1070
MAXON_ATTRIBUTE_FORCE_INLINE Bool Pop(T *dst=nullptr)
Deletes the last element.
Definition: basearray.h:1294
Iterate
It is simple to iterate over all elements stored in a maxon::BaseArray:
{
itEnd--;
baseArray.
Swap(itBegin, itEnd);
}
Py_ssize_t count
Definition: abstract.h:640
MAXON_ATTRIBUTE_FORCE_INLINE void Swap(Iterator a, Iterator b)
Swaps elements a and b (equivalent to global Swap(array[a], array[b]).
Definition: basearray.h:1459
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator Begin() const
Returns an iterator for the first element.
Definition: basearray.h:1483
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator End() const
Returns an iterator for the end (End() - 1 is the last element if the array is not empty).
Definition: basearray.h:1503
Copy
A maxon::BaseArray can simply be copied with:
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFrom(COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE)
Definition: collection.h:263
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];
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Resizes the array to contain newCnt elements. If newCnt is smaller than GetCount() all extra elements...
Definition: basearray.h:1217
Float64 Float
Definition: apibase.h:196
class CopyClass
{
public:
CopyClass() { };
CopyClass(
const CopyClass&
src) : _value(
src._value) { }
private:
};
CopyClass exampleElement(1);
PyObject * src
Definition: abstract.h:305
class CopyFromClass
{
public:
CopyFromClass() { };
CopyFromClass(CopyFromClass&&
src) =
default;
{
}
private:
};
const CopyFromClass exampleElement(1);
return OK
Definition: apibase.h:2740
#define MAXON_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: classhelpers.h:352
class MoveClass
{
public:
MoveClass() { };
MoveClass(MoveClass&&
src)
{
}
private:
};
#define MAXON_OPERATOR_MOVE_ASSIGNMENT(TypeName)
Definition: classhelpers.h:381
Further Reading