cisst-saw
Loading...
Searching...
No Matches
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-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://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
27
29
33
76template <class _elementType>
77class vctDynamicVectorRef: public vctDynamicVectorBase<vctDynamicVectorRefOwner<_elementType>, _elementType>
78{
79public:
84 typedef typename BaseType::CopyType CopyType;
89
93
101 BaseType()
102 {
103 this->SetRef(other.size(), const_cast<pointer>(other.Pointer()), other.stride());
104 }
105
106 vctDynamicVectorRef(size_type size, value_type* data, stride_type stride = 1)
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) CISST_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) CISST_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 }
253
254
256 inline ThisType & operator = (const value_type & value) {
257 this->SetAll(value);
258 return *this;
259 }
260
264 void DeSerializeRaw(std::istream & inputStream) CISST_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
Definition vctForwardDeclarations.h:119
Dynamic vector referencing existing memory (const).
Definition vctDynamicConstVectorRef.h:79
Definition vctDynamicVectorBase.h:62
pointer Pointer(index_type index=0)
Definition vctDynamicVectorBase.h:155
value_type SetAll(const value_type value)
Definition vctDynamicVectorBase.h:209
BaseType::CopyType CopyType
Definition vctDynamicVectorBase.h:79
reference Element(index_type index)
Definition vctDynamicVectorBase.h:195
ThisType & Assign(const vctDynamicConstVectorBase< __vectorOwnerType, value_type > &other)
Definition vctDynamicVectorBase.h:242
void SetRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length) CISST_THROW(std
Definition vctDynamicVectorRef.h:211
vctDynamicVectorRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition vctDynamicVectorRef.h:117
VectorOwnerType::const_iterator const_iterator
Definition vctDynamicVectorRef.h:86
vctDynamicVectorRef(size_type size, value_type *data, stride_type stride=1)
Definition vctDynamicVectorRef.h:106
vctDynamicVectorRefOwner< value_type > VectorOwnerType
Definition vctDynamicVectorRef.h:82
BaseType::CopyType CopyType
Definition vctDynamicVectorRef.h:84
vctDynamicVectorRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector)
Definition vctDynamicVectorRef.h:140
ThisType & operator=(const ThisType &other)
Definition vctDynamicVectorRef.h:234
VectorOwnerType::reverse_iterator reverse_iterator
Definition vctDynamicVectorRef.h:87
VectorOwnerType::iterator iterator
Definition vctDynamicVectorRef.h:85
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctDynamicVectorRef()
Definition vctDynamicVectorRef.h:91
VectorOwnerType::const_reverse_iterator const_reverse_iterator
Definition vctDynamicVectorRef.h:88
vctDynamicVectorRef(const ThisType &other)
Definition vctDynamicVectorRef.h:100
vctDynamicVectorRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector, size_type startPosition, size_type length)
Definition vctDynamicVectorRef.h:150
void DeSerializeRaw(std::istream &inputStream) CISST_THROW(std
Definition vctDynamicVectorRef.h:264
void SetRef(size_type size, pointer data, stride_type stride=1)
Definition vctDynamicVectorRef.h:156
vctDynamicVectorBase< vctDynamicVectorRefOwner< value_type >, value_type > BaseType
Definition vctDynamicVectorRef.h:83
vctDynamicVectorRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length)
Definition vctDynamicVectorRef.h:130
vctDynamicVectorRef< value_type > ThisType
Definition vctDynamicVectorRef.h:81
void SetRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition=0)
Definition vctDynamicVectorRef.h:171
void SetRef(vctDynamicVectorBase< __vectorOwnerType, _elementType > &otherVector)
Definition vctDynamicVectorRef.h:199
void SetRef(vctFixedSizeVectorBase< __size, __stride, _elementType, __dataPtrType > &otherVector, size_type startPosition, size_type length) CISST_THROW(std
Definition vctDynamicVectorRef.h:185
Definition vctDynamicVectorRefOwner.h:40
vctVarStrideVectorIterator< value_type > reverse_iterator
Definition vctDynamicVectorRefOwner.h:52
vctVarStrideVectorConstIterator< value_type > const_iterator
Definition vctDynamicVectorRefOwner.h:49
vctVarStrideVectorConstIterator< value_type > const_reverse_iterator
Definition vctDynamicVectorRefOwner.h:51
vctVarStrideVectorIterator< value_type > iterator
Definition vctDynamicVectorRefOwner.h:50
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeConstVectorBase.h:108
difference_type stride(void) const
Definition vctFixedSizeConstVectorBase.h:218
size_type size(void) const
Definition vctFixedSizeConstVectorBase.h:205
A template for a fixed length vector with fixed spacing in memory.
Definition vctFixedSizeVectorBase.h:77
pointer Pointer(size_type index=0)
Definition vctFixedSizeVectorBase.h:226
Declaration of cmnDeSerializer and functions cmnDeSerializeRaw.
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:82
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
size_type size(void) const
Definition vctDynamicConstMatrixBase.h:228
difference_type stride(dimension_type dimension) const
Definition vctDynamicConstNArrayBase.h:325
OwnerType Vector
Definition vctDynamicConstVectorBase.h:126
Declaration of vctDynamicConstVectorRef.
Declaration of vctDynamicVectorBase.
Declaration of vctDynamicVectorRefOwner.