Block< T, STRIDED, MOVE > Class Template Reference Data Types

| Data Structures

#include <block.h>

详细描述

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

static Result<Int32> StringConversion::ToInt32 ( const Block<const Utf32Char>& str, STRINGCONVERSION flags);

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).
另请参阅
$ref blocks

Classes

class   ResultFunctions

Public Types

using  Super = ArrayBase < Block < T, STRIDED, MOVE >, T, BlockBase < T, STRIDED >, DefaultCompare >
using  StrideType = typename std::conditional< GENERIC , Char , T >:: type
using  IsBlock = std::true_type
using  Iterator = BaseIterator < Block , STRIDED >
using  ConstIterator = BaseIterator < const Block , STRIDED >

公共成员函数

  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  重置 ()
  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   切片 ( Int start) const
Block   切片 ( 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

静态公共成员函数

static const Block NullValueRef ()

Public Attributes

const  DummyReturnType
volatile  DummyReturnType

静态公共属性

static const Bool   GENERIC

私有成员函数

T *  GetPtr ( Int index) const
ResultRef < T >  Insert ( Int index)
ResultMem   Insert ( Int index, const Block < const T > &values)
ResultRef < T >  Append ()
ResultMem   Erase ( Int index, Int count)
ResultMem   SwapErase ( Int index, Int count)
ResultMem   SetCapacityHint ( Int requestedCapacity, COLLECTION_RESIZE_FLAGS resizeFlags= COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY )
ResultMem   Resize ( Int count, COLLECTION_RESIZE_FLAGS resizeFlags= COLLECTION_RESIZE_FLAGS::DEFAULT )
void  Flush ()

Friends

template<typename ARRAY >
class  ArrayImpl

Member Typedef Documentation

◆  Super

using Super = ArrayBase < Block <T, STRIDED, MOVE>, T, BlockBase <T, STRIDED>, DefaultCompare >

◆  StrideType

using StrideType = typename std::conditional< GENERIC , Char , T>:: type

◆  IsBlock

using IsBlock = std::true_type

◆  Iterator

using Iterator = BaseIterator < Block , STRIDED>

◆  ConstIterator

using ConstIterator = BaseIterator <const Block , STRIDED>

构造函数 & 析构函数文档编制

◆  Block() [1/7]

Block ( )

Constructs an empty block with a nullptr pointer and zero count.

◆  Block() [2/7]

Block ( T *  ptr ,
Int   size ,
Int   stride = (STRIDED && GENERIC) ? -1 : SIZEOF(StrideType)  
)

Constructs a block using the given values.

参数
[in] ptr Pointer to the first element.
[in] size Number of elements.
[in] stride Element stride. If the STRIDED parameter of the Block class is false , this has to be SIZEOF(T) .

◆  Block() [3/7]

Block ( Iterator   start ,
Int   size ,
Int   stride = (STRIDED && GENERIC) ? -1 : SIZEOF(StrideType)  
)

Constructs a block from iterator and size. Equivalent to Block(static_cast<T*>(&*start), size, stride).

◆  Block() [4/7]

Block ( ConstIterator   start ,
Int   size ,
Int   stride = (STRIDED && GENERIC) ? -1 : SIZEOF(StrideType)  
)

Constructs a block from const iterator and size. Equivalent to Block(static_cast<T*>(&*start), size, stride).

◆  Block() [5/7]

MAXON_IMPLICIT Block ( T(&)  array [N] )

Constructs a block for a C++ fixed-size array. The length is automatically set to the full length of the array.

◆  Block() [6/7]

MAXON_IMPLICIT Block ( const std::initializer_list< typename std::remove_const< T >:: type > &  list )

◆  Block() [7/7]

Block ( const Block < T, STRIDED, MOVE > &  src )
default

成员函数文档编制

◆  operator=()

Block & operator= ( const Block < T, STRIDED, MOVE > &  src )
default

◆  CopyFrom()

Result <void> CopyFrom ( const Block < T, STRIDED, MOVE > &  src )
delete

◆  operator ArrayImpl< Block & >()

operator ArrayImpl < Block & > ( )
delete

◆  operator ArrayImpl< const Block & >()

operator ArrayImpl < const Block & > ( ) const
delete

◆  GetStride()

Int GetStride ( ) const

Returns the stride of this block. If the STRIDED parameter of the Block class is false , this will always be SIZEOF(T) .

返回
Element stride of this block, i.e., the difference in bytes between two consecutive elements.

◆  IsStrided()

Bool IsStrided ( ) const

Returns true if this block uses a stride other than SIZEOF(T) .

返回
True if the stride differs from the element size.

◆  Set()

void Set ( T *  ptr ,
Int   size ,
Int   stride = (STRIDED && GENERIC) ? -1 : SIZEOF(StrideType)  
)

Sets this block to new values.

参数
[in] ptr Pointer to the first element.
[in] size Number of elements.
[in] stride Element stride. If the STRIDED parameter of the Block class is false , this has to be SIZEOF(T) .

◆  Reset()

void Reset ( )

Resets this block so that is points to nullptr and has zero length.

◆  operator typename std::conditional< STRIDED, DummyReturnType, Block< T, true, MOVE >>::type()

operator typename std::conditional< STRIDED, DummyReturnType , Block < T, true, MOVE >>:: type ( ) const

Converts this block to a strided block.

◆  operator typename std::conditional< STRIDED||STD_IS_REPLACEMENT()

operator typename std::conditional< STRIDED|| STD_IS_REPLACEMENT ( const  ,
 
)

Converts this block to a strided block with constant elements.

◆  type() [1/4]

const Block <const T, true, MOVE> type ( ) const

◆  operator typename std::conditional< STD_IS_REPLACEMENT()

operator typename std::conditional< STD_IS_REPLACEMENT ( const  ,
 
)

Converts this block to a block with constant elements.

◆  type() [2/4]

volatile const Block <const T, STRIDED, MOVE>& type ( ) const

◆  operator typename std::conditional< STRIDED||!MOVE, DummyReturnType &, Block< T, true, false >>::type()

operator typename std::conditional< STRIDED||!MOVE, DummyReturnType &, Block < T, true, false >>:: type ( ) const

Converts this block to a strided non-movable block.

◆  operator typename std::conditional< STRIDED||!MOVE||STD_IS_REPLACEMENT()

operator typename std::conditional< STRIDED||!MOVE|| STD_IS_REPLACEMENT ( const  ,
 
)

Converts this block to a strided non-movable block with constant elements.

◆  type() [3/4]

const DummyReturnType Block <const T, true, false> type ( ) const

◆  operator typename std::conditional<!MOVE||STD_IS_REPLACEMENT()

operator typename std::conditional<!MOVE|| STD_IS_REPLACEMENT ( const  ,
 
)

Converts this block to a non-movable block with constant elements.

◆  type() [4/4]

volatile DummyReturnType const Block <const T, STRIDED, false>& type ( ) const

◆  operator typename std::conditional<!MOVE, const volatile DummyReturnType &, const Block< T, STRIDED, false > & >::type()

operator typename std::conditional<!MOVE, const volatile DummyReturnType &, const Block < T, STRIDED, false > & >:: type ( ) const

Converts this block to a non-movable block.

◆  operator typename std::conditional< GENERIC, const volatile DummyReturnType, const Block< typename InheritConst< Generic, T >::type, STRIDED > & >::type()

operator typename std::conditional< GENERIC , const volatile DummyReturnType , const Block < typename InheritConst < Generic, T >:: type , STRIDED > & >:: type ( ) const

Converts this block to a generic block.

◆  GetFirst()

T* GetFirst ( ) const

Returns the first element of this block. For an empty block, this is undefined and might be nullptr or any other value.

返回
Pointer to the first element of this block (undefined if the block is empty).

◆  SetFirst()

void SetFirst ( T *  value )

Sets the first element of this block, may be nullptr .

参数
[in] value Pointer to first element of this block.

◆  GetLast()

T* GetLast ( ) const

Returns the last element of this block. For an empty block, this is undefined and might be nullptr or any other value.

返回
Pointer to the last element of this block (undefined if the block is empty).

◆  operator[]()

T& operator[] ( Int   index ) const

Returns the element at the given index of this block.

参数
[in] index Index into the block.
返回
Reference to the value at index .

◆  Slice() [1/2]

Block 切片 ( Int   start ) const

Returns a sub block of this block with contains the elements from the given start index up to the end of the block.

参数
[in] start Start index of the sub block.
返回
Sub block starting at start .

◆  Slice() [2/2]

Block 切片 ( Int   start ,
Int   end  
) const

Returns a sub block of this block with contains the elements from the given start index up to but not including the given end index.

参数
[in] start Start index of the sub block.
[in] end End index of the sub block. The end index is exclusive.
返回
Sub block with elements from start up to end .

◆  StartsWith()

Bool StartsWith ( const Block < T, STRIDED, MOVE > &  prefix ) const

◆  Begin()

Iterator Begin ( ) const

Gets an iterator for the first element.

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

◆  End()

Iterator End ( ) const

Gets an iterator for the end ( End() - 1 is the last element if the array is not empty).

返回
Iterator for the array end (this is behind the last element).

◆  NullValueRef()

static const Block & NullValueRef ( )
static

◆  GetCapacityCount()

Int GetCapacityCount ( ) const

◆  CopyValuesFrom() [1/2]

Result <void> CopyValuesFrom ( const Block < T2, S2 > &  other )

◆  CopyValuesFrom() [2/2]

Result <void> CopyValuesFrom ( const COLLECTION &  other )

◆  GetMemorySize()

Int GetMemorySize ( ) const

◆  GetBlock() [1/4]

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

◆  GetBlock() [2/4]

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

◆  GetBlock() [3/4]

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

◆  GetBlock() [4/4]

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

◆  GetPtr()

T* GetPtr ( Int   index ) const
private

◆  Insert() [1/2]

ResultRef <T> Insert ( Int   index )
private

◆  Insert() [2/2]

ResultMem Insert ( Int   index ,
const Block < const T > &  values  
)
private

◆  Append()

ResultRef <T> Append ( )
private

◆  Erase()

ResultMem Erase ( Int   index ,
Int   count  
)
private

◆  SwapErase()

ResultMem SwapErase ( Int   index ,
Int   count  
)
private

◆  SetCapacityHint()

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

◆  Resize()

ResultMem Resize ( Int   count ,
COLLECTION_RESIZE_FLAGS   resizeFlags = COLLECTION_RESIZE_FLAGS::DEFAULT  
)
private

◆  Flush()

void Flush ( )
private

Friends And Related Function Documentation

◆  ArrayImpl

friend class ArrayImpl
friend

Member Data Documentation

◆  GENERIC

const Bool GENERIC static

◆  DummyReturnType [1/2]

const DummyReturnType

◆  DummyReturnType [2/2]

volatile DummyReturnType
STRINGCONVERSION
Flags for the string to value conversion.
定义: string.h:40
static MAXON_METHOD Result< Int32 > ToInt32(const Block< const Utf32Char > &str, STRINGCONVERSION flags)