ArrayInterface< TYPE > Class Template Reference

#include <array.h>

Inheritance diagram for ArrayInterface< TYPE >:

Detailed Description

template<typename TYPE>
class maxon::ArrayInterface< TYPE >

ArrayInterface is an interface which provides the usual array functions as virtual methods. Each standard array of the MAXON API can be represented as such an interface, so this allows to write non-template functions which nevertheless are able to deal with any kind of array.

If the function won't modify both the structure and values of the array, you should use a const ArrayInterface with const elements:

void Func(const ArrayInterface<const Char>& array);
BlockArray<Char> myArray;
Func(myArray); // OK
BaseArray<Char> myArray2;
Func(myArray2); // OK

As the access to the array happens via virtual methods, there is an inevitable performance penalty. Often this will be negligible, but if not, you can use the GetBlock function to obtain a fraction of the array as a Block of array elements which are laid out regularly in memory. Then as long as the elements you need to access are within that same block, no further virtual method invocations are necessary. E.g., a BaseArray consists of just a single block, and a BlockArray of a small number of blocks (small compared to the number of elements). The iterator of an ArrayInterface already takes this into account, so it uses the minimum possible number of virtual method invocations.

For an array which shall be modified, use WritableArrayInterface as type of the function parameter instead.

Template Parameters
TYPEType of elements of the array.

Public Types

using ValueType = TYPE
 
using Super = VArrayInterface< TYPE >
 
using Iterator = typename Super::template IteratorTemplate< ArrayInterface >
 
using ConstIterator = typename Super::template IteratorTemplate< const ArrayInterface >
 
- Public Types inherited from Collection< ArrayInterface< TYPE >, TYPE, VArrayInterface< TYPE > >
using Super = BaseCollection< ArrayInterface< TYPE >, VArrayInterface< TYPE > >
 
using ValueType = TYPE
 
- Public Types inherited from BaseCollection< ArrayInterface< TYPE >, VArrayInterface< TYPE > >
using IsCollection = std::true_type
 
- Public Types inherited from VArrayInterface< TYPE >
using TYPE_FOR_SIZEOF = typename std::conditional< GENERIC, Char, TYPE >::type
 
using Iterator = IteratorTemplate< VArrayInterface >
 
using ConstIterator = IteratorTemplate< const VArrayInterface >
 

Public Member Functions

TYPE & operator[] (Int index)
 
MAXON_METHOD Int GetBlock (Int index, Block< const TYPE, false > &block) const
 
Int GetBlock (Int index, Block< TYPE, false > &block)
 
Int GetBlock (Int index, StridedBlock< const TYPE > &block) const
 
Int GetBlock (Int index, StridedBlock< TYPE > &block)
 
MAXON_METHOD Int GetMemorySize () const
 
template<typename T >
MAXON_FUNCTION Bool HasType () const
 
template<typename T >
MAXON_FUNCTION void AssertType () const
 
template<typename T >
ArrayInterface< T > & AssertCast ()
 
template<typename T >
const ArrayInterface< T > & AssertCast () const
 
 operator const ArrayInterface< const TYPE > & () const
 
 operator const ArrayInterface< typename std::conditional< std::is_same< const TYPE, const Generic >::value, const DummyReturnType, const Generic >::type > & () const
 
 operator ArrayInterface< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > & ()
 
 operator const NonConstArray< TYPE > & ()
 
 operator const NonConstArray< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > & ()
 
MAXON_FUNCTION ConstIterator Begin () const
 
Iterator Begin ()
 
MAXON_FUNCTION ConstIterator End () const
 
Iterator End ()
 
MAXON_METHOD Result< void > CopyFrom (const VArrayInterface &other)
 
MAXON_METHOD Bool IsEqual (const VArrayInterface *other, EQUALITY equality) const
 
MAXON_METHOD UInt GetHashCode () const
 
MAXON_METHOD String ToString (const FormatStatement *formatStatement) const
 
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
 
- Public Member Functions inherited from ArrayBase0< ArrayInterface< TYPE >, TYPE, VArrayInterface< TYPE >, DefaultCompare >
MAXON_ATTRIBUTE_FORCE_INLINE ArrayBase0 (ARGS &&... args)
 
