cisst-saw
Loading...
Searching...
No Matches
vctVarStrideVectorIterator.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): Ofri Sadowsky, Anton Deguet
7 Created on: 2004-07-02
8
9 (C) Copyright 2004-2025 Johns Hopkins University (JHU), All Rights Reserved.
10
11--- begin cisst license - do not edit ---
12
13This software is provided "as is" under an open source license, with
14no warranty. The complete license can be found in license.txt and
15http://www.cisst.org/cisst/license.txt.
16
17--- end cisst license ---
18*/
19
20#pragma once
21#ifndef _vctVarStrideVectorIterator_h
22#define _vctVarStrideVectorIterator_h
23
28
29#include <iterator>
31
32
54template<class _elementType>
56{
57public:
58 /* define most types from vctContainerTraits */
60
63
66 typedef typename std::random_access_iterator_tag iterator_category;
67
68protected:
76
77 /* Stride between the elements of a vector. */
78 difference_type Stride;
79
80
81
82public:
88
89
92 explicit vctVarStrideVectorConstIterator(value_type * dataPtr, difference_type stride = 1)
93 : DataPtr(dataPtr), Stride(stride)
94 {}
95
96
105 explicit vctVarStrideVectorConstIterator(const value_type * dataPtr, difference_type stride = 1)
106 : DataPtr(const_cast<value_type *>(dataPtr)), Stride(stride)
107 {}
108
109
112 DataPtr += Stride;
113 return *this;
114 }
115
116
119 ThisType tmp(*this);
120 ++(*this);
121 return tmp;
122 }
123
124
127 DataPtr -= Stride;
128 return *this;
129 }
130
131
134 ThisType tmp(*this);
135 --(*this);
136 return tmp;
137 }
138
139
141 ThisType & operator+=(difference_type difference) {
142 DataPtr += difference * Stride;
143 return *this;
144 }
145
146
148 ThisType & operator-=(difference_type difference) {
149 DataPtr -= difference * Stride;
150 return *this;
151 }
152
153
159 difference_type operator-(const ThisType & other) const {
160 return (DataPtr - other.DataPtr) / Stride;
161 }
162
163
165 const value_type & operator[](difference_type index) const {
166 return *(DataPtr + index * Stride);
167 }
168
169
171 const value_type & operator* () const {
172 return *DataPtr;
173 }
174
175
181 bool operator< (const ThisType & other) const {
182 return ((*this) - other) < 0;
183 }
184 bool operator<= (const ThisType & other) const {
185 return ((*this) < other) || ((*this) == other);
186 }
187
188
190 bool operator== (const ThisType & other) const {
191 return DataPtr == other.DataPtr;
192 }
193
194
196 bool operator> (const ThisType & other) const {
197 return other < (*this);
198 }
199 bool operator>= (const ThisType & other) const {
200 return ((*this) > other) || ((*this) == other);
201 }
202
203
205 bool operator != (const ThisType & other) const {
206 return !( (*this) == other );
207 }
208};
209
210
211
212
216template<class _elementType>
218{
219public:
220 /* documented in base class */
225
230
231
236 explicit vctVarStrideVectorIterator(value_type * dataPtr, difference_type stride = 1)
237 : BaseType(dataPtr, stride)
238 {}
239
240
244 this->DataPtr += this->Stride;
245 return *this;
246 }
247
248
252 ThisType tmp(*this);
253 this->DataPtr += this->Stride;
254 return tmp;
255 }
256
257
261 this->DataPtr -= this->Stride;
262 return *this;
263 }
264
265
269 ThisType tmp(*this);
270 this->DataPtr -= this->Stride;
271 return tmp;
272 }
273
274
277 ThisType & operator+=(difference_type difference) {
278 this->DataPtr += difference * this->Stride;
279 return *this;
280 }
281
282
285 ThisType & operator-=(difference_type difference) {
286 this->DataPtr -= difference * this->Stride;
287 return *this;
288 }
289
290
292 value_type & operator[](difference_type index) const {
293 return *(this->DataPtr + index * this->Stride);
294 }
295
296
299 return *(this->DataPtr);
300 }
301};
302
303
304
306template<class _elementType>
315
316
318template<class _elementType>
326
327
329template<class _elementType>
337
338
343template<class _elementType>
351
352
354template<class _elementType>
362
363
365template<class _elementType>
373
374
375#endif // _vctVarStrideVectorIterator_h
376
Definition vctVarStrideVectorIterator.h:56
ThisType & operator-=(difference_type difference)
Definition vctVarStrideVectorIterator.h:148
value_type * DataPtr
Definition vctVarStrideVectorIterator.h:75
difference_type Stride
Definition vctVarStrideVectorIterator.h:78
bool operator<(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:181
ThisType operator++(int)
Definition vctVarStrideVectorIterator.h:118
const value_type & operator*() const
Definition vctVarStrideVectorIterator.h:171
difference_type operator-(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:159
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
bool operator==(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:190
ThisType & operator+=(difference_type difference)
Definition vctVarStrideVectorIterator.h:141
ThisType & operator++()
Definition vctVarStrideVectorIterator.h:111
ThisType operator--(int)
Definition vctVarStrideVectorIterator.h:133
vctVarStrideVectorConstIterator(const value_type *dataPtr, difference_type stride=1)
Definition vctVarStrideVectorIterator.h:105
ThisType & operator--()
Definition vctVarStrideVectorIterator.h:126
std::random_access_iterator_tag iterator_category
Definition vctVarStrideVectorIterator.h:66
bool operator>(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:196
bool operator>=(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:199
bool operator!=(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:205
bool operator<=(const ThisType &other) const
Definition vctVarStrideVectorIterator.h:184
vctVarStrideVectorConstIterator(value_type *dataPtr, difference_type stride=1)
Definition vctVarStrideVectorIterator.h:92
const value_type & operator[](difference_type index) const
Definition vctVarStrideVectorIterator.h:165
vctVarStrideVectorConstIterator()
Definition vctVarStrideVectorIterator.h:84
vctVarStrideVectorConstIterator< value_type > ThisType
Definition vctVarStrideVectorIterator.h:62
Definition vctVarStrideVectorIterator.h:218
ThisType operator++(int)
Definition vctVarStrideVectorIterator.h:251
ThisType & operator--()
Definition vctVarStrideVectorIterator.h:260
BaseType::iterator_category iterator_category
Definition vctVarStrideVectorIterator.h:224
ThisType operator--(int)
Definition vctVarStrideVectorIterator.h:268
vctVarStrideVectorConstIterator< value_type > BaseType
Definition vctVarStrideVectorIterator.h:223
ThisType & operator++()
Definition vctVarStrideVectorIterator.h:243
vctVarStrideVectorIterator< value_type > ThisType
Definition vctVarStrideVectorIterator.h:222
ThisType & operator+=(difference_type difference)
Definition vctVarStrideVectorIterator.h:277
ThisType & operator-=(difference_type difference)
Definition vctVarStrideVectorIterator.h:285
value_type & operator[](difference_type index) const
Definition vctVarStrideVectorIterator.h:292
value_type & operator*() const
Definition vctVarStrideVectorIterator.h:298
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
vctVarStrideVectorIterator(value_type *dataPtr, difference_type stride=1)
Definition vctVarStrideVectorIterator.h:236
vctVarStrideVectorIterator()
Definition vctVarStrideVectorIterator.h:227
Basic traits for the cisstVector containers.
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
difference_type stride(dimension_type dimension) const
Definition vctDynamicConstNArrayBase.h:325
vctReturnDynamicMatrix< _elementType > operator-(const vctDynamicConstMatrixBase< _matrixOwnerType1, _elementType > &inputMatrix1, const vctDynamicConstMatrixBase< _matrixOwnerType2, _elementType > &inputMatrix2)
Definition vctDynamicMatrix.h:487
vctReturnDynamicMatrix< _elementType > operator+(const vctDynamicConstMatrixBase< _matrixOwnerType1, _elementType > &inputMatrix1, const vctDynamicConstMatrixBase< _matrixOwnerType2, _elementType > &inputMatrix2)
Definition vctDynamicMatrix.h:476