VArrayInterface< TYPE > Class Template Reference

#include <array.h>

Inheritance diagram for VArrayInterface< TYPE >:

Classes

class  IteratorTemplate
 

Public Types

using TYPE_FOR_SIZEOF = typename std::conditional< GENERIC, Char, TYPE >::type
 
using Iterator = IteratorTemplate< VArrayInterface >
 
using ConstIterator = IteratorTemplate< const VArrayInterface >
 

Public Member Functions

MAXON_METHOD Int GetCount () const
 
MAXON_FUNCTION Bool IsEmpty () const
 
MAXON_FUNCTION Bool IsPopulated () const
 
const MAXON_METHOD TYPE & operator[] (Int index) const
 
MAXON_METHOD ResultRef< TYPE > GetWritable (Int index)
 
template<typename T >
MAXON_FUNCTION ResultMem Set (Int index, T &&value)
 
MAXON_METHOD Int GetBlock (Int index, SimdBlock< const TYPE > &block) const
 
Int GetBlock (Int index, StridedBlock< const TYPE > &block) const
 
Int GetBlock (Int index, Block< const TYPE, false > &block) const
 
MAXON_METHOD Result< IntGetWritableBlock (Int index, SimdBlock< TYPE > &block)
 
MAXON_METHOD Result< VArrayInterface * > Clone (Bool cloneElements=true) const
 
const MAXON_METHOD DataTypeGetValueDataType () const
 
MAXON_METHOD String ToString (const FormatStatement *formatStatement) const
 
MAXON_METHOD Bool IsEqual (const VArrayInterface *other, EQUALITY equality) const
 
MAXON_METHOD UInt GetHashCode () const
 
MAXON_METHOD Result< void > PrivateInsert (Int index, const StridedBlock< const TYPE > &values, Bool move)
 
