cisst-saw
Loading...
Searching...
No Matches
vctFixedStrideVectorIterator.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: 2003-09-30
8
9 (C) Copyright 2003-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 _vctFixedStrideVectorIterator_h
22#define _vctFixedStrideVectorIterator_h
23
28
31
32#include <iterator>
33
60template <class _elementType, vct::stride_type _stride>
62{
63public:
64 /* define most types from vctContainerTraits */
66
69
72 typedef typename std::random_access_iterator_tag iterator_category;
73
74 /* Stride between the elements of a vector. */
75 enum {STRIDE = _stride};
76
77protected:
85
86public:
90
91
95 : DataPtr(dataPtr)
96 {}
97
98
108 : DataPtr(const_cast<value_type *>(dataPtr))
109 {}
110
111
114 DataPtr += STRIDE;
115 return *this;
116 }
117
118
121 ThisType tmp(*this);
122 ++(*this);
123 return tmp;
124 }
125
126
129 DataPtr -= STRIDE;
130 return *this;
131 }
132
133
136 ThisType tmp(*this);
137 --(*this);
138 return tmp;
139 }
140
141
143 ThisType & operator+=(difference_type difference) {
144 DataPtr += difference * STRIDE;
145 return *this;
146 }
147
148
150 ThisType & operator-=(difference_type difference) {
151 DataPtr -= difference * STRIDE;
152 return *this;
153 }
154
155
161 difference_type operator-(const ThisType & other) const {
162 return (DataPtr - other.DataPtr) / STRIDE;
163 }
164
165
167 const value_type & operator[](difference_type index) const {
168 return *(DataPtr + index * STRIDE);
169 }
170
171
173 const value_type & operator* () const {
174 return *DataPtr;
175 }
176
177
183 bool operator< (const ThisType & other) const {
184 return ((*this) - other) < 0;
185 }
186 bool operator<= (const ThisType & other) const {
187 return (*this < other) || (*this == other);
188 }
189
190
192 bool operator== (const ThisType & other) const {
193 return DataPtr == other.DataPtr;
194 }
195
196
198 bool operator> (const ThisType & other) const {
199 return other < (*this);
200 }
201 bool operator>= (const ThisType & other) const {
202 return (*this > other) || (*this == other);
203 }
204
205
207 bool operator != (const ThisType & other) const {
208 return !( (*this) == other );
209 }
210};
211
212
213
214
218template<class _elementType, vct::stride_type _stride>
220{
221public:
222 /* documented in base class */
227
232
233
239 : BaseType(dataPtr)
240 {}
241
242
246 this->DataPtr += this->STRIDE;
247 return *this;
248 }
249
250
254 ThisType tmp(*this);
255 this->DataPtr += this->STRIDE;
256 return tmp;
257 }
258
259
263 this->DataPtr -= this->STRIDE;
264 return *this;
265 }
266
267
271 ThisType tmp(*this);
272 this->DataPtr -= this->STRIDE;
273 return tmp;
274 }
275
276
279 ThisType & operator+=(difference_type difference) {
280 this->DataPtr += difference * this->STRIDE;
281 return *this;
282 }
283
284
287 ThisType & operator-=(difference_type difference) {
288 this->DataPtr -= difference * this->STRIDE;
289 return *this;
290 }
291
292
294 value_type & operator[](difference_type index) const {
295 return *(this->DataPtr + index * this->STRIDE);
296 }
297
298
301 return *(this->DataPtr);
302 }
303
305 return *(this->DataPtr);
306 }
307};
308
309
310
312template<class _elementType, vct::stride_type _stride>
320
321
323template<class _elementType, vct::stride_type _stride>
331
332
334template<class _elementType, vct::stride_type _stride>
342
343
348template<class _elementType, vct::stride_type _stride>
356
357
359template<class _elementType, vct::stride_type _stride>
367
368
370template<class _elementType, vct::stride_type _stride>
378
379
380#endif // _vctFixedStrideVectorIterator_h
Definition vctFixedStrideVectorIterator.h:62
bool operator==(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:192
bool operator<(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:183
const value_type & operator*() const
Definition vctFixedStrideVectorIterator.h:173
@ STRIDE
Definition vctFixedStrideVectorIterator.h:75
bool operator>(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:198
ThisType & operator+=(difference_type difference)
Definition vctFixedStrideVectorIterator.h:143
vctFixedStrideVectorConstIterator(value_type *dataPtr)
Definition vctFixedStrideVectorIterator.h:94
bool operator!=(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:207
ThisType & operator--()
Definition vctFixedStrideVectorIterator.h:128
value_type * DataPtr
Definition vctFixedStrideVectorIterator.h:84
bool operator>=(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:201
ThisType operator--(int)
Definition vctFixedStrideVectorIterator.h:135
bool operator<=(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:186
std::random_access_iterator_tag iterator_category
Definition vctFixedStrideVectorIterator.h:72
vctFixedStrideVectorConstIterator< value_type, _stride > ThisType
Definition vctFixedStrideVectorIterator.h:68
ThisType & operator-=(difference_type difference)
Definition vctFixedStrideVectorIterator.h:150
vctFixedStrideVectorConstIterator(const value_type *dataPtr)
Definition vctFixedStrideVectorIterator.h:107
difference_type operator-(const ThisType &other) const
Definition vctFixedStrideVectorIterator.h:161
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
ThisType & operator++()
Definition vctFixedStrideVectorIterator.h:113
const value_type & operator[](difference_type index) const
Definition vctFixedStrideVectorIterator.h:167
ThisType operator++(int)
Definition vctFixedStrideVectorIterator.h:120
vctFixedStrideVectorConstIterator()
Definition vctFixedStrideVectorIterator.h:88
Definition vctFixedStrideVectorIterator.h:220
ThisType operator--(int)
Definition vctFixedStrideVectorIterator.h:270
vctFixedStrideVectorIterator(value_type *dataPtr)
Definition vctFixedStrideVectorIterator.h:238
vctFixedStrideVectorIterator< value_type, _stride > ThisType
Definition vctFixedStrideVectorIterator.h:224
BaseType::iterator_category iterator_category
Definition vctFixedStrideVectorIterator.h:226
ThisType operator++(int)
Definition vctFixedStrideVectorIterator.h:253
vctFixedStrideVectorConstIterator< value_type, _stride > BaseType
Definition vctFixedStrideVectorIterator.h:225
ThisType & operator-=(difference_type difference)
Definition vctFixedStrideVectorIterator.h:287
vctFixedStrideVectorIterator()
Definition vctFixedStrideVectorIterator.h:229
value_type & operator[](difference_type index) const
Definition vctFixedStrideVectorIterator.h:294
ThisType & operator--()
Definition vctFixedStrideVectorIterator.h:262
value_type & operator*()
Definition vctFixedStrideVectorIterator.h:300
VCT_CONTAINER_TRAITS_TYPEDEFS(_elementType)
ThisType & operator+=(difference_type difference)
Definition vctFixedStrideVectorIterator.h:279
ThisType & operator++()
Definition vctFixedStrideVectorIterator.h:245
Portability across compilers and operating systems tools.
Basic traits for the cisstVector containers.
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
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