VTK: Common/Core/vtkTypedDataArrayIterator.h Source File

| VTK 9.3.1

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
31 VTK_ABI_NAMESPACE_BEGIN
32 template <class Scalar>
33 class vtkTypedDataArrayIterator
34 {
35 public:
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
42 vtkTypedDataArrayIterator()
43 : Data(nullptr)
44 , Index(0)
45 {
46 }
47
48 explicit vtkTypedDataArrayIterator(vtkTypedDataArray<Scalar>* arr, const vtkIdType index = 0)
49 : Data(arr)
50 , Index(index)
51 {
52 }
53
54 vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator& o)
55 : Data(o.Data)
56 , Index(o.Index)
57 {
58 }
59
60 vtkTypedDataArrayIterator& operator=(vtkTypedDataArrayIterator<Scalar> o)
61 {
62 std::swap(this->Data, o.Data);
63 std::swap(this->Index, o.Index);
64 return *this;
65 }
66
67 bool operator==(const vtkTypedDataArrayIterator<Scalar>& o) const
68 {
69 return this->Data == o.Data && this->Index == o.Index;
70 }
71
72 bool operator!=(const vtkTypedDataArrayIterator<Scalar>& o) const
73 {
74 return this->Data == o.Data && this->Index != o.Index;
75 }
76
77 bool operator>(const vtkTypedDataArrayIterator<Scalar>& o) const
78 {
79 return this->Data == o.Data && this->Index > o.Index;
80 }
81
82 bool operator>=(const vtkTypedDataArrayIterator<Scalar>& o) const
83 {
84 return this->Data == o.Data && this->Index >= o.Index;
85 }
86
87 bool operator<(const vtkTypedDataArrayIterator<Scalar>& o) const
88 {
89 return this->Data == o.Data && this->Index < o.Index;
90 }
91
92 bool operator<=(const vtkTypedDataArrayIterator<Scalar>& o) const
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
106 vtkTypedDataArrayIterator& operator++()
107 {
108 ++this->Index;
109 return *this;
110 }
111
112 vtkTypedDataArrayIterator& operator--()
113 {
114 --this->Index;
115 return *this;
116 }
117
118 vtkTypedDataArrayIterator operator++(int)
119 {
120 return vtkTypedDataArrayIterator(this->Data, this->Index++);
121 }
122
123 vtkTypedDataArrayIterator operator--(int)
124 {
125 return vtkTypedDataArrayIterator(this->Data, this->Index--);
126 }
127
128 vtkTypedDataArrayIterator operator+(const difference_type& n) const
129 {
130 return vtkTypedDataArrayIterator(this->Data, this->Index + n);
131 }
132
133 vtkTypedDataArrayIterator operator-(const difference_type& n) const
134 {
135 return vtkTypedDataArrayIterator(this->Data, this->Index - n);
136 }
137
138 difference_type operator-(const vtkTypedDataArrayIterator& other) const
139 {
140 return this->Index - other.Index;
141 }
142
143 vtkTypedDataArrayIterator& operator+=(const difference_type& n)
144 {
145 this->Index += n;
146 return *this;
147 }
148
149 vtkTypedDataArrayIterator& operator-=(const difference_type& n)
150 {
151 this->Index -= n;
152 return *this;
153 }
154
155 private:
156 vtkTypedDataArray<Scalar>* Data;
157 vtkIdType Index;
158 };
159
160 VTK_ABI_NAMESPACE_END
161 #endif // vtkTypedDataArrayIterator_h
162
163 // VTK-HeaderTest-Exclude: vtkTypedDataArrayIterator.h
vtkTypedDataArrayIterator
STL-style random access iterator for vtkTypedDataArrays.
Definition: vtkTypedDataArrayIterator.h:34
vtkTypedDataArrayIterator::operator>=
bool operator>=(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:82
vtkTypedDataArrayIterator::operator++
vtkTypedDataArrayIterator operator++(int)
Definition: vtkTypedDataArrayIterator.h:118
vtkTypedDataArrayIterator::reference
Scalar & reference
Definition: vtkTypedDataArrayIterator.h:39
vtkTypedDataArrayIterator::vtkTypedDataArrayIterator
vtkTypedDataArrayIterator(vtkTypedDataArray< Scalar > *arr, const vtkIdType index=0)
Definition: vtkTypedDataArrayIterator.h:48
vtkTypedDataArrayIterator::operator+
vtkTypedDataArrayIterator operator+(const difference_type &n) const
Definition: vtkTypedDataArrayIterator.h:128
vtkTypedDataArrayIterator::operator--
vtkTypedDataArrayIterator operator--(int)
Definition: vtkTypedDataArrayIterator.h:123
vtkTypedDataArrayIterator::operator-=
vtkTypedDataArrayIterator & operator-=(const difference_type &n)
Definition: vtkTypedDataArrayIterator.h:149
vtkTypedDataArrayIterator::operator!=
bool operator!=(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:72
vtkTypedDataArrayIterator::operator->
Scalar * operator->() const
Definition: vtkTypedDataArrayIterator.h:99
vtkTypedDataArrayIterator::operator=
vtkTypedDataArrayIterator & operator=(vtkTypedDataArrayIterator< Scalar > o)
Definition: vtkTypedDataArrayIterator.h:60
vtkTypedDataArrayIterator::value_type
Scalar value_type
Definition: vtkTypedDataArrayIterator.h:37
vtkTypedDataArrayIterator::vtkTypedDataArrayIterator
vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
Definition: vtkTypedDataArrayIterator.h:54
vtkTypedDataArrayIterator::operator[]
Scalar & operator[](const difference_type &n)
Definition: vtkTypedDataArrayIterator.h:101
vtkTypedDataArrayIterator::operator==
bool operator==(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:67
vtkTypedDataArrayIterator::vtkTypedDataArrayIterator
vtkTypedDataArrayIterator()
Definition: vtkTypedDataArrayIterator.h:42
vtkTypedDataArrayIterator::operator<=
bool operator<=(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:92
vtkTypedDataArrayIterator::pointer
Scalar * pointer
Definition: vtkTypedDataArrayIterator.h:40
vtkTypedDataArrayIterator::operator-
vtkTypedDataArrayIterator operator-(const difference_type &n) const
Definition: vtkTypedDataArrayIterator.h:133
vtkTypedDataArrayIterator::operator<
bool operator<(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:87
vtkTypedDataArrayIterator::operator-
difference_type operator-(const vtkTypedDataArrayIterator &other) const
Definition: vtkTypedDataArrayIterator.h:138
vtkTypedDataArrayIterator::operator>
bool operator>(const vtkTypedDataArrayIterator< Scalar > &o) const
Definition: vtkTypedDataArrayIterator.h:77
vtkTypedDataArrayIterator::operator++
vtkTypedDataArrayIterator & operator++()
Definition: vtkTypedDataArrayIterator.h:106
vtkTypedDataArrayIterator::difference_type
std::ptrdiff_t difference_type
Definition: vtkTypedDataArrayIterator.h:38
vtkTypedDataArrayIterator::operator--
vtkTypedDataArrayIterator & operator--()
Definition: vtkTypedDataArrayIterator.h:112
vtkTypedDataArrayIterator::operator+=
vtkTypedDataArrayIterator & operator+=(const difference_type &n)
Definition: vtkTypedDataArrayIterator.h:143
vtkTypedDataArrayIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: vtkTypedDataArrayIterator.h:36
vtkTypedDataArrayIterator::operator*
Scalar & operator*()
Definition: vtkTypedDataArrayIterator.h:97
vtkTypedDataArray
Extend vtkDataArray with abstract type-specific API.
Definition: vtkTypedDataArray.h:41
vtkX3D::index
@ index
Definition: vtkX3D.h:246
vtkIdType
int vtkIdType
Definition: vtkType.h:315
vtkTypedDataArray.h