cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctDynamicConstNArrayRef.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-03
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 _vctDynamicConstNArrayRef_h
23 #define _vctDynamicConstNArrayRef_h
24 
32 
88 template <class _elementType, vct::size_type _dimension>
90  public vctDynamicConstNArrayBase<vctDynamicNArrayRefOwner<_elementType, _dimension>, _elementType, _dimension>
91 {
92 public:
93  /* define most types from vctContainerTraits and vctNArrayTraits */
94  enum {DIMENSION = _dimension};
95  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
97 
98  /* documented in base class */
106 
107 
109  {
110  this->SetRef(0, nsize_type(0), nstride_type(0));
111  }
112 
115  BaseType()
116  {
117  SetRef(other.Pointer(), other.sizes(), other.strides());
118  }
119 
123  vctDynamicConstNArrayRef(const_pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
124  {
125  this->SetRef(dataPointer, sizes, strides);
126  }
127 
131  vctDynamicConstNArrayRef(pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
132  {
133  this->SetRef(dataPointer, sizes, strides);
134  }
135 
139  template <class __ownerType>
141  {
142  this->SetRef(otherNArray);
143  }
144 
148  template <class __ownerType>
150  {
151  this->SetRef(vector);
152  }
153 
157  template <size_type __size, stride_type __stride, typename __dataPtrType>
159  {
160  this->SetRef(vector);
161  }
162 
166  template <class __ownerType>
168  {
169  this->SetRef(matrix);
170  }
171 
175  template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
177  __rowStride, __colStride,
178  value_type, __dataPtrType>
179  & matrix)
180  {
181  this->SetRef(matrix);
182  }
183 
184 
188  void SetRef(const_pointer dataPointer, const nsize_type & sizes, const nstride_type & strides)
189  {
190  this->NArray.SetRef( const_cast<pointer>(dataPointer), sizes, strides );
191  }
192 
196  template <class __ownerType>
198  {
199  this->SetRef( otherNArray.Pointer(), otherNArray.sizes(), otherNArray.strides() );
200  }
201 
209  template <class __ownerType>
211  const nsize_type & startPosition,
212  const nsize_type & lengths)
213  {
214  CMN_ASSERT((startPosition + lengths).LesserOrEqual(otherNArray.sizes()));
215  this->SetRef(otherNArray.Pointer(startPosition), lengths, otherNArray.strides());
216  }
217 
225  template <class __ownerType>
227  const ndimension_type & dimensions)
228  {
229  nsize_type sizes;
230  nstride_type strides;
231 
232  const typename ndimension_type::const_iterator dimensionsBegin = dimensions.begin();
233  const typename ndimension_type::const_iterator dimensionsEnd = dimensions.end();
234  typename ndimension_type::const_iterator dimensionsIter;
235  typename nsize_type::iterator sizesIter = sizes.begin();
236  typename nstride_type::iterator stridesIter = strides.begin();
237  for (dimensionsIter = dimensionsBegin;
238  dimensionsIter != dimensionsEnd;
239  ++dimensionsIter, ++sizesIter, ++stridesIter) {
240  *sizesIter = otherNArray.size(*dimensionsIter);
241  *stridesIter = otherNArray.stride(*dimensionsIter);
242  }
243 
244  this->SetRef(otherNArray.Pointer(), sizes, strides);
245  }
246 
255  template <class __ownerType>
257  dimension_type dimension,
258  size_type index)
259  {
260  // set up local sizes and strides
261  nsize_type sizes;
262  nstride_type strides;
263  size_type i;
264 
266  typedef typename OtherArrayType::nsize_type other_nsize_type;
267  typedef typename OtherArrayType::nstride_type other_nstride_type;
268 
269  // set up iterators
270  const typename other_nsize_type::const_iterator otherSizesBegin = otherNArray.sizes().begin();
271  typename other_nsize_type::const_iterator otherSizesIter;
272  const typename other_nstride_type::const_iterator otherStridesBegin = otherNArray.strides().begin();
273  typename other_nstride_type::const_iterator otherStridesIter;
274  const typename nsize_type::iterator sizesBegin = sizes.begin();
275  const typename nsize_type::iterator sizesEnd = sizes.end();
276  typename nsize_type::iterator sizesIter;
277  const typename nstride_type::iterator stridesBegin = strides.begin();
278  typename nstride_type::iterator stridesIter;
279 
280  // copy sizes and strides in every dimension except the one specified
281  otherSizesIter = otherSizesBegin;
282  otherStridesIter = otherStridesBegin;
283  sizesIter = sizesBegin;
284  stridesIter = stridesBegin;
285  i = 0;
286  while (sizesIter != sizesEnd) {
287  if (i == dimension) {
288  ++otherSizesIter;
289  ++otherStridesIter;
290  ++i;
291  } else {
292  *sizesIter = *otherSizesIter;
293  *stridesIter = *otherStridesIter;
294 
295  ++otherSizesIter;
296  ++otherStridesIter;
297  ++sizesIter;
298  ++stridesIter;
299  ++i;
300  }
301  }
302 
303  // set start position
304  other_nsize_type startPosition(static_cast<size_type>(0));
305  startPosition[dimension] = index;
306  this->SetRef(otherNArray.Pointer(startPosition), sizes, strides);
307  }
308 
312  template <class __ownerType>
314  {
315  this->SetRef( vector.Pointer(), nsize_type(vector.size()), nstride_type(vector.stride()) );
316  }
317 
321  template <size_type __size, stride_type __stride, typename __dataPtrType>
323  {
324  this->SetRef( vector.Pointer(), nsize_type(__size), nstride_type(__stride) );
325  }
326 
330  template <class __ownerType>
332  {
333  this->SetRef(matrix.Pointer(),
334  nsize_type(matrix.rows(), matrix.cols()),
335  nstride_type(matrix.row_stride(), matrix.col_stride()));
336  }
337 
341  template <size_type __rows, size_type __cols, stride_type __rowStride, stride_type __colStride, typename __dataPtrType>
343  {
344  this->SetRef(matrix.Pointer(),
345  nsize_type(__rows, __cols),
346  nstride_type(__rowStride, __colStride));
347  }
348 };
349 
350 
351 #endif // _vctDynamicConstNArrayRef_h
352 
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
vctDynamicConstNArrayRef(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray)
Definition: vctDynamicConstNArrayRef.h:140
const nsize_type & sizes(void) const
Definition: vctDynamicConstNArrayBase.h:308
NArrayOwnerType::const_reverse_iterator const_reverse_iterator
Definition: vctDynamicConstNArrayRef.h:105
void SetRef(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray)
Definition: vctDynamicConstNArrayRef.h:197
void SliceOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION+1 > &otherNArray, dimension_type dimension, size_type index)
Definition: vctDynamicConstNArrayRef.h:256
vctDynamicConstNArrayRef(const vctDynamicConstMatrixBase< __ownerType, value_type > &matrix)
Definition: vctDynamicConstNArrayRef.h:167
Definition: vctDynamicConstNArrayRef.h:94
const_pointer Pointer(void) const
Definition: vctDynamicConstNArrayBase.h:436
vctDynamicConstNArrayBase< vctDynamicNArrayRefOwner< _elementType, DIMENSION >, _elementType, DIMENSION > BaseType
Definition: vctDynamicConstNArrayRef.h:101
Definition: vctDynamicConstNArrayBase.h:155
vctDynamicConstNArrayRef(pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicConstNArrayRef.h:131
void SetRef(const vctFixedSizeConstVectorBase< __size, __stride, value_type, __dataPtrType > &vector)
Definition: vctDynamicConstNArrayRef.h:322
vctDynamicConstNArrayRef(const vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix)
Definition: vctDynamicConstNArrayRef.h:176
size_t size_type
Definition: vctContainerTraits.h:35
bool LesserOrEqual(const vctDynamicConstNArrayBase< __nArrayOwnerType, value_type, DIMENSION > &otherNArray) const
Definition: vctDynamicConstNArrayBase.h:816
vctDynamicConstNArrayRef(const_pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicConstNArrayRef.h:123
void SetRef(const vctFixedSizeConstMatrixBase< __rows, __cols, __rowStride, __colStride, value_type, __dataPtrType > &matrix)
Definition: vctDynamicConstNArrayRef.h:342
void SetRef(const_pointer dataPointer, const nsize_type &sizes, const nstride_type &strides)
Definition: vctDynamicConstNArrayRef.h:188
Dynamic nArray referencing existing memory (const)
Definition: vctDynamicConstNArrayRef.h:89
Definition: vctDynamicConstMatrixBase.h:77
Definition: vctDynamicNArrayRefOwner.h:36
NArrayOwnerType::const_iterator const_iterator
Definition: vctDynamicConstNArrayRef.h:103
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
Definition: vctForwardDeclarations.h:77
void SetRef(const vctDynamicConstVectorBase< __ownerType, value_type > &vector)
Definition: vctDynamicConstNArrayRef.h:313
size_type rows() const
Definition: vctDynamicConstMatrixBase.h:238
size_type cols() const
Definition: vctDynamicConstMatrixBase.h:243
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
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
vctDynamicConstNArrayRef< _elementType, DIMENSION > ThisType
Definition: vctDynamicConstNArrayRef.h:99
vctDynamicConstNArrayRef(const ThisType &other)
Definition: vctDynamicConstNArrayRef.h:114
void SetRef(const vctDynamicConstMatrixBase< __ownerType, value_type > &matrix)
Definition: vctDynamicConstNArrayRef.h:331
void PermutationOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray, const ndimension_type &dimensions)
Definition: vctDynamicConstNArrayRef.h:226
const_pointer Pointer(index_type index=0) const
Definition: vctDynamicConstVectorBase.h:221
void SubarrayOf(const vctDynamicConstNArrayBase< __ownerType, value_type, DIMENSION > &otherNArray, const nsize_type &startPosition, const nsize_type &lengths)
Definition: vctDynamicConstNArrayRef.h:210
NArrayOwnerType::iterator iterator
Definition: vctDynamicConstNArrayRef.h:102
vctDynamicConstNArrayRef()
Definition: vctDynamicConstNArrayRef.h:108
Definition: vctForwardDeclarations.h:74
size_type size(void) const
Definition: vctDynamicConstNArrayBase.h:302
Definition: vctDynamicConstVectorBase.h:77
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
VCT_NARRAY_TRAITS_TYPEDEFS(DIMENSION)
vctDynamicConstNArrayRef(const vctFixedSizeConstVectorBase< __size, __stride, value_type, __dataPtrType > &vector)
Definition: vctDynamicConstNArrayRef.h:158
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
vctDynamicNArrayRefOwner< _elementType, DIMENSION > NArrayOwnerType
Definition: vctDynamicConstNArrayRef.h:100
NArrayOwnerType::reverse_iterator reverse_iterator
Definition: vctDynamicConstNArrayRef.h:104
vctDynamicConstNArrayRef(const vctDynamicConstVectorBase< __ownerType, value_type > &vector)
Definition: vctDynamicConstNArrayRef.h:149
Declaration of vctDynamicConstNArrayBase.
Declaration of vctDynamicNArrayRefOwner.