MAXON_METHOD ResultMem Resize (Int count, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
 
MAXON_METHOD ResultMem SetCapacityHint (Int requestedCapacity, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
MAXON_METHOD ResultRef< TYPE > Insert (Int index)
 
MAXON_FUNCTION ResultRef< TYPE > Insert (Int index, const TYPE &value)
 
MAXON_FUNCTION ResultRef< TYPE > Insert (Int index, TYPE &&value)
 
MAXON_METHOD ResultMem Insert (Int index, const Block< const TYPE > &values)
 
MAXON_METHOD ResultMem Insert (Int index, const MoveBlock< TYPE > &values)
 
MAXON_METHOD ResultRef< TYPE > Append ()
 
MAXON_FUNCTION ResultRef< TYPE > Append (const TYPE &value)
 
MAXON_FUNCTION ResultRef< TYPE > Append (TYPE &&value)
 
template<typename T >
MAXON_FUNCTION ResultRef< TYPE > Append (T &&value)
 
MAXON_FUNCTION Bool Pop ()
 
MAXON_FUNCTION Bool Pop (TYPE *dst)
 
MAXON_METHOD ResultMem Erase (Int index, Int count=1)
 
MAXON_METHOD ResultMem SwapErase (Int index, Int count=1)
 
MAXON_METHOD void Reset ()
 
MAXON_METHOD void Flush ()
 
MAXON_METHOD Result< void > CopyFrom (const VArrayInterface &other)
 
BlockIterator< VArrayInterface, TYPE, true, false > GetBlocks () const
 
BlockIterator< VArrayInterface, TYPE, true, true > GetStridedBlocks () const
 
Int GetValueSize () const
 
MAXON_FUNCTION ConstIterator Begin () const
 
Iterator Begin ()
 
MAXON_FUNCTION ConstIterator End () const
 
Iterator End ()
 

Static Public Attributes

static const Bool GENERIC
 

Private Member Functions

 MAXON_INTERFACE_SIMPLE_VIRTUAL (VArrayInterface, MAXON_REFERENCE_COPY_ON_WRITE)
 

Static Private Member Functions

static VArrayInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 
static VArrayInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const VArrayInterface &src)
 

Member Typedef Documentation

◆ TYPE_FOR_SIZEOF

using TYPE_FOR_SIZEOF = typename std::conditional<GENERIC, Char, TYPE>::type

◆ Iterator

◆ ConstIterator

Member Function Documentation

◆ MAXON_INTERFACE_SIMPLE_VIRTUAL()

MAXON_INTERFACE_SIMPLE_VIRTUAL ( VArrayInterface< TYPE >  ,
MAXON_REFERENCE_COPY_ON_WRITE   
)
private

◆ GetCount()

MAXON_METHOD Int GetCount ( ) const

Gets the number of array elements.

Returns
Number of array elements.

◆ IsEmpty()

MAXON_FUNCTION Bool IsEmpty ( ) const

@MAXON_ANNOTATION{default=true}

◆ IsPopulated()

MAXON_FUNCTION Bool IsPopulated ( void  ) const

◆ operator[]()

const MAXON_METHOD TYPE& operator[] ( Int  index) const

Array (subscript) operator for const objects.

Parameters
[in]indexElement index.
Returns
Array element.

◆ GetWritable()

MAXON_METHOD ResultRef<TYPE> GetWritable ( Int  index)

Array (subscript) operator for non-const objects.

Parameters
[in]indexElement index.
Returns
Array element.

◆ Set()

MAXON_FUNCTION ResultMem Set ( Int  index,
T &&  value 
)

◆ GetBlock() [1/3]

MAXON_METHOD Int GetBlock ( Int  index,
SimdBlock< const TYPE > &  block 
) const

Determines a contiguous, possibly strided block of array elements which contains the element at index. The returned blocks are guaranteed to form a partition of the array, i.e., no two blocks overlap, and they cover the whole array.

Using this method can greatly reduce the performance penalty of virtual method invocations of the Array interface as only one such invocation has to happen per block, and a block may consist of a relatively large number of elements which can then be accessed directly.

Parameters
[in]indexElement index.
[out]blockBlock which contains the element at index.
Returns
Start index of the block. I.e., the requested element can be found within the block at index - start index.

◆ GetBlock() [2/3]

Int GetBlock ( Int  index,
StridedBlock< const TYPE > &  block 
) const

◆ GetBlock() [3/3]

Int GetBlock ( Int  index,
Block< const TYPE, false > &  block 
) const

◆ GetWritableBlock()

MAXON_METHOD Result<Int> GetWritableBlock ( Int  index,
SimdBlock< TYPE > &  block 
)

Determines a contiguous, possibly strided writable block of array elements which contains the element at index. The returned blocks are guaranteed to form a partition of the array, i.e., no two blocks overlap, and they cover the whole array.

Using this method can greatly reduce the performance penalty of virtual method invocations of the Array interface as only one such invocation has to happen per block, and a block may consist of a relatively large number of elements which can then be accessed directly.

Parameters
[in]indexElement index.
[out]blockBlock which contains the element at index.
Returns
Start index of the block. I.e., the requested element can be found within the block at index - start index.

◆ Clone()

MAXON_METHOD Result<VArrayInterface*> Clone ( Bool  cloneElements = true) const

Returns a clone of this array.

Parameters
[in]cloneElementsTrue if also the elements shall be cloned, false otherwise (then just a new object sharing the same ArrayInterface implementation is created).
Returns
Pointer to the new array object, nullptr if allocation or copying failed.

◆ GetValueDataType()

const MAXON_METHOD DataType& GetValueDataType ( ) const

Returns the data type of this array's elements. This may be nullptr if there is no DataType for the template parameter TYPE.

Returns
DataType of the elements or nullptr.

◆ ToString()

MAXON_METHOD String ToString ( const FormatStatement formatStatement) const
Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.

◆ IsEqual()

MAXON_METHOD Bool IsEqual ( const VArrayInterface< TYPE > *  other,
EQUALITY  equality 
) const

◆ GetHashCode()

MAXON_METHOD UInt GetHashCode ( ) const

◆ PrivateInsert()

MAXON_METHOD Result<void> PrivateInsert ( Int  index,
const StridedBlock< const TYPE > &  values,
Bool  move 
)

For future compatibility, not implemented at the moment.

◆ Resize()

Resizes the array to contain count elements. If count 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.

Parameters
[in]countNew array size.
[in]resizeFlagsSee COLLECTION_RESIZE_FLAGS.
Returns
False if allocation failed.

◆ SetCapacityHint()

MAXON_METHOD ResultMem SetCapacityHint ( Int  requestedCapacity,
COLLECTION_RESIZE_FLAGS  resizeFlags = COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY 
)

Prepare the internal array so that it can hold at least the given number of elements with as few further memory allocations as possible.

Parameters
[in]requestedCapacityThe desired internal capacity.
[in]resizeFlagsIf ON_GROW_FIT_TO_SIZE is set, the collection will use only as much memory as needed to hold the data.
Returns
False if allocation failed.

◆ Insert() [1/5]

MAXON_METHOD ResultRef<TYPE> Insert ( Int  index)

Inserts a new element at index. The element will be default-constructed.

Parameters
[in]indexInsertion index (the array size will increase and the existing elements are moved).
Returns
Element reference or OutOfMemoryError if the allocation failed (or position is out of boundaries).

◆ Insert() [2/5]

MAXON_FUNCTION ResultRef<TYPE> Insert ( Int  index,
const TYPE &  value 
)

Inserts a new element at index position and initializes it with #value.

Parameters
[in]indexInsert index (the array size will increase and the existing elements are moved).
[in]valueValue to be inserted.
Returns
Element reference or OutOfMemoryError if the allocation failed (or position is out of boundaries).

◆ Insert() [3/5]

MAXON_FUNCTION ResultRef<TYPE> Insert ( Int  index,
TYPE &&  value 
)

Inserts a new element at index position and initializes it with #value.

Parameters
[in]indexInsert index (the array size will increase and the existing elements are moved).
[in]valueValue to be inserted.
Returns
Element reference or OutOfMemoryError if the allocation failed (or position is out of boundaries).

◆ Insert() [4/5]

MAXON_METHOD ResultMem Insert ( Int  index,
const Block< const TYPE > &  values 
)

Inserts a number of new elements at index. The elements will be copied.

Parameters
[in]indexInsertion index (the array size will increase and the existing elements are moved).
[in]valuesBlock with values to be copied. If the block points to nullptr, only its count is used, and you have to call the constructor of the new elements manually.
Returns
False if insert failed.

◆ Insert() [5/5]

MAXON_METHOD ResultMem Insert ( Int  index,
const MoveBlock< TYPE > &  values 
)

Inserts a number of new elements at index. The elements will be moved.

Parameters
[in]indexInsertion index (the array size will increase and the existing elements are moved).
[in]valuesBlock with values to be moved. If the block points to nullptr, only its count is used, and you have to call the constructor of the new elements manually.
Returns
False if insert failed.

◆ Append() [1/4]

MAXON_METHOD ResultRef<TYPE> Append ( )

Adds a new element at the end of the array. The element will be default-constructed.

Returns
Element reference or OutOfMemoryError if the allocation failed.

◆ Append() [2/4]

MAXON_FUNCTION ResultRef<TYPE> Append ( const TYPE &  value)

Adds a new element at the end of the array and initializes it with #value.

Parameters
[in]valueValue to be appended.
Returns
Element reference or OutOfMemoryError if the allocation failed.

◆ Append() [3/4]

MAXON_FUNCTION ResultRef<TYPE> Append ( TYPE &&  value)

Adds a new element at the end of the array and initializes it with #value.

Parameters
[in]valueValue to be appended.
Returns
Element reference or OutOfMemoryError if the allocation failed.

◆ Append() [4/4]

MAXON_FUNCTION ResultRef<TYPE> Append ( T &&  value)

Adds a new element at the end of the array and initializes it with #value.

Parameters
[in]valueValue to be appended.
Returns
Element reference or OutOfMemoryError if the allocation failed.

◆ Pop() [1/2]

Deletes the last element.

Returns
True if there was at least one element.

◆ Pop() [2/2]

MAXON_FUNCTION Bool Pop ( TYPE *  dst)

Deletes the last element.

Parameters
[out]dstNullptr or pointer to return value.
Returns
True if there was at least one element.

◆ Erase()

MAXON_METHOD ResultMem Erase ( Int  index,
Int  count = 1 
)

Erases (removes and deletes) elements.

Parameters
[in]indexErase index.
[in]countNumber 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).
Returns
True if operation was successul.

