template<typename T, Bool STRIDED, Bool MOVE>
class maxon::Block< T, STRIDED, MOVE >
A Block stands for a number of elements with a regular memory layout. It consists of a pointer for the first element, the element count and optionally a stride. All elements are placed consecutively in memory, but with a possible padding inbetween: The stride is the pointer difference between consecutive elements in bytes. By default, the stride is just SIZEOF(T)
.
You can use an alternative stride length to access only specific elements of your array. For example if you have an array with XYZ vectors and want to access only the X-values as a block, you could use the pointer to the first X-value and a stride length of SIZEOF(Vector). Or for a Block whose elements are all the same, you can use a stride of 0 and a pointer to a single value.
There is an important difference between a Block and arrays such as BaseArray with respect to the meaning of a const Block: A const block can't be modified itself, so its pointer and length cannot be changed, but the memory to which the block points is still non-const (if #T is a non-const type). So you can modify the memory through a const block. In other words, a[13] = 42;
is OK for a const Block<Int> a
, but not for a const BaseArray<Int> a
. Therefore you have to use Block<const Int>
whenever the memory of the block shall be read-only. A typical case is an input parameter to a function such as
A Block supports the usual array functions which do not modify the length. Also it can be converted to the Array interface. If unsupported functions are invoked then, they will cause a DebugStop
and indicate a failure on return.
- Template Parameters
-
T | Type of elements of the block. If the memory must not be modified through this block, use a const type. |
STRIDED | True if a stride other than SIZEOF(T) shall be supported. |
MOVE | True if the values of this block shall be moved (only useful when used as a parameter type, see MoveBlock). |
- See also
- $ref blocks
|
| Block () |
|
| Block (T *ptr, Int size, Int stride=(STRIDED &&GENERIC) ? -1 :SIZEOF(StrideType)) |
|
| Block (Iterator start, Int size, Int stride=(STRIDED &&GENERIC) ? -1 :SIZEOF(StrideType)) |
|
| Block (ConstIterator start, Int size, Int stride=(STRIDED &&GENERIC) ? -1 :SIZEOF(StrideType)) |
|
template<Int N> |
MAXON_IMPLICIT | Block (T(&array)[N]) |
|
MAXON_IMPLICIT | Block (const std::initializer_list< typename std::remove_const< T >::type > &list) |
|
| Block (const Block &src)=default |
|
Block & | operator= (const Block &src)=default |
|
Result< void > | CopyFrom (const Block &src)=delete |
|
| operator ArrayImpl< Block & > ()=delete |
|
| operator ArrayImpl< const Block & > () const =delete |
|
Int | GetStride () const |
|
Bool | IsStrided () const |
|
void | Set (T *ptr, Int size, Int stride=(STRIDED &&GENERIC) ? -1 :SIZEOF(StrideType)) |
|
void | Reset () |
|
| operator typename std::conditional< STRIDED, DummyReturnType, Block< T, true, MOVE >>::type () const |
|
| operator typename std::conditional< STRIDED||STD_IS_REPLACEMENT (const, T) |
|
const Block< const T, true, MOVE > | type () const |
|
| operator typename std::conditional< STD_IS_REPLACEMENT (const, T) |
|
volatile const Block< const T, STRIDED, MOVE > & | type () const |
|
| operator typename std::conditional< STRIDED||!MOVE, DummyReturnType &, Block< T, true, false >>::type () const |
|
| operator typename std::conditional< STRIDED||!MOVE||STD_IS_REPLACEMENT (const, T) |
|
const DummyReturnType Block< const T, true, false > | type () const |
|
| operator typename std::conditional<!MOVE||STD_IS_REPLACEMENT (const, T) |
|
volatile DummyReturnType const Block< const T, STRIDED, false > & | type () const |
|
| operator typename std::conditional<!MOVE, const volatile DummyReturnType &, const Block< T, STRIDED, false > & >::type () const |
|
| operator typename std::conditional< GENERIC, const volatile DummyReturnType, const Block< typename InheritConst< Generic, T >::type, STRIDED > & >::type () const |
|
T * | GetFirst () const |
|
void | SetFirst (T *value) |
|
T * | GetLast () const |
|
T & | operator[] (Int index) const |
|
Block | Slice (Int start) const |
|
Block | Slice (Int start, Int end) const |
|
Bool | StartsWith (const Block &prefix) const |
|
Iterator | Begin () const |
|
Iterator | End () const |
|
Int | GetCapacityCount () const |
|
template<typename T2 , Bool S2> |
Result< void > | CopyValuesFrom (const Block< T2, S2 > &other) |
|
template<typename COLLECTION > |
Result< void > | CopyValuesFrom (const COLLECTION &other) |
|
Int | GetMemorySize () const |
|
Int | GetBlock (Int index, Block< const T, false > &block) const |
|
Int | GetBlock (Int index, Block< T, false > &block) |
|
Int | GetBlock (Int index, StridedBlock< T > &block) |
|
Int | GetBlock (Int index, StridedBlock< const T > &block) const |
|