ERC CISST - cisst software

vctDynamicVectorRef< _elementType > Class Template Reference
[Vectors]

#include <vctDynamicVectorRef.h>

Inheritance diagram for vctDynamicVectorRef< _elementType >:

Inheritance graph
[legend]
Collaboration diagram for vctDynamicVectorRef< _elementType >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class _elementType>
class vctDynamicVectorRef< _elementType >

Dynamic vector referencing existing memory.

The class vctDynamicVectorRef 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.

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

  vctDynamicVector<double> wholeVector(10);
  vctRandom(wholeVector, -10.0, 10.0);
  vctDynamicVectorRef<double> first5;
  first5.SetRef(wholeVector, 0, 5);
  first5.SetAll(5.0);

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.

vctDynamicVectorRef can perform const and non-const operations. It can be initialized with a non-const object only (value_type *). For a const Ref, see vctDynamicConstVectorRef.

See also:
vctDynamicVector, vctDynamicConstVectorRef
Parameters:
_elementType Type of elements referenced. Also defined as value_type.

Definition at line 80 of file vctDynamicVectorRef.h.

Public Types

Public Member Functions

Public Attributes


Member Typedef Documentation

template<class _elementType>
typedef vctDynamicVectorRef<_elementType> vctDynamicVectorRef< _elementType >::ThisType

Type of the vector itself.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 84 of file vctDynamicVectorRef.h.

template<class _elementType>
typedef vctDynamicVectorBase<vctDynamicVectorRefOwner<_elementType>, _elementType> vctDynamicVectorRef< _elementType >::BaseType

Type of the base class.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 86 of file vctDynamicVectorRef.h.

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

The type used to create a copy.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 87 of file vctDynamicVectorRef.h.

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

Iterator on the elements of the vector.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 88 of file vctDynamicVectorRef.h.

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

Const iterator on the elements of the vector.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 89 of file vctDynamicVectorRef.h.

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

Reverse iterator on the elements of the vector.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 90 of file vctDynamicVectorRef.h.

template<class _elementType>
typedef VectorOwnerType::const_reverse_iterator vctDynamicVectorRef< _elementType >::const_reverse_iterator

Const reverse iterator on the elements of the vector.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 91 of file vctDynamicVectorRef.h.


Constructor & Destructor Documentation

template<class _elementType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef (  )  [inline]

Default constructor initializes the vector reference to NULL

Definition at line 94 of file vctDynamicVectorRef.h.

template<class _elementType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef ( const ThisType other  )  [inline]

Copy constructor. This copy constructor takes a const reference on the object to copy but has to remove the const-ness of the point to create a vctDynamicVectorRef and allow it to manipulate elements. The explict use of a const_cast is far from great but there is no easy solution as C++ requires the copy constructor to take a const reference.

Definition at line 103 of file vctDynamicVectorRef.h.

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef ( vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &  otherVector,
size_type  startPosition = 0 
) [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.

Definition at line 120 of file vctDynamicVectorRef.h.

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef ( vctFixedSizeVectorBase< __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.

Definition at line 133 of file vctDynamicVectorRef.h.

template<class _elementType>
template<class __vectorOwnerType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef ( vctDynamicVectorBase< __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.

Definition at line 143 of file vctDynamicVectorRef.h.

template<class _elementType>
template<class __vectorOwnerType>
vctDynamicVectorRef< _elementType >::vctDynamicVectorRef ( vctDynamicVectorBase< __vectorOwnerType, _elementType > &  otherVector,
size_type  startPosition,
size_type  length 
) [inline]

Initialize a dynamic reference to a dynamic vector.

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

Definition at line 153 of file vctDynamicVectorRef.h.


Member Function Documentation

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
void vctDynamicVectorRef< _elementType >::SetRef ( vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &  otherVector,
size_type  startPosition = 0 
) [inline]

Set a dynamic reference to a fixed-size vector.

Parameters:
otherVector the vector for which a new reference is set.
startPosition the index of the first element in otherVector to be indexed by this reference.
Note:
The size of the reference is set to the size of otherVector minus the startPosition. By default, startPosition=0 and the behavior is transparent.

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

Definition at line 174 of file vctDynamicVectorRef.h.

template<class _elementType>
template<size_type __size, stride_type __stride, class __dataPtrType>
void vctDynamicVectorRef< _elementType >::SetRef ( vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &  otherVector,
size_type  startPosition,
size_type  length 
) throw (std::out_of_range) [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).

Definition at line 188 of file vctDynamicVectorRef.h.

template<class _elementType>
template<class __vectorOwnerType>
void vctDynamicVectorRef< _elementType >::SetRef ( vctDynamicVectorBase< __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.

Definition at line 202 of file vctDynamicVectorRef.h.

template<class _elementType>
template<class __vectorOwnerType>
void vctDynamicVectorRef< _elementType >::SetRef ( vctDynamicVectorBase< __vectorOwnerType, _elementType > &  otherVector,
size_type  startPosition,
size_type  length 
) throw (std::out_of_range) [inline]

Set a dynamic reference to a specified subvector of a 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).

Definition at line 214 of file vctDynamicVectorRef.h.

template<class _elementType>
ThisType& vctDynamicVectorRef< _elementType >::operator= ( const ThisType other  )  [inline]

Assignment operation between vectors of different types

Parameters:
other The vector to be copied.
Note:
We overload operator = to perform elemenwise copy/assign. Although one may consider other meanings for the overloaded operator, we thought this was the most natural one.

Definition at line 237 of file vctDynamicVectorRef.h.

template<class _elementType>
ThisType& vctDynamicVectorRef< _elementType >::operator= ( const vctDynamicConstVectorRef< value_type > &  other  )  [inline]

Assignment operation between vectors of different types

Parameters:
other The vector to be copied.
Note:
We overload operator = to perform elemenwise copy/assign. Although one may consider other meanings for the overloaded operator, we thought this was the most natural one.

Definition at line 242 of file vctDynamicVectorRef.h.

template<class _elementType>
template<class __vectorOwnerType, typename __elementType>
ThisType& vctDynamicVectorRef< _elementType >::operator= ( const vctDynamicConstVectorBase< __vectorOwnerType, __elementType > &  other  )  [inline]

Assignment operation between vectors of different types

Parameters:
other The vector to be copied.
Note:
We overload operator = to perform elemenwise copy/assign. Although one may consider other meanings for the overloaded operator, we thought this was the most natural one.

Reimplemented from vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType >.

Definition at line 247 of file vctDynamicVectorRef.h.

template<class _elementType>
ThisType& vctDynamicVectorRef< _elementType >::operator= ( const value_type &  value  )  [inline]

Assignement of a scalar to all elements. See also SetAll.

Definition at line 253 of file vctDynamicVectorRef.h.

template<class _elementType>
void vctDynamicVectorRef< _elementType >::DeSerializeRaw ( std::istream &  inputStream  )  throw (std::runtime_error) [inline]

Binary deserialization. This method can not resize the existing block of memory and will throw an exception is the sizes don't match.

Definition at line 261 of file vctDynamicVectorRef.h.


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu