StaticArrayInterface< TYPE > Class Template Reference

#include <array.h>

Inheritance diagram for StaticArrayInterface< TYPE >:

Classes

class  IteratorTemplate
 

Public Types

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

Public Member Functions

MAXON_METHOD const TYPE & operator[] (Int index) const
 
MAXON_METHOD ResultRef< TYPE > GetWritable (Int index)
 
template<typename A >
MAXON_FUNCTION ResultMem Set (Int index, A &&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< IntGetBlock (Int index, SimdBlock< NonConstValueType > &block)
 
Int GetBlock (Int index, StridedBlock< NonConstValueType > &block)
 
MAXON_METHOD const DataTypeGetValueDataType () const
 
MAXON_METHOD const PersistentIdGenerator & GetPersistentIdGenerator () const
 
MAXON_METHOD Result< void > MakeAllElementsWritable (Bool copyElements=true)
 
MAXON_METHOD Result< void > MakeElementsWritable (Int start, Int end, Bool copyElements=true)
 
BlockIterator< StaticArrayInterface, TYPE, true, false > GetBlocks () const
 
BlockIterator< StaticArrayInterface, TYPE, true, true > GetStridedBlocks () const
 
Int GetValueSize () const
 
 MAXON_ADD_TO_CONST_REFERENCE_CLASS (using Iterator=typename StaticArrayInterface::ConstIterator;using ConstIterator=typename StaticArrayInterface::ConstIterator;)
 
MAXON_FUNCTION StaticArrayInterface< TYPE >::ConstIterator Begin () const
 
Iterator Begin ()
 
MAXON_FUNCTION StaticArrayInterface< TYPE >::ConstIterator End () const
 
Iterator End ()
 

Public Attributes

 MAXON_METHOD_RESERVE
 

Static Public Attributes

static const Bool GENERIC
 

Private Member Functions

 MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED (StaticArrayInterface, MAXON_REFERENCE_COPY_ON_WRITE)
 

Static Private Member Functions

static StaticArrayInterfaceAlloc (MAXON_SOURCE_LOCATION_DECLARATION)
 

Friends

class StrongCOWRefHandler
 

Member Typedef Documentation

◆ ValueType

using ValueType = TYPE

◆ NonConstValueType

◆ TYPE_FOR_SIZEOF

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

◆ Iterator

◆ ConstIterator

Member Function Documentation

◆ MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED()

MAXON_INTERFACE_SIMPLE_VIRTUAL_DERIVED ( StaticArrayInterface< TYPE >  ,
MAXON_REFERENCE_COPY_ON_WRITE   
)
private

◆ operator[]()

MAXON_METHOD const 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,
A &&  value 
)

◆ GetBlock() [1/5]

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/5]

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

◆ GetBlock() [3/5]

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

◆ GetBlock() [4/5]

MAXON_METHOD Result<Int> GetBlock ( Int  index,
SimdBlock< NonConstValueType > &  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. @MAXON_ANNOTATION{cowName=GetWritableBlock}

◆ GetBlock() [5/5]

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

◆ GetValueDataType()

MAXON_METHOD const 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.

◆ GetPersistentIdGenerator()

MAXON_METHOD const PersistentIdGenerator& GetPersistentIdGenerator ( ) const

◆ MakeAllElementsWritable()

MAXON_METHOD Result<void> MakeAllElementsWritable ( Bool  copyElements = true)

Will ensure that all elements of the array are writable for multithreaded access. Besides parallel write use case, MakeAllElementsWritable is not required as GetWritable(Int index) method does all the work. This is useful mostly for paged arrays (GenericContainerInterface::INTERFACES::PAGED_ARRAY).

Parameters
[in]copyElementsClone all the elements.
Returns
OK on success.

◆ MakeElementsWritable()

MAXON_METHOD Result<void> MakeElementsWritable ( Int  start,
Int  end,
Bool  copyElements = true 
)

Will ensure that all required elements of the array ([start, end]) are writable for multithreaded access. Elements before and after the given range [start, end], will always get copied so that the rest of the target page(s) are still valid after the write operations. I.e. use #copyElements = false when the range will get overwritten without reading current value. Besides parallel write use case, MakeElementsWritable is not required as GetWritable(Int index) method does all the work. This is useful mostly for paged arrays (GenericContainerInterface::INTERFACES::PAGED_ARRAY).

Array<Int> myInts;
...
// For a single writable element (writable element will not get copied, other elements will):
array.MakeElementsWritable(10, 11, false) iferr_return;
// For a more writable elements (writable elements will get copied, along with all other elements of the target page(s)):
array.MakeElementsWritable(0, 2000, true) iferr_return;
#define iferr_return
Definition: resultbase.h:1465
Parameters
[in]startStart index (inclusive).
[in]endEnd index (exclusive).
[in]copyElementsClone elements of the given range.
Returns
OK on success.

◆ GetBlocks()

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

◆ GetStridedBlocks()

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

◆ GetValueSize()

Int GetValueSize ( ) const

◆ MAXON_ADD_TO_CONST_REFERENCE_CLASS()

MAXON_ADD_TO_CONST_REFERENCE_CLASS ( using  Iterator = typename StaticArrayInterface< TYPE >::ConstIterator;using ConstIterator=typename StaticArrayInterface< TYPE >::ConstIterator;)

◆ Begin() [1/2]

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()

static StaticArrayInterface* Alloc ( MAXON_SOURCE_LOCATION_DECLARATION  )
staticprivate

Friends And Related Function Documentation

◆ StrongCOWRefHandler

friend class StrongCOWRefHandler
friend

Member Data Documentation

◆ MAXON_METHOD_RESERVE

MAXON_METHOD_RESERVE

◆ GENERIC

const Bool GENERIC
static