Bool IsValidIndex (Int index) const
 
Result< void > CheckValidIndex (Int index) const
 
Int FindIndex (typename ByValueParam< TYPE >::type v, Int start) const
 
Int FindLastIndex (typename ByValueParam< TYPE >::type v) const
 
Int FindLastIndex (typename ByValueParam< TYPE >::type v, Int start) const
 
Bool EraseFirst (typename ByValueParam< TYPE >::type v)
 
Int EraseAll (typename ByValueParam< TYPE >::type v)
 
Result< void > AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0)
 
Result< void > InsertAll (Int index, COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
Result< void > Add (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
Result< void > SubtractImpl (COLLECTION2 &&other, OverloadRank0)
 
Bool IsEqualImpl (const COLLECTION2 &other, COMPARE &&cmp, OverloadRank0) const
 
UInt GetHashCode () const
 
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< ArrayInterface< TYPE > > Slice (Int start)
 
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< const ArrayInterface< TYPE > > Slice (Int start) const
 
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< ArrayInterface< TYPE > > Slice (Int start, Int end)
 
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< const ArrayInterface< TYPE > > Slice (Int start, Int end) const
 
BlockIterator< ArrayInterface< TYPE >, TYPE, false, false > GetBlocks ()
 
BlockIterator< ArrayInterface< TYPE >, TYPE, true, false > GetBlocks () const
 
BlockIterator< ArrayInterface< TYPE >, TYPE, false, true > GetStridedBlocks ()
 
BlockIterator< ArrayInterface< TYPE >, TYPE, true, true > GetStridedBlocks () const
 
- Public Member Functions inherited from Collection< ArrayInterface< TYPE >, TYPE, VArrayInterface< TYPE > >
MAXON_ATTRIBUTE_FORCE_INLINE Collection (ARGS &&... args)
 
ResultOk< void > VariadicAppend ()
 
Result< void > VariadicAppend (V &&value, VALUES &&... rest)
 
 operator ValueReceiver< const TYPE & > ()
 
 operator ValueReceiver< TYPE && > ()
 
 operator ValueReceiver< typename std::conditional< std::is_scalar< TYPE >::value, TYPE, DummyParamType & >::type > ()
 
Result< BoolForEach (FN &&callback)
 
H::Iterator Find (typename ByValueParam< TYPE >::type v)
 
H::ConstIterator Find (typename ByValueParam< TYPE >::type v) const
 
Int FindIndex (typename ByValueParam< TYPE >::type v) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool Contains (typename ByValueParam< TYPE >::type v) const
 
- Public Member Functions inherited from BaseCollection< ArrayInterface< TYPE >, VArrayInterface< TYPE > >
MAXON_ATTRIBUTE_FORCE_INLINE BaseCollection (ARGS &&... args)
 
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type operator== (const COLLECTION2 &other) const
 
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type operator!= (const COLLECTION2 &other) const
 
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value &&!std::is_same< typename std::decay< COMPARE >::type, EQUALITY >::value, Bool >::type IsEqual (const COLLECTION2 &other, COMPARE &&cmp=COMPARE()) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFrom (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE)
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > Subtract (COLLECTION2 &&other)
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > Intersect (const COLLECTION2 &other)
 
Bool Intersects (const COLLECTION2 &other) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > CopyFromImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0)
 
Result< void > AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0)
 
Result< void > IntersectImpl (COLLECTION2 &&other, OverloadRank0)
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsEmpty () const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool IsPopulated () const
 
String ToString (const FormatStatement *formatStatement) const
 
MAXON_ATTRIBUTE_FORCE_INLINE Bool ContainsAll (COLLECTION2 &&other) const
 
Bool ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const
 
- Public Member Functions inherited from VArrayInterface< TYPE >
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 ()
 

Private Member Functions

 MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED (ArrayInterface, MAXON_REFERENCE_COPY_ON_WRITE)
 

Static Private Member Functions

static ArrayInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 
static ArrayInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION, const ArrayInterface &src)
 

Friends