◆ SwapErase()

MAXON_METHOD ResultMem SwapErase ( Int  index,
Int  count = 1 
)

Erases elements within the array and moves elements from the end to the erased gap. This is generally faster than Erase because at most count elements have to be moved, but it changes the order of elements.

Parameters
[in]indexErase index.
[in]countNumber 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).
Returns
True if operation was successul.

◆ Reset()

MAXON_METHOD void Reset ( )

Deletes all elements (calls destructors and frees memory).

◆ Flush()

MAXON_METHOD void Flush ( )

Deletes all elements, but doesn't free memory (calls destructors though).

◆ CopyFrom()

MAXON_METHOD Result<void> CopyFrom ( const VArrayInterface< TYPE > &  other)

Sets this array to a copy of the given other array.

Parameters
[in]otherSource array.
Returns
Success of operation.

◆ GetBlocks()

BlockIterator<VArrayInterface, TYPE, true, false> GetBlocks ( ) const

◆ GetStridedBlocks()

BlockIterator<VArrayInterface, TYPE, true, true> GetStridedBlocks ( ) const

◆ GetValueSize()

Int GetValueSize ( ) const

◆ Begin() [1/2]

MAXON_FUNCTION ConstIterator Begin ( ) const

Returns an iterator pointing to the first array element.

Returns
Iterator for the first element (equal to End() if the array is empty).

◆ Begin() [2/2]

Iterator Begin ( )

Returns an iterator pointing to the first array element.

Returns
Iterator for the first element (equal to End() if the array is empty).

◆ End() [1/2]

Returns an iterator pointing one behind the last array element.

Returns
Iterator for the array end, this is one behind the last element.

◆ End() [2/2]

Iterator End ( )

Returns an iterator pointing one behind the last array element.

Returns
Iterator for the array end, this is one behind the last element.

◆ Alloc() [1/2]

static VArrayInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  )
staticprivate

◆ Alloc() [2/2]

static VArrayInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  ,
const VArrayInterface< TYPE > &  src 
)
staticprivate

Member Data Documentation

◆ GENERIC

const Bool GENERIC
static