BaseArray Manual
maxon::BaseArray is a generic array class template used to stored any kind of data. It is based on maxon::BaseCollection and maxon::Collection .
A new maxon::BaseArray can simply be created on the stack.
A maxon::BaseArray can be cleared with:
// check count DiagnosticOutput ( "Count: @" , baseArray.GetCount());
// reset baseArray.Reset();
// check count DiagnosticOutput ( "Count: @" , baseArray.GetCount());
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).
New elements can be added to the array with:
The elements stored in the array are easily accessed with:
Elements can be removed from the array with:
It is simple to iterate over all elements stored in a maxon::BaseArray :
// swap elements baseArray. Swap (itBegin, itEnd); }
// check order for ( const maxon::Int & value : baseArray) DiagnosticOutput ( "Value: @" , value);
A maxon::BaseArray can simply be copied with:
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 .
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:
// primitive class class SimpleClass { public : maxon::Float _x, _y, _z; };
// using the primitive class with maxon::BaseArray maxon::BaseArray<SimpleClass> exampleArray; exampleArray. Resize (100) iferr_return ; SimpleClass& exampleElement = exampleArray[0];
// A class can provide a copy contructor to be used with a BaseArray.
// class with copy constructor class CopyClass { public : CopyClass() { }; CopyClass( maxon::Int value) : _value(value) { } CopyClass( const CopyClass& src ) : _value( src ._value) { } private : maxon::Int _value = 0; }; maxon::BaseArray<CopyClass> exampleArray;
// the new element is appended using the copy constructor CopyClass exampleElement(1); exampleArray. Append (exampleElement) iferr_return ;
// A class with CopyFrom() allows to insert or add const elements to a BaseArray. // It also allows to copy arrays. class CopyFromClass { MAXON_DISALLOW_COPY_AND_ASSIGN (CopyFromClass) // no copy constructor, no "=" operator public : CopyFromClass() { }; CopyFromClass( maxon::Int value) : _value(value) { } CopyFromClass(CopyFromClass&& src ) = default ; maxon::Result<void> CopyFrom( const CopyFromClass& src ) { // CopyFrom() is invoked when adding/inserting a const element to a BaseArray _value = src ._value; return maxon::OK ; } private : maxon::Int _value = 0; }; maxon::BaseArray<CopyFromClass> exampleArray;
// the new element is appended using CopyFrom() const CopyFromClass exampleElement(1); exampleArray. Append (exampleElement) iferr_return ;
// A class can provide a move constructor/operator to be used with a BaseArray. class MoveClass { MAXON_DISALLOW_COPY_AND_ASSIGN (MoveClass) // no copy constructor, no "=" operator public : MoveClass() { }; MoveClass( maxon::Int value) : _value(value) { } MoveClass(MoveClass&& src ) { _value = src ._value; } MAXON_OPERATOR_MOVE_ASSIGNMENT (MoveClass); // move assignment based on move constructor private : maxon::Int _value = 0; }; maxon::BaseArray<MoveClass> exampleArray; // the new element is appended using the move constuctor exampleArray. Append (MoveClass(1)) iferr_return ;