VTK  9.3.20240419
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>
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 
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 
155 private:
157  vtkIdType Index;
158 };
159 
160 VTK_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++(int)
vtkTypedDataArrayIterator(vtkTypedDataArray< Scalar > *arr, const vtkIdType index=0)
vtkTypedDataArrayIterator operator+(const difference_type &n) const
vtkTypedDataArrayIterator operator--(int)
vtkTypedDataArrayIterator & operator-=(const difference_type &n)
bool operator!=(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator & operator=(vtkTypedDataArrayIterator< Scalar > o)
vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
Scalar & operator[](const difference_type &n)
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 & operator+=(const difference_type &n)
std::random_access_iterator_tag iterator_category
Extend vtkDataArray with abstract type-specific API.
@ index
Definition: vtkX3D.h:246
int vtkIdType
Definition: vtkType.h:315