template<typename ARRAY >
class ArrayImpl
 
class StrongCOWRefHandler
 

Additional Inherited Members

- Static Public Member Functions inherited from Collection< ArrayInterface< TYPE >, TYPE, VArrayInterface< TYPE > >
static const TYPEGetMapKey (const TYPE &key)
 
- Static Public Attributes inherited from ArrayBase0< ArrayInterface< TYPE >, TYPE, VArrayInterface< TYPE >, DefaultCompare >
static const COLLECTION_KIND KIND
 
- Static Public Attributes inherited from VArrayInterface< TYPE >
static const Bool GENERIC
 

Member Typedef Documentation

◆ ValueType

using ValueType = TYPE

◆ Super

using Super = VArrayInterface<TYPE>

◆ Iterator

using Iterator = typename Super::template IteratorTemplate<ArrayInterface>

◆ ConstIterator

using ConstIterator = typename Super::template IteratorTemplate<const ArrayInterface>

Member Function Documentation

◆ MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED()

MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED ( ArrayInterface< TYPE >  ,
MAXON_REFERENCE_COPY_ON_WRITE   
)
private

◆ operator[]()

TYPE& operator[] ( Int  index)

◆ GetBlock() [1/7]

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

Determines a contiguous non-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/7]

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

◆ GetBlock() [3/7]

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

◆ GetBlock() [4/7]

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

◆ GetMemorySize()

MAXON_METHOD Int GetMemorySize ( ) const

Calculates the memory usage for this array.

Returns
Memory size in bytes.

◆ HasType()

MAXON_FUNCTION Bool HasType ( ) const

◆ AssertType()

MAXON_FUNCTION void AssertType ( ) const

Issues a failed DebugAssert if the DataType of this array doesn't match T. If T is Generic, no check happens.

Template Parameters
TType to check.

◆ AssertCast() [1/2]

ArrayInterface<T>& AssertCast ( )

Casts this array to an array with elements of type T. If T doesn't match the actual data type of this array, a failed DebugAssert is issued. This function only makes sense when the original array uses Generic as its type.

Template Parameters
TElement type of the destination array.
Returns
This array, cast to an ArrayInterface of T elements.

◆ AssertCast() [2/2]

const ArrayInterface<T>& AssertCast ( ) const

Casts this array to an array with elements of type T. If T doesn't match the actual data type of this array, a failed DebugAssert is issued. This function only makes sense when the original array uses Generic as its type.

Template Parameters
TElement type of the destination array.
Returns
This array, cast to an ArrayInterface of T elements.

◆ operator const ArrayInterface< const TYPE > &()

operator const ArrayInterface< const TYPE > & ( ) const

◆ operator const ArrayInterface< typename std::conditional< std::is_same< const TYPE, const Generic >::value, const DummyReturnType, const Generic >::type > &()

operator const ArrayInterface< typename std::conditional< std::is_same< const TYPE, const Generic >::value, const DummyReturnType, const Generic >::type > & ( ) const

◆ operator ArrayInterface< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > &()

operator ArrayInterface< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > & ( )

◆ operator const NonConstArray< TYPE > &()

operator const NonConstArray< TYPE > & ( )

◆ operator const NonConstArray< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > &()

operator const NonConstArray< typename std::conditional< std::is_same< TYPE, Generic >::value, DummyReturnType, Generic >::type > & ( )

◆ 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 ArrayInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  )
staticprivate

◆ Alloc() [2/2]

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

◆ CopyFrom()

MAXON_METHOD Result<void> CopyFrom

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

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

◆ IsEqual()

MAXON_METHOD Bool IsEqual

◆ GetHashCode()

MAXON_METHOD UInt GetHashCode

◆ ToString()

MAXON_METHOD String ToString
Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.

◆ GetBlock() [5/7]

MAXON_METHOD Int GetBlock

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() [6/7]

Int GetBlock

◆ GetBlock() [7/7]

Int GetBlock

Friends And Related Function Documentation

◆ ArrayImpl

friend class ArrayImpl
friend

◆ StrongCOWRefHandler

friend class StrongCOWRefHandler
friend