cisst-saw
Loading...
Searching...
No Matches
vctDynamicConstVectorRef< _elementType > Class Template Reference

Dynamic vector referencing existing memory (const). More...

#include <vctDynamicConstVectorRef.h>

Inheritance diagram for vctDynamicConstVectorRef< _elementType >:
vctDynamicConstVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >

Public Types

typedef vctDynamicConstVectorRef< value_typeThisType
typedef vctDynamicVectorRefOwner< value_typeVectorOwnerType
typedef vctDynamicConstVectorBase< vctDynamicVectorRefOwner< value_type >, _elementType > BaseType
typedef BaseType::CopyType CopyType
typedef VectorOwnerType::iterator iterator
typedef VectorOwnerType::const_iterator const_iterator
typedef VectorOwnerType::reverse_iterator reverse_iterator
typedef VectorOwnerType::const_reverse_iterator const_reverse_iterator

Public Member Functions

 VCT_CONTAINER_TRAITS_TYPEDEFS (_elementType)
 vctDynamicConstVectorRef ()
 vctDynamicConstVectorRef (const ThisType &other)
 vctDynamicConstVectorRef (size_type size, pointer data, stride_type stride=1)
 vctDynamicConstVectorRef (size_type size, const_pointer data, stride_type stride=1)
template<size_type __size, stride_type __stride, class __dataPtrType>
 vctDynamicConstVectorRef (const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector)
template<size_type __size, stride_type __stride, class __dataPtrType>
 vctDynamicConstVectorRef (const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length)
template<class __vectorOwnerType>
 vctDynamicConstVectorRef (const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > &otherVector)
template<class __vectorOwnerType>
 vctDynamicConstVectorRef (const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length)
void SetRef (size_type size, const_pointer p, stride_type stride=1)
template<size_type __size, stride_type __stride, class __dataPtrType>
void SetRef (const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector)
template<size_type __size, stride_type __stride, class __dataPtrType>
void SetRef (const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length) CISST_THROW(std
template<class __vectorOwnerType>
void SetRef (const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > &otherVector)
template<class __vectorOwnerType>
void SetRef (const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length) CISST_THROW(std

Detailed Description

template<class _elementType>
class vctDynamicConstVectorRef< _elementType >

Dynamic vector referencing existing memory (const).

The class vctDynamicConstVectorRef allows to create a vector overlaying an existing block of memory. It can be used to manipulate a container created by another toolkit (i.e. OpenGL, vtk, ...) or a cisstVector container using different parameters (different size, storage order or stride).

To setup the overlay, one can use either the constructors or the SetRef methods. When used with a cisst container, the SetRef methods can infer some of the memory layout information (pointer on first element, size, stride). When used to overlay existing memory referenced by a pointer, the user has to provide all the required information. In any case, the Ref object doesn't allocate nor free memory.

Finally, as this overlay is const, it can be used to make sure the referenced content is not modified.

For example to manipulate the first five elements of a vector, one can do:

vctDynamicVector<double> wholeVector(10);
vctRandom(wholeVector, -10.0, 10.0);
first5.SetRef(wholeVector, 0, 5);
std::cout << first5 << " " << first5.SumOfElements() << std::endl;
void SetRef(size_type size, const_pointer p, stride_type stride=1)
Definition vctDynamicConstVectorRef.h:154
vctDynamicConstVectorRef()
Definition vctDynamicConstVectorRef.h:92
Definition vctForwardDeclarations.h:131
void vctRandom(vctDynamicMatrixBase< _matrixOwnerType, _elementType > &matrix, const typename vctDynamicMatrixBase< _matrixOwnerType, _elementType >::value_type min, const typename vctDynamicMatrixBase< _matrixOwnerType, _elementType >::value_type max)
Definition vctRandomDynamicMatrix.h:47
Note
Make sure the underlying memory is not freed after the Ref object is created and before it is used. This would lead to faulty memory access and potential bugs.
vctDynamicConstVectorRef only performs const operations even if it stores a non-const value_type *. It can be initialized with either value_type * or const value_type *. For a non-const Ref, see vctDynamicVectorRef.
See also
vctDynamicVector, vctDynamicVectorRef
Parameters
_elementTypeType of elements referenced. Also defined as value_type.

Member Typedef Documentation

◆ BaseType

template<class _elementType>
typedef vctDynamicConstVectorBase<vctDynamicVectorRefOwner<value_type>, _elementType> vctDynamicConstVectorRef< _elementType >::BaseType

◆ const_iterator

template<class _elementType>
typedef VectorOwnerType::const_iterator vctDynamicConstVectorRef< _elementType >::const_iterator

◆ const_reverse_iterator

◆ CopyType

template<class _elementType>
typedef BaseType::CopyType vctDynamicConstVectorRef< _elementType >::CopyType

◆ iterator

template<class _elementType>
typedef VectorOwnerType::iterator vctDynamicConstVectorRef< _elementType >::iterator

◆ reverse_iterator

template<class _elementType>
typedef VectorOwnerType::reverse_iterator vctDynamicConstVectorRef< _elementType >::reverse_iterator

◆ ThisType

template<class _elementType>
typedef vctDynamicConstVectorRef<value_type> vctDynamicConstVectorRef< _elementType >::ThisType

◆ VectorOwnerType

template<class _elementType>
typedef vctDynamicVectorRefOwner<value_type> vctDynamicConstVectorRef< _elementType >::VectorOwnerType

Constructor & Destructor Documentation

◆ vctDynamicConstVectorRef() [1/8]

template<class _elementType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( )
inline

Default constructor initializes the vector reference to NULL

◆ vctDynamicConstVectorRef() [2/8]

template<class _elementType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( const ThisType & other)
inline

Copy constructor

◆ vctDynamicConstVectorRef() [3/8]

template<class _elementType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( size_type size,
pointer data,
stride_type stride = 1 )
inline

◆ vctDynamicConstVectorRef() [4/8]

template<class _elementType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( size_type size,
const_pointer data,
stride_type stride = 1 )
inline

◆ vctDynamicConstVectorRef() [5/8]

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > & otherVector)
inline

Initialize a dynamic reference to a fixed-size vector.

Note
This constructor is non-explicit, and allows automatic conversion from a fixed-size vector to a dynamic vector representation.
The size and stride values are taken from the fixed size vector.

◆ vctDynamicConstVectorRef() [6/8]

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > & otherVector,
size_type startPosition,
size_type length )
inline

