ERC CISST - cisst software

vctDynamicNArray< _elementType, _dimension > Class Template Reference
[Vectors]

#include <vctDynamicNArray.h>

Inheritance diagram for vctDynamicNArray< _elementType, _dimension >:

Inheritance graph
[legend]
Collaboration diagram for vctDynamicNArray< _elementType, _dimension >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class _elementType, vct::size_type _dimension>
class vctDynamicNArray< _elementType, _dimension >

An nArray object of dynamic size.

This class defines a nArray object of dynamic size with memory allocation.

The algebraic operations are mostly inherited from the base classes vctDynamicNArrayBase and vctDynamicConstNArrayBase. Here, we will briefly describe the specific properties of vctDynamicNArray, with a few usage examples.

  1. The class is templated by its element type, that is, the nArray element. Normally, the element should be an arithmetic type, that is, support all the standard arithmetic operations: +, -, *, /, =, ==, <, >, <=, >=, ...
  2. The class is templated by dimension, i.e. for a vector-like nArray the dimension would be 1, 2 for a matrix-like nArray, 3 for a volume, ...
  3. The types nsize_type, nindex_type and nstride_type are defined within the scope of the nArray classes and used in their interfaces to set the sizes, access elements or manipulate the layout.
  4. The class uses dynamically allocated memory, and, more importantly, owns the memory. That is, a vctDynamicNArray object automatically frees the allocated memory it owns when it is destroyed.
  5. To allocate the memory, use one of the following operations.
      // define a typical element type and a couple of useful other types
      typedef double ElementType;
      enum {DIMENSION = 3};
      typedef vctDynamicNArray<ElementType, DIMENSION> ArrayType;
      typedef typename ArrayType::nsize_type SizeType;
    
      // constructor allocation, empty array
      ArrayType a1;
    
      // Create an empty nArray and later allocate memory.
      ArrayType a2;
      a2.SetSize(SizeType(5, 7, 8));
      vctRandom(a2, ElementType(0), ElementType(10));
    
      // Create an nArray of some size and change it later.
      // This operation does not preserve any elements in the resized
      // nArray
      ArrayType a3(SizeType(7, 8, 9));
      a3.SetSize(a2.sizes());
      vctRandom(a3, ElementType(-10), ElementType(0));
    
      // Store an algebraic result to a new nArray.  In this case,
      // memory is allocated by the algebraic operation, and then
      // attached to the nArray object.
      ArrayType a4 = a3 - a2;
    
  6. NArray assignment can be facilitated through the Assign method (defined in the base class) or as follows.
      // Initialize all elements to the same value
      ArrayType a5(a3.sizes(), 2.0);
    
      // Assign one matrix to another.
      vctDynamicNArray<int, DIMENSION> nArrayInt;
      nArrayInt.Assign(a5); // preferred syntax
      nArrayInt = a5; // same operation
    

A few more notes.

Parameters:
_elementType the type of an element in the nArray.
_dimension the dimension the multi-dimensional array.
See also:
vctDynamicNArrayBase vctDynamicConstNArrayBase

Definition at line 123 of file vctDynamicNArray.h.

Public Types

Public Member Functions

Public Attributes

Friends


Member Typedef Documentation

template<class _elementType, vct::size_type _dimension>
typedef vctDynamicNArrayBase<vctDynamicNArrayOwner<_elementType, _dimension>, _elementType, _dimension> vctDynamicNArray< _elementType, _dimension >::BaseType

Type of the base class

Reimplemented from vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >.

Reimplemented in vctReturnDynamicNArray< _elementType, _dimension >.

Definition at line 134 of file vctDynamicNArray.h.

template<class _elementType, vct::size_type _dimension>
typedef vctDynamicNArray<_elementType, _dimension> vctDynamicNArray< _elementType, _dimension >::ThisType

Type of the nArray itself

Reimplemented from vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >.

Definition at line 135 of file vctDynamicNArray.h.


Constructor & Destructor Documentation

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray (  )  [inline]

Default constructor. Initialize an empty nArray.

Definition at line 138 of file vctDynamicNArray.h.

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const nsize_type &  sizes  )  [inline]

Constructor: Create an nArray of the specified sizes. Elements initialized with default constructor.

Definition at line 144 of file vctDynamicNArray.h.

References vctDynamicConstNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::NArray, and vctDynamicNArrayOwner< _elementType, _dimension >::SetSize().

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const nsize_type &  sizes,
value_type  value 
) [inline]

Constructor: Create an nArray of the specified size and assign all elements a specific value.

