VTK  9.0.1
vtkTypedDataArrayIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTypedDataArrayIterator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
33 #ifndef vtkTypedDataArrayIterator_h
34 #define vtkTypedDataArrayIterator_h
35 
36 #include <iterator> // For iterator traits
37 
38 #include "vtkTypedDataArray.h" // For vtkTypedDataArray
39 
40 template <class Scalar>
42 {
43 public:
44  typedef std::random_access_iterator_tag iterator_category;
45  typedef Scalar value_type;
46  typedef std::ptrdiff_t difference_type;
47  typedef Scalar& reference;
48  typedef Scalar* pointer;
49 
51  : Data(nullptr)
52  , Index(0)
53  {
54  }
55 
57  : Data(arr)
58  , Index(index)
59  {
60  }
61 
63  : Data(o.Data)
64  , Index(o.Index)
65  {
66  }
67 
69  {
70  std::swap(this->Data, o.Data);
71  std::swap(this->Index, o.Index);
72  return *this;
73  }
74 
76  {
77  return this->Data == o.Data && this->Index == o.Index;
78  }
79 
81  {
82  return this->Data == o.Data && this->Index != o.Index;
83  }
84 
86  {
87  return this->Data == o.Data && this->Index > o.Index;
88  }
89 
91  {
92  return this->Data == o.Data && this->Index >= o.Index;
93  }
94 
96  {
97  return this->Data == o.Data && this->Index < o.Index;
98  }
99 
101  {
102  return this->Data == o.Data && this->Index <= o.Index;
103  }
104 
105  Scalar& operator*() { return this->Data->GetValueReference(this->Index); }
106 
107  Scalar* operator->() const { return &this->Data->GetValueReference(this->Index); }
108 
109  Scalar& operator[](const difference_type& n)
110  {
111  return this->Data->GetValueReference(this->Index + n);
112  }
113 
115  {
116  ++this->Index;
117  return *this;
118  }
119 
121  {
122  --this->Index;
123  return *this;
124  }
125 
127  {
128  return vtkTypedDataArrayIterator(this->Data, this->Index++);
129  }
130 
132  {
133  return vtkTypedDataArrayIterator(this->Data, this->Index--);
134  }
135 
137  {
138  return vtkTypedDataArrayIterator(this->Data, this->Index + n);
139  }
140 
142  {
143  return vtkTypedDataArrayIterator(this->Data, this->Index - n);
144  }
145 
147  {
148  return this->Index - other.Index;
149  }
150 
152  {
153  this->Index += n;
154  return *this;
155  }
156 
158  {
159  this->Index -= n;
160  return *this;
161  }
162 
163 private:
165  vtkIdType Index;
166 };
167 
168 #endif // vtkTypedDataArrayIterator_h
169 
170 // 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:252
int vtkIdType
Definition: vtkType.h:338