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
PyCompilerFlags * flags
Definition: ast.h:14
static MAXON_METHOD Result< Int32 > ToInt32(const Block< const Utf32Char > &str, STRINGCONVERSION flags)
void * str
Definition: bytesobject.h:77
STRINGCONVERSION
Flags for the string to value conversion.
Definition: string.h:40
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)) |
|
template<Int N> |
MAXON_IMPLICIT | Block (T(&array)[N]) |
|
MAXON_IMPLICIT | Block (const std::initializer_list< typename std::remove_const< T >::type > &list) |
|
template<typename ANY , typename = typename std::enable_if<BYTE_BLOCK, ANY>::type> |
| Block (ANY *ptr, Int size) |
|
template<typename ANY , typename = typename std::enable_if<BYTE_BLOCK, ANY>::type> |
| Block (const Block< ANY > &src) |
|
template<typename ANY , Int N, typename = typename std::enable_if<BYTE_BLOCK, ANY>::type> |
MAXON_IMPLICIT | Block (ANY(&array)[N]) |
|
| 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, DeleteReturnType01, Block< T, true, MOVE >>::type () const |
|
| operator typename std::conditional< STRIDED||CONSTBLOCK, DeleteReturnType02, Block< const T, true, MOVE >>::type () const |
|
| operator typename std::conditional< CONSTBLOCK, DeleteReturnType03, const Block< const T, STRIDED, MOVE > & >::type () const |
|
| operator typename std::conditional< STRIDED||!MOVE, DeleteReturnType04, Block< T, true, false >>::type () const |
|
| operator typename std::conditional< STRIDED||!MOVE||CONSTBLOCK, DeleteReturnType05, Block< const T, true, false >>::type () const |
|
| operator typename std::conditional<!MOVE||CONSTBLOCK, DeleteReturnType06, const Block< const T, STRIDED, false > & >::type () const |
|
| operator typename std::conditional<!MOVE, DeleteReturnType07, const Block< T, STRIDED, false > & >::type () const |
|
| operator typename std::conditional< GENERIC, DeleteReturnType08, const Block< typename InheritConst< Generic, T >::type, STRIDED > & >::type () const |
|
| operator typename std::conditional< BYTE_OR_CHAR, const Block< typename InheritConst< SwapByteChar, T >::type, STRIDED >, DeleteReturnType09 >::type & () const |
|
| operator typename std::conditional< BYTE_OR_CHAR &&!CONSTBLOCK, const Block< const SwapByteChar, STRIDED >, const DeleteReturnType09 >::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 |
|
Bool | EndsWith (const Block &suffix) const |
|
Iterator | Begin () const |
|
Iterator | End () const |
|
Int | GetCapacityCount () const |
|
template<typename T2 , Bool S2, Bool M2> |
Result< void > | CopyValuesFrom (const Block< T2, S2, M2 > &other) |
|
template<typename T2 , Bool S2, Bool M2> |
Result< void > | ConstructValuesFrom (const Block< T2, S2, M2 > &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, typename std::conditional< CONSTBLOCK, DeleteReturnType01, Block< T, false > & >::type block) const |
|
Int | GetBlock (Int index, typename std::conditional< CONSTBLOCK, DeleteReturnType02, StridedBlock< T > & >::type block) const |
|
Int | GetBlock (Int index, StridedBlock< const T > &block) const |
|
UniqueHash | GetUniqueHashCode () const |
|
template<typename HASH = DefaultCompare> |
void | CombineUniqueHash (UniqueHasher &hash) const |
|
template<typename BLOCK , typename COMPARE > |
std::enable_if<!STRIDED &&std::is_same< BLOCK, Block >::value, Bool >::type | IsEqualImpl (const BLOCK &other, COMPARE &&cmp, OverloadRank1) const |
|
T * | GetPtr (Int index) const |
|
MAXON_ATTRIBUTE_FORCE_INLINE | ArrayBase (ARGS &&... args) |
|
ArrayImpl< Block< T, STRIDED, MOVE > & > | ToArray () |
|
ArrayImpl< const Block< T, STRIDED, MOVE > & > | ToArray () const |
|
MAXON_ATTRIBUTE_FORCE_INLINE | operator ArrayImpl< Block< T, STRIDED, MOVE > & > () |
|
MAXON_ATTRIBUTE_FORCE_INLINE | operator ArrayImpl< const Block< T, STRIDED, MOVE > & > () const |
|
template<typename... ARGS> |
MAXON_ATTRIBUTE_FORCE_INLINE | ArrayBase0 (ARGS &&... args) |
|
Bool | IsValidIndex (Int index) const |
|
Result< void > | CheckValidIndex (Int index) const |
|
Int | FindIndex (typename ByValueParam< VALUETYPE >::type v, Int start) const |
|
Int | FindLastIndex (typename ByValueParam< VALUETYPE >::type v) const |
|
Int | FindLastIndex (typename ByValueParam< VALUETYPE >::type v, Int start) const |
|
Bool | EraseFirst (typename ByValueParam< VALUETYPE >::type v) |
|
Int | EraseAll (typename ByValueParam< VALUETYPE >::type v) |
|
template<typename COLLECTION2 > |
Result< void > | AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0) |
|
template<typename COLLECTION2 > |
Result< void > | InsertAll (Int index, COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
|
template<typename COLLECTION2 > |
Result< void > | Add (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
|
template<typename COLLECTION2 > |
Result< void > | SubtractImpl (COLLECTION2 &&other, OverloadRank0) |
|
template<typename COLLECTION2 , typename COMPARE > |
Bool | IsEqualImpl (const COLLECTION2 &other, COMPARE &&cmp, OverloadRank0) const |
|
HashInt | GetHashCode () const |
|
UniqueHash | GetUniqueHashCode () const |
|
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< COLLECTION > | Slice (Int start) |
|
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< const COLLECTION > | Slice (Int start) const |
|
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< COLLECTION > | Slice (Int start, Int end) |
|
MAXON_ATTRIBUTE_FORCE_INLINE AutoIterator< const COLLECTION > | Slice (Int start, Int end) const |
|
BlockIterator< COLLECTION, VALUETYPE, false, false > | GetBlocks () |
|
BlockIterator< COLLECTION, VALUETYPE, true, false > | GetBlocks () const |
|
BlockIterator< COLLECTION, VALUETYPE, false, true > | GetStridedBlocks () |
|
BlockIterator< COLLECTION, VALUETYPE, true, true > | GetStridedBlocks () const |
|
template<typename... ARGS> |
MAXON_ATTRIBUTE_FORCE_INLINE | Collection (ARGS &&... args) |
|
ResultOk< void > | VariadicAppend () |
|
template<typename V , typename... VALUES> |
Result< void > | VariadicAppend (V &&value, VALUES &&... rest) |
|
| operator ValueReceiver< const VALUETYPE & > () |
|
| operator ValueReceiver< VALUETYPE && > () |
|
| operator ValueReceiver< typename std::conditional< STD_IS_REPLACEMENT (scalar, VALUETYPE) |
|
DummyParamType & | type () |
|
template<typename FN > |
Result< Bool > | ForEach (FN &&callback) const |
|
template<typename FN > |
Result< Bool > | ForEach (FN &&callback) |
|
template<typename H = COLLECTION> |
H::Iterator | Find (typename ByValueParam< VALUETYPE >::type v) |
|
template<typename H = COLLECTION> |
H::ConstIterator | Find (typename ByValueParam< VALUETYPE >::type v) const |
|
Int | FindIndex (typename ByValueParam< VALUETYPE >::type v) const |
|
MAXON_ATTRIBUTE_FORCE_INLINE Bool | Contains (typename ByValueParam< VALUETYPE >::type v) const |
|
template<typename... ARGS> |
MAXON_ATTRIBUTE_FORCE_INLINE | BaseCollection (ARGS &&... args) |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type | operator== (const COLLECTION2 &other) const |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type | operator!= (const COLLECTION2 &other) const |
|
template<typename COMPARE = EqualityCompare, typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value &&!STD_IS_REPLACEMENT(same, typename std::decay< COMPARE >::type, EQUALITY), Bool >::type | IsEqual (const COLLECTION2 &other, COMPARE &&cmp=COMPARE()) const |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | CopyFrom (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE) |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | Subtract (COLLECTION2 &&other) |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | Intersect (const COLLECTION2 &other) |
|
template<typename COLLECTION2 > |
Bool | Intersects (const COLLECTION2 &other) const |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | CopyFromImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0) |
|
template<typename COLLECTION2 > |
Result< void > | AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0) |
|
template<typename COLLECTION2 > |
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=nullptr) const |
|
template<typename COLLECTION2 > |
MAXON_ATTRIBUTE_FORCE_INLINE Bool | ContainsAll (COLLECTION2 &&other) const |
|
template<typename COLLECTION2 > |
Bool | ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const |
|