VTK  9.3.0
vtkTypedDataArrayIterator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
24#ifndef vtkTypedDataArrayIterator_h
25#define vtkTypedDataArrayIterator_h
26
27#include <iterator> // For iterator traits
28
29#include "vtkTypedDataArray.h" // For vtkTypedDataArray
30
31VTK_ABI_NAMESPACE_BEGIN
32template <class Scalar>
34{
35public:
36 typedef std::random_access_iterator_tag iterator_category;
37 typedef Scalar value_type;
38 typedef std::ptrdiff_t difference_type;
39 typedef Scalar& reference;
40 typedef Scalar* pointer;
41
43 : Data(nullptr)
44 , Index(0)
45 {
46 }
47
49 : Data(arr)
50 , Index(index)
51 {
52 }
53
55 : Data(o.Data)
56 , Index(o.Index)
57 {
58 }
59
61 {
62 std::swap(this->Data, o.Data);
63 std::swap(this->Index, o.Index);
64 return *this;
65 }
66
68 {
69 return this->Data == o.Data && this->Index == o.Index;
70 }
71
73 {
74 return this->Data == o.Data && this->Index != o.Index;
75 }
76
78 {
79 return this->Data == o.Data && this->Index > o.Index;
80 }
81
83 {
84 return this->Data == o.Data && this->Index >= o.Index;
85 }
86
88 {
89 return this->Data == o.Data && this->Index < o.Index;
90 }
91
93 {
94 return this->Data == o.Data && this->Index <= o.Index;
95 }
96
97 Scalar& operator*() { return this->Data->GetValueReference(this->Index); }
98
99 Scalar* operator->() const { return &this->Data->GetValueReference(this->Index); }
100
101 Scalar& operator[](const difference_type& n)
102 {
103 return this->Data->GetValueReference(this->Index + n);
104 }
105
107 {
108 ++this->Index;
109 return *this;
110 }
111
113 {
114 --this->Index;
115 return *this;
116 }
117
119 {
120 return vtkTypedDataArrayIterator(this->Data, this->Index++);
121 }
122
124 {
125 return vtkTypedDataArrayIterator(this->Data, this->Index--);
126 }
127
129 {
130 return vtkTypedDataArrayIterator(this->Data, this->Index + n);
131 }
132
134 {
135 return vtkTypedDataArrayIterator(this->Data, this->Index - n);
136 }
137
139 {
140 return this->Index - other.Index;
141 }
142
144 {
145 this->Index += n;
146 return *this;
147 }
148
150 {
151 this->Index -= n;
152 return *this;
153 }
154
155private:
157 vtkIdType Index;
158};
159
160VTK_ABI_NAMESPACE_END
161#endif // vtkTypedDataArrayIterator_h
162
163// VTK-HeaderTest-Exclude: vtkTypedDataArrayIterator.h
STL-style random access iterator for vtkTypedDataArrays.
bool operator>=(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator & operator--()
vtkTypedDataArrayIterator & operator+=(const difference_type &n)
vtkTypedDataArrayIterator & operator-=(const difference_type &n)
vtkTypedDataArrayIterator operator++(int)
vtkTypedDataArrayIterator(vtkTypedDataArray< Scalar > *arr, const vtkIdType index=0)
vtkTypedDataArrayIterator operator+(const difference_type &n) const
vtkTypedDataArrayIterator operator--(int)
bool operator!=(const vtkTypedDataArrayIterator< Scalar > &o) const
Scalar & operator[](const difference_type &n)
vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
bool operator==(const vtkTypedDataArrayIterator< Scalar > &o) const
bool operator<=(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator operator-(const difference_type &n) const
bool operator<(const vtkTypedDataArrayIterator< Scalar > &o) const
difference_type operator-(const vtkTypedDataArrayIterator &other) const
bool operator>(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator & operator++()
vtkTypedDataArrayIterator & operator=(vtkTypedDataArrayIterator< Scalar > o)
std::random_access_iterator_tag iterator_category
Extend vtkDataArray with abstract type-specific API.
int vtkIdType
Definition vtkType.h:315