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:412
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Definition: basearray.h:677
#define iferr_return
Definition: resultbase.h:1465
A maxon::BaseArray can be cleared with:
baseArray.Reset();
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
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)
Definition: basearray.h:950
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
Definition: basearray.h:573
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
Elements can be removed from the array with:
ResultMem SwapErase(Int position, Int eraseCnt=1)
Definition: basearray.h:1222
MAXON_ATTRIBUTE_FORCE_INLINE Bool Pop(T *dst=nullptr)
Definition: basearray.h:1446
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)
Definition: basearray.h:1613
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator Begin() const
Definition: basearray.h:1637
MAXON_ATTRIBUTE_FORCE_INLINE ConstIterator End() const
Definition: basearray.h:1657
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:261
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)
Definition: basearray.h:1369
Float64 Float
Definition: apibase.h:197
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:2667
#define MAXON_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: classhelpers.h:320
class MoveClass
{
public:
MoveClass() { };
MoveClass(MoveClass&&
src)
{
}
private:
};
#define MAXON_OPERATOR_MOVE_ASSIGNMENT(TypeName)
Definition: classhelpers.h:349
Further Reading