VTK  9.2.6
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 
36 #ifndef vtkTypedDataArrayIterator_h
37 #define vtkTypedDataArrayIterator_h
38 
39 #include <iterator> // For iterator traits
40 
41 #include "vtkTypedDataArray.h" // For vtkTypedDataArray
42 
43 template <class Scalar>
45 {
46 public:
47  typedef std::random_access_iterator_tag iterator_category;
48  typedef Scalar value_type;
49  typedef std::ptrdiff_t difference_type;
50  typedef Scalar& reference;
51  typedef Scalar* pointer;
52 
54  : Data(nullptr)
55  , Index(0)
56  {
57  }
58 
60  : Data(arr)
61  , Index(index)
62  {
63  }
64 
66  : Data(o.Data)
67  , Index(o.Index)
68  {
69  }
70 
72  {
73  std::swap(this->Data, o.Data);
74  std::swap(this->Index, o.Index);
75  return *this;
76  }
77 
79  {
80  return this->Data == o.Data && this->Index == o.Index;
81  }
82 
84  {
85  return this->Data == o.Data && this->Index != o.Index;
86  }
87 
89  {
90  return this->Data == o.Data && this->Index > o.Index;
91  }
92 
94  {
95  return this->Data == o.Data && this->Index >= o.Index;
96  }
97 
98  bool operator<(const vtkTypedDataArrayIterator<Scalar>& o) const
99  {
100  return this->Data == o.Data && this->Index < o.Index;
101  }
102 
103  bool operator<=(const vtkTypedDataArrayIterator<Scalar>& o) const
104  {
105  return this->Data == o.Data && this->Index <= o.Index;
106  }
107 
108  Scalar& operator*() { return this->Data->GetValueReference(this->Index); }
109 
110  Scalar* operator->() const { return &this->Data->GetValueReference(this->Index); }
111 
112  Scalar& operator[](const difference_type& n)
113  {
114  return this->Data->GetValueReference(this->Index + n);
115  }
116 
118  {
119  ++this->Index;
120  return *this;
121  }
122 
124  {
125  --this->Index;
126  return *this;
127  }
128 
130  {
131  return vtkTypedDataArrayIterator(this->Data, this->Index++);
132  }
133 
135  {
136  return vtkTypedDataArrayIterator(this->Data, this->Index--);
137  }
138 
139  vtkTypedDataArrayIterator operator+(const difference_type& n) const
140  {
141  return vtkTypedDataArrayIterator(this->Data, this->Index + n);
142  }
143 
144  vtkTypedDataArrayIterator operator-(const difference_type& n) const
145  {
146  return vtkTypedDataArrayIterator(this->Data, this->Index - n);
147  }
148 
149  difference_type operator-(const vtkTypedDataArrayIterator& other) const
150  {
151  return this->Index - other.Index;
152  }
153 
154  vtkTypedDataArrayIterator& operator+=(const difference_type& n)
155  {
156  this->Index += n;
157  return *this;
158  }
159 
160  vtkTypedDataArrayIterator& operator-=(const difference_type& n)
161  {
162  this->Index -= n;
163  return *this;
164  }
165 
166 private:
168  vtkIdType Index;
169 };
170 
171 #endif // vtkTypedDataArrayIterator_h
172 
173 // VTK-HeaderTest-Exclude: vtkTypedDataArrayIterator.h
bool operator>=(const vtkTypedDataArrayIterator< Scalar > &o) const
bool operator>(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator & operator=(vtkTypedDataArrayIterator< Scalar > o)
bool operator==(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator & operator--()
vtkTypedDataArrayIterator & operator+=(const difference_type &n)
vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
vtkTypedDataArrayIterator & operator++()
bool operator!=(const vtkTypedDataArrayIterator< Scalar > &o) const
int vtkIdType
Definition: vtkType.h:332
vtkTypedDataArrayIterator & operator-=(const difference_type &n)
vtkTypedDataArrayIterator(vtkTypedDataArray< Scalar > *arr, const vtkIdType index=0)
vtkTypedDataArrayIterator operator+(const difference_type &n) const
vtkTypedDataArrayIterator operator--(int)
std::random_access_iterator_tag iterator_category
Scalar & operator[](const difference_type &n)
difference_type operator-(const vtkTypedDataArrayIterator &other) const
Extend vtkDataArray with abstract type-specific API.
vtkTypedDataArrayIterator operator++(int)
STL-style random access iterator for vtkTypedDataArrays.
vtkTypedDataArrayIterator operator-(const difference_type &n) const