Initialize a dynamic reference to specified subvector of a fixed-size vector.

Note
This constructor allows automatic conversion from a fixed-size vector to a dynamic vector representation.
The stride values are taken from the fixed size vector, but the starting point and length must be specified.

◆ vctDynamicConstVectorRef() [7/8]

template<class _elementType>
template<class __vectorOwnerType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > & otherVector)
inline

Initialize a dynamic reference to a dynamic vector.

Note
the starting point, size, and stride, are taken from the other vector.

◆ vctDynamicConstVectorRef() [8/8]

template<class _elementType>
template<class __vectorOwnerType>
vctDynamicConstVectorRef< _elementType >::vctDynamicConstVectorRef ( const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > & otherVector,
size_type startPosition,
size_type length )
inline

Initialize a dynamic reference to a specified subvector of a dynamic vector.

Note
the stride is taken from the other vector, but the starting point and the length must be specified.

Member Function Documentation

◆ SetRef() [1/5]

template<class _elementType>
template<class __vectorOwnerType>
void vctDynamicConstVectorRef< _elementType >::SetRef ( const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > & otherVector)
inline

Set a dynamic reference to a dynamic vector

Note
the size and memory stride of this reference will be equal to the size memory stride of the input vector.

◆ SetRef() [2/5]

template<class _elementType>
template<class __vectorOwnerType>
void vctDynamicConstVectorRef< _elementType >::SetRef ( const vctDynamicConstVectorBase< __vectorOwnerType, _elementType > & otherVector,
size_type startPosition,
size_type length )
inline

Set a dynamic reference to a specified subvector of dynamic vector

Note
the memory stride of this reference will be equal to the memory stride of the input vector.
This method verifies that the size of this vector does not exceed the size of the input vector (otherwise cmnThrow is used to throw std::out_of_range).

◆ SetRef() [3/5]

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
void vctDynamicConstVectorRef< _elementType >::SetRef ( const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > & otherVector)
inline

Set a dynamic reference to a fixed-size vector

Note
the size and memory stride of this reference will be equal to the size and memory stride of the input vector.

◆ SetRef() [4/5]

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
void vctDynamicConstVectorRef< _elementType >::SetRef ( const vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > & otherVector,
size_type startPosition,
size_type length )
inline

Set a dynamic reference to a specified subvector of a fixed-size vector

Note
the memory stride of this reference will be equal to the memory stride of the input vector.
This method verifies that the size of this vector does not exceed the size of the input vector (otherwise cmnThrow is used to throw std::out_of_range).

◆ SetRef() [5/5]

template<class _elementType>
void vctDynamicConstVectorRef< _elementType >::SetRef ( size_type size,
const_pointer p,
stride_type stride = 1 )
inline

◆ VCT_CONTAINER_TRAITS_TYPEDEFS()

template<class _elementType>
vctDynamicConstVectorRef< _elementType >::VCT_CONTAINER_TRAITS_TYPEDEFS ( _elementType )

The documentation for this class was generated from the following file: