cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctDynamicNArrayRef.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Daniel Li, Ofri Sadowsky, Anton Deguet
7  Created on: 2006-07-13
8 
9  (C) Copyright 2006-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #pragma once
22 #ifndef _vctDynamicNArrayRef_h
23 #define _vctDynamicNArrayRef_h
24 
33 
86 template <class _elementType, vct::size_type _dimension>
88  public vctDynamicNArrayBase<vctDynamicNArrayRefOwner<_elementType, _dimension>, _elementType, _dimension>
89 {
90 public:
91  /* define most types from vctContainerTraits and vctNArrayTraits */
92  enum {DIMENSION = _dimension};
93  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
95 
96  /* documented in base class */
104 
105 
107  {
108  this->SetRef(0, nsize_type(0), nstride_type(0));
109  }
110 
118  BaseType()
119  {
120  this->SetRef(const_cast<pointer>(other.Pointer()), other.sizes(), other.strides());
121  }
122 
126  vctDynamicNArrayRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
127  {
128  this->SetRef(dataPointer, sizes, strides);
129  }
130 
134  template <class __ownerType>
136  {
137  this->SetRef(otherNArray);
138  }
139 
143  template <class __ownerType>
145  {
146  this->SetRef(vector);
147  }
148 
152  template <size_type __size, stride_type __stride, typename __dataPtrType>
154  {
155  this->SetRef(vector);
156  }
157 
161  template <class __ownerType>
163  {
164  this->SetRef(matrix);
165  }
166 
170  template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
172  {
173  this->SetRef(matrix);
174  }
175 
176 
180  void SetRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
181  {
182  this->NArray.SetRef(dataPointer, sizes, strides);
183  }
184 
188  template <class __ownerType>
190  {
191  this->SetRef(otherNArray.Pointer(), otherNArray.sizes(), otherNArray.strides());
192  }
193 
201  template <class __ownerType>
203  const nsize_type & startPosition,
204  const nsize_type & lengths)
205  {
206  CMN_ASSERT((startPosition + lengths).LesserOrEqual(otherNArray.sizes()));
207  this->SetRef(otherNArray.Pointer(startPosition), lengths, otherNArray.strides());
208  }
209 
217  template <class __ownerType>
219  const ndimension_type & dimensions)
220  {
221  nsize_type sizes;
222  nstride_type strides;
223 
224  const typename ndimension_type::const_iterator dimensionsBegin = dimensions.begin();
225  const typename ndimension_type::const_iterator dimensionsEnd = dimensions.end();
226  typename ndimension_type::const_iterator dimensionsIter;
227  typename nsize_type::iterator sizesIter = sizes.begin();
228  typename nstride_type::iterator stridesIter = strides.begin();
229  for (dimensionsIter = dimensionsBegin;
230  dimensionsIter != dimensionsEnd;
231  ++dimensionsIter, ++sizesIter, ++stridesIter) {
232  *sizesIter = otherNArray.size(*dimensionsIter);
233  *stridesIter = otherNArray.stride(*dimensionsIter);
234  }
235 
236  this->SetRef(otherNArray.Pointer(), sizes, strides);
237  }
238 
247  template <class __ownerType>
249  dimension_type dimension,
250  size_type index)
251  {
252  // set up local sizes and strides
253  nsize_type sizes;
254  nstride_type strides;
255  size_type i;
256 
258  typedef typename OtherArrayType::nsize_type other_nsize_type;
259  typedef typename OtherArrayType::nstride_type other_nstride_type;
260 
261  // set up iterators
262  const typename other_nsize_type::const_iterator otherSizesBegin = otherNArray.sizes().begin();
263  typename other_nsize_type::const_iterator otherSizesIter;
264  const typename other_nstride_type::const_iterator otherStridesBegin = otherNArray.strides().begin();
265  typename other_nstride_type::const_iterator otherStridesIter;
266  const typename nsize_type::iterator sizesBegin = sizes.begin();
267  const typename nsize_type::iterator sizesEnd = sizes.end();
268  typename nsize_type::iterator sizesIter;
269  const typename nstride_type::iterator stridesBegin = strides.begin();
270  typename nstride_type::iterator stridesIter;
271 
272  // copy sizes and strides in every dimension except the one specified
273  otherSizesIter = otherSizesBegin;
274  otherStridesIter = otherStridesBegin;
275  sizesIter = sizesBegin;
276  stridesIter = stridesBegin;
277  i = 0;
278  while (sizesIter != sizesEnd) {
279  if (i == dimension) {
280  ++otherSizesIter;
281  ++otherStridesIter;
282  ++i;
283  } else {
284  *sizesIter = *otherSizesIter;
285  *stridesIter = *otherStridesIter;
286 
287  ++otherSizesIter;
288  ++otherStridesIter;
289  ++sizesIter;
290  ++stridesIter;
291  ++i;
292  }
293  }
294 
295  // set start position
296  other_nsize_type startPosition(static_cast<size_type>(0));
297  startPosition[dimension] = index;
298  this->SetRef(otherNArray.Pointer(startPosition), sizes, strides);
299  }
300 
304  template <class __ownerType>
306  {
307  this->SetRef( vector.Pointer(), nsize_type(vector.size()), nstride_type(vector.stride()) );
308  }
309 
313  template <size_type __size, stride_type __stride, typename __dataPtrType>
315  {
316  this->SetRef( vector.Pointer(), nsize_type(__size), nstride_type(__stride) );
317  }
318 
322  template <class __ownerType>
324  {
325  this->SetRef(matrix.Pointer(),
326  nsize_type(matrix.rows(), matrix.cols()),
327  nstride_type(matrix.row_stride(), matrix.col_stride()));
328  }
329 
333  template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
335  {
336  this->SetRef(matrix.Pointer(),
337  nsize_type(__rows, __cols),
338  nstride_type(__rowStride, __colStride));
339  }
340 
341 
347  inline ThisType & operator = (const ThisType & other)
348  {
349  return reinterpret_cast<ThisType &>(this->Assign(other));
350  }
351 
353  {
354  return reinterpret_cast<ThisType &>(this->Assign(other));
355  }
356 
357  template <class __nArrayOwnerType, typename __elementType>
359  {
360  return reinterpret_cast<ThisType &>(this->Assign(other));
361  }
363 
365  inline ThisType & operator = (const value_type & value)
366  {
367  this->SetAll(value);
368  return *this;
369  }
370 
371 };
372 
373 
374 #endif // _vctDynamicNArrayRef_h
375 
A template for a fixed size matrix with fixed spacing in memory.
Definition: vctFixedSizeConstMatrixBase.h:103
#define CMN_ASSERT(expr)
Definition: cmnAssert.h:90
dimension_type dimension(void) const
Definition: vctDynamicConstNArrayBase.h:332
vctDynamicNArrayRef(const ThisType &other)
Definition: vctDynamicNArrayRef.h:117
const nsize_type & sizes(void) const
Definition: vctDynamicConstNArrayBase.h:308
void SetRef(vctDynamicConstVectorBase< __ownerType, _elementType > &vector)
Definition: vctDynamicNArrayRef.h:305
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
vctDynamicNArrayRef(vctDynamicConstMatrixBase< __ownerType, _elementType > &matrix)
Definition: vctDynamicNArrayRef.h:162
void SubarrayOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray, const nsize_type &startPosition, const nsize_type &lengths)
Definition: vctDynamicNArrayRef.h:202
vctDynamicNArrayRef(vctDynamicConstVectorBase< __ownerType, _elementType > &vector)
Definition: vctDynamicNArrayRef.h:144
vctDynamicNArrayRef(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray)
Definition: vctDynamicNArrayRef.h:135
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
size_t size_type
Definition: vctContainerTraits.h:35
void PermutationOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray, const ndimension_type &dimensions)
Definition: vctDynamicNArrayRef.h:218
bool LesserOrEqual(const vctDynamicConstNArrayBase< __nArrayOwnerType, value_type, DIMENSION > &otherNArray) const
Definition: vctDynamicConstNArrayBase.h:816
NArrayOwnerType::iterator iterator
Definition: vctDynamicNArrayRef.h:100
NArrayOwnerType::const_iterator const_iterator
Definition: vctDynamicNArrayRef.h:101
Dynamic nArray referencing existing memory (const)
Definition: vctDynamicConstNArrayRef.h:89
Definition: vctDynamicConstMatrixBase.h:77
Declaration of vctDynamicConstNArrayRef.
ThisType & operator=(const ThisType &other)
Definition: vctDynamicNArrayRef.h:347
Definition: vctDynamicNArrayRefOwner.h:36
void SetRef(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION > &otherNArray)
Definition: vctDynamicNArrayRef.h:189
pointer Pointer(const nsize_type &indices)
Definition: vctDynamicNArrayBase.h:156
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
Definition: vctForwardDeclarations.h:77
void SetRef(vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix)
Definition: vctDynamicNArrayRef.h:334
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
ThisType & Assign(const vctDynamicConstNArrayBase< __nArrayOwnerType, value_type, DIMENSION > &other)
Definition: vctDynamicNArrayBase.h:374
NArrayOwnerType::const_reverse_iterator const_reverse_iterator
Definition: vctDynamicNArrayRef.h:103
Declaration of vctDynamicNArrayBase.
Dynamic nArray referencing existing memory.
Definition: vctDynamicNArrayRef.h:87
vctDynamicNArrayRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicNArrayRef.h:126
const_pointer Pointer(size_type index=0) const
Definition: vctFixedSizeConstVectorBase.h:268
difference_type stride() const
Definition: vctDynamicConstVectorBase.h:169
const_pointer Pointer(index_type rowIndex, index_type colIndex) const
Definition: vctDynamicConstMatrixBase.h:306
void SetRef(vctDynamicConstMatrixBase< __ownerType, _elementType > &matrix)
Definition: vctDynamicNArrayRef.h:323
vctDynamicNArrayBase< vctDynamicNArrayRefOwner< _elementType, DIMENSION >, _elementType, DIMENSION > BaseType
Definition: vctDynamicNArrayRef.h:99
const_pointer Pointer(index_type index=0) const
Definition: vctDynamicConstVectorBase.h:221
void SetRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicNArrayRef.h:180
Definition: vctDynamicNArrayBase.h:42
Definition: vctDynamicNArrayRef.h:92
vctDynamicNArrayRefOwner< _elementType, DIMENSION > NArrayOwnerType
Definition: vctDynamicNArrayRef.h:98
Definition: vctForwardDeclarations.h:74
size_type size(void) const
Definition: vctDynamicConstNArrayBase.h:302
Definition: vctDynamicConstVectorBase.h:77
void SetRef(vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &vector)
Definition: vctDynamicNArrayRef.h:314
difference_type row_stride() const
Definition: vctDynamicConstMatrixBase.h:263
const nstride_type & strides(void) const
Definition: vctDynamicConstNArrayBase.h:320
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
difference_type col_stride() const
Definition: vctDynamicConstMatrixBase.h:268
vctDynamicNArrayRef(vctFixedSizeConstVectorBase< __size, __stride, _elementType, __dataPtrType > &vector)
Definition: vctDynamicNArrayRef.h:153
value_type SetAll(const value_type value)
Definition: vctDynamicNArrayBase.h:341
difference_type stride(dimension_type dimension) const
Definition: vctDynamicConstNArrayBase.h:326
void SetRef(pointer data, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicNArrayRefOwner.h:67
vctDynamicNArrayRef()
Definition: vctDynamicNArrayRef.h:106
vctDynamicNArrayRef< _elementType, DIMENSION > ThisType
Definition: vctDynamicNArrayRef.h:97
NArrayOwnerType::reverse_iterator reverse_iterator
Definition: vctDynamicNArrayRef.h:102
void SliceOf(vctDynamicNArrayBase< __ownerType, _elementType, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition: vctDynamicNArrayRef.h:248
vctDynamicNArrayRef(vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, _elementType, __dataPtrType > &matrix)
Definition: vctDynamicNArrayRef.h:171
Declaration of vctDynamicNArrayRefOwner.