cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vctDynamicVectorRef.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  Author(s): Ofri Sadowsky, Anton Deguet
6  Created on: 2004-07-01
7 
8  (C) Copyright 2004-2015 Johns Hopkins University (JHU), All Rights Reserved.
9 
10 --- begin cisst license - do not edit ---
11 
12 This software is provided "as is" under an open source license, with
13 no warranty. The complete license can be found in license.txt and
14 http://www.cisst.org/cisst/license.txt.
15 
16 --- end cisst license ---
17 */
18 
19 #pragma once
20 #ifndef _vctDynamicVectorRef_h
21 #define _vctDynamicVectorRef_h
22 
29 
33 
76 template <class _elementType>
77 class vctDynamicVectorRef: public vctDynamicVectorBase<vctDynamicVectorRefOwner<_elementType>, _elementType>
78 {
79 public:
80  VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType);
84  typedef typename BaseType::CopyType CopyType;
89 
92  {}
93 
101  BaseType()
102  {
103  this->SetRef(other.size(), const_cast<pointer>(other.Pointer()), other.stride());
104  }
105 
107  {
108  this->SetRef(size, data, stride);
109  }
110 
116  template <size_type __size, stride_type __stride, class __dataPtrType>
118  size_type startPosition = 0)
119  {
120  this->SetRef(otherVector, startPosition);
121  }
122 
129  template <size_type __size, stride_type __stride, class __dataPtrType>
131  size_type startPosition, size_type length)
132  {
133  this->SetRef(otherVector, startPosition, length);
134  }
135 
139  template <class __vectorOwnerType>
141  {
142  this->SetRef(otherVector);
143  }
144 
149  template <class __vectorOwnerType>
151  size_type startPosition, size_type length)
152  {
153  this->SetRef(otherVector, startPosition, length);
154  }
155 
156  void SetRef(size_type size, pointer data, stride_type stride = 1)
157  {
158  this->Vector.SetRef(size, data, stride);
159  }
160 
170  template <size_type __size, stride_type __stride, class __dataPtrType>
172  size_type startPosition = 0)
173  {
174  SetRef(otherVector.size() - startPosition, otherVector.Pointer(startPosition),
175  otherVector.stride());
176  }
177 
184  template <size_type __size, stride_type __stride, class __dataPtrType>
186  size_type startPosition, size_type length) throw(std::out_of_range)
187  {
188  if (startPosition + length > otherVector.size()) {
189  cmnThrow(std::out_of_range("vctDynamicVectorRef SetRef out of range"));
190  }
191  SetRef(length, otherVector.Pointer(startPosition), otherVector.stride());
192  }
193 
198  template <class __vectorOwnerType>
200  {
201  SetRef(otherVector.size(), otherVector.Pointer(), otherVector.stride());
202  }
203 
210  template <class __vectorOwnerType>
212  size_type startPosition, size_type length) throw(std::out_of_range)
213  {
214  if (startPosition + length > otherVector.size()) {
215  cmnThrow(std::out_of_range("vctDynamicVectorRef SetRef out of range"));
216  }
217  SetRef(length, otherVector.Pointer(startPosition), otherVector.stride());
218  }
219 
229 
230 #ifndef _cisstVectorPython_EXPORTS
231  /* Equivalent to Assign. Please note that this operator performs a data
232  copy, not an object copy as understood with a C++ copy constructor. If
233  the size of operands don't match an exception will be thrown. */
234  inline ThisType & operator = (const ThisType & other) {
235  return reinterpret_cast<ThisType &>(this->Assign(other));
236  }
237 #endif // _cisstVectorPython_EXPORTS
238 
240  return reinterpret_cast<ThisType &>(this->Assign(other));
241  }
242 
243  template <class __vectorOwnerType, typename __elementType>
245  return reinterpret_cast<ThisType &>(this->Assign(other));
246  }
247 
248  template <size_type __size, stride_type __stride, class __elementType, class __dataPtrType>
249  inline ThisType & operator =
251  return reinterpret_cast<ThisType &>(this->Assign(other));
252  }
254 
256  inline ThisType & operator = (const value_type & value) {
257  this->SetAll(value);
258  return *this;
259  }
260 
264  void DeSerializeRaw(std::istream & inputStream) throw(std::runtime_error)
265  {
266  // get and set size
267  size_type mySize;
268  cmnDeSerializeRaw(inputStream, mySize);
269 
270  if (mySize != this->size()) {
271  cmnThrow(std::runtime_error("vctDynamicVectorRef::DeSerializeRaw: Sizes of vectors don't match"));
272  }
273 
274  // get data
275  size_type index;
276  for (index = 0; index < mySize; ++index) {
277  cmnDeSerializeRaw(inputStream, this->Element(index));
278  }
279  }
280 
281 };
282 
283 #endif // _vctDynamicVectorRef_h
void SetRef(size_type size, value_type *data, stride_type stride=1)
Definition: vctDynamicVectorRefOwner.h:67
void SetRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length)
Definition: vctDynamicVectorRef.h:211
A vector object of dynamic size.
Definition: vctDynamicVector.h:127
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
Dynamic vector referencing existing memory (const)
Definition: vctDynamicConstVectorRef.h:79
vctVarStrideVectorIterator< value_type > reverse_iterator
Definition: vctDynamicVectorRefOwner.h:52
VectorOwnerType::const_reverse_iterator const_reverse_iterator
Definition: vctDynamicVectorRef.h:88
ThisType & Assign(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &other)
Definition: vctDynamicVectorBase.h:242
vctDynamicVectorRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector)
Definition: vctDynamicVectorRef.h:140
Dynamic vector referencing existing memory.
Definition: vctDynamicVectorRef.h:77
vctDynamicVectorRef(const ThisType &other)
Definition: vctDynamicVectorRef.h:100
size_t size_type
Definition: vctContainerTraits.h:35
vctVarStrideVectorConstIterator< value_type > const_iterator
Definition: vctDynamicVectorRefOwner.h:49
Declaration of vctDynamicConstVectorRef.
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition: vctDynamicVectorRef.h:156
vctDynamicVectorBase< vctDynamicVectorRefOwner< _elementType >, _elementType > BaseType
Definition: vctDynamicVectorRef.h:83
ThisType & operator=(const ThisType &other)
Definition: vctDynamicVectorRef.h:234
vctDynamicVectorRef< _elementType > ThisType
Definition: vctDynamicVectorRef.h:81
VectorOwnerType::reverse_iterator reverse_iterator
Definition: vctDynamicVectorRef.h:87
vctDynamicVectorRef(size_type size, value_type *data, stride_type stride=1)
Definition: vctDynamicVectorRef.h:106
size_type size(void) const
Definition: vctDynamicConstVectorBase.h:164
BaseType::CopyType CopyType
Definition: vctDynamicVectorRef.h:84
difference_type stride(void) const
Definition: vctFixedSizeConstVectorBase.h:218
reference Element(index_type index)
Definition: vctDynamicVectorBase.h:195
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:82
size_type size(void) const
Definition: vctFixedSizeConstVectorBase.h:205
vctVarStrideVectorIterator< value_type > iterator
Definition: vctDynamicVectorRefOwner.h:50
difference_type stride() const
Definition: vctDynamicConstVectorBase.h:169
vctDynamicVectorRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length)
Definition: vctDynamicVectorRef.h:130
void SetRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector)
Definition: vctDynamicVectorRef.h:199
#define cmnThrow(a)
Definition: MinimalCmn.h:4
Declaration of vctDynamicVectorBase.
const_pointer Pointer(index_type index=0) const
Definition: vctDynamicConstVectorBase.h:221
vctDynamicVectorRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length)
Definition: vctDynamicVectorRef.h:150
pointer Pointer(index_type index=0)
Definition: vctDynamicVectorBase.h:155
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeVectorBase.h:76
Definition: vctDynamicVectorRefOwner.h:39
value_type SetAll(const value_type value)
Definition: vctDynamicVectorBase.h:209
ptrdiff_t stride_type
Definition: vctContainerTraits.h:37
VectorOwnerType::const_iterator const_iterator
Definition: vctDynamicVectorRef.h:86
void SetRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length)
Definition: vctDynamicVectorRef.h:185
vctDynamicVectorRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition: vctDynamicVectorRef.h:117
Definition: vctDynamicConstVectorBase.h:77
void DeSerializeRaw(std::istream &inputStream)
Definition: vctDynamicVectorRef.h:264
A template for a fixed length vector with fixed spacing in memory.
Definition: vctFixedSizeConstVectorBase.h:107
pointer Pointer(size_type index=0)
Definition: vctFixedSizeVectorBase.h:226
Declaration of cmnDeSerializer and functions cmnDeSerializeRaw.
vctDynamicVectorRef()
Definition: vctDynamicVectorRef.h:91
void SetRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition: vctDynamicVectorRef.h:171
vctVarStrideVectorConstIterator< value_type > const_reverse_iterator
Definition: vctDynamicVectorRefOwner.h:51
Declaration of vctDynamicVectorRefOwner.
Definition: vctDynamicVectorBase.h:61
vctDynamicVectorRefOwner< _elementType > VectorOwnerType
Definition: vctDynamicVectorRef.h:82
VectorOwnerType::iterator iterator
Definition: vctDynamicVectorRef.h:85