Definition at line 151 of file vctDynamicNArray.h.

References vctDynamicConstNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::NArray, vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::SetAll(), and vctDynamicNArrayOwner< _elementType, _dimension >::SetSize().

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const vctReturnDynamicNArray< value_type, _dimension > &  otherNArray  ) 

Special copy constructor: Take ownership of the data of a temporary nArray object of type vctReturnDynamicNArray. Disown the other nArray.

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const ThisType otherNArray  )  [inline]

Copy constructor: Allocate memory to store a copy of the other nArray, and copy the elements of the other nArray to this nArray.

Definition at line 167 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
template<class _otherNArrayOwnerType>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const vctDynamicConstNArrayBase< _otherNArrayOwnerType, value_type, _dimension > &  otherNArray  )  [inline]

Copy constructor: Allocate memory to store a copy of the other nArray, and copy the elements of the other nArray to this nArray.

Definition at line 174 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
template<class _otherNArrayOwnerType, typename _otherNArrayElementType>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const vctDynamicConstNArrayBase< _otherNArrayOwnerType, _otherNArrayElementType, _dimension > &  otherNArray  )  [inline, explicit]

Copy constructor: Allocate memory and copy all the elements from the other nArray. This constructor can also be used for type conversions.

Definition at line 186 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const ThisType otherNArray  )  [inline]

Copy constructor: Allocate memory to store a copy of the other nArray, and copy the elements of the other nArray to this nArray.

Definition at line 167 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
template<class _otherNArrayOwnerType>
vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray ( const vctDynamicConstNArrayBase< _otherNArrayOwnerType, value_type, _dimension > &  otherNArray  )  [inline]

Copy constructor: Allocate memory to store a copy of the other nArray, and copy the elements of the other nArray to this nArray.

Definition at line 174 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().


Member Function Documentation

template<class _elementType, vct::size_type _dimension>
template<class __nArrayOwnerType, typename __elementType>
ThisType& vctDynamicNArray< _elementType, _dimension >::operator= ( const vctDynamicConstNArrayBase< __nArrayOwnerType, __elementType, _dimension > &  otherNArray  )  [inline]

Assignment from an nArray to this nArray. The operation discards the old memory allocated for this nArray and allocates new memory the size of the input nArray. Then the elements of the input nArray are copied into this nArray.

Definition at line 199 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
ThisType& vctDynamicNArray< _elementType, _dimension >::operator= ( const ThisType otherNArray  )  [inline]

Equals operator: Assignment from a vctDynamicNArray to this nArray (also a vctDynamicNArray). The operation discards the old memory allocated for this nArray and allocates new memory the size of the input vctDynamicNArray. Then the elements of the input vctDynamicNArray are copied into this nArray.

Definition at line 212 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::Assign(), vctDynamicNArray< _elementType, _dimension >::SetSize(), and vctDynamicConstNArrayBase< _nArrayOwnerType, _elementType, _dimension >::sizes().

template<class _elementType, vct::size_type _dimension>
ThisType& vctDynamicNArray< _elementType, _dimension >::operator= ( const vctReturnDynamicNArray< value_type, _dimension > &  otherNArray  ) 

Assignment from a transitional vctReturnDynamicNArray to a vctDynamicNArray variable. This specialized operation does not perform any element copy. Instead it transfers ownership of the data from the other nArray to this nArray, and disowns the other nArray. The right hand side operand must be a temporary object returned, e.g., from a function or overloaded operator.

Todo:
This operator needs some revisions.

template<class _elementType, vct::size_type _dimension>
ThisType& vctDynamicNArray< _elementType, _dimension >::operator= ( const value_type &  value  )  [inline]

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

Definition at line 232 of file vctDynamicNArray.h.

References vctDynamicNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::SetAll().

template<class _elementType, vct::size_type _dimension>
void vctDynamicNArray< _elementType, _dimension >::SetSize ( const nsize_type &  sizes  )  [inline]

Destructive size change. Change the size to the specified size. Discard all of the old values.

Definition at line 248 of file vctDynamicNArray.h.

References vctDynamicConstNArrayBase< vctDynamicNArrayOwner< _elementType, _dimension >, _elementType, _dimension >::NArray, and vctDynamicNArrayOwner< _elementType, _dimension >::SetSize().

Referenced by vctDynamicNArray< _elementType, _dimension >::ForceAssign(), vctDynamicNArray< _elementType, _dimension >::operator=(), and vctDynamicNArray< _elementType, _dimension >::vctDynamicNArray().


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