VTK
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), Index(0) {}
52 
54  const vtkIdType index = 0)
55  : Data(arr),
56  Index(index)
57  {
58  }
59 
61  : Data(o.Data),
62  Index(o.Index)
63  {
64  }
65 
68  {
69  std::swap(this->Data, o.Data);
70  std::swap(this->Index, o.Index);
71  return *this;
72  }
73 
75  {
76  return this->Data == o.Data && this->Index == o.Index;
77  }
78 
80  {
81  return this->Data == o.Data && this->Index != o.Index;
82  }
83 
85  {
86  return this->Data == o.Data && this->Index > o.Index;
87  }
88 
90  {
91  return this->Data == o.Data && this->Index >= o.Index;
92  }
93 
95  {
96  return this->Data == o.Data && this->Index < o.Index;
97  }
98 
100  {
101  return this->Data == o.Data && this->Index <= o.Index;
102  }
103 
104  Scalar& operator*()
105  {
106  return this->Data->GetValueReference(this->Index);
107  }
108 
109  Scalar* operator->() const
110  {
111  return &this->Data->GetValueReference(this->Index);
112  }
113 
114  Scalar& operator[](const difference_type &n)
115  {
116  return this->Data->GetValueReference(this->Index + n);
117  }
118 
120  {
121  ++this->Index;
122  return *this;
123  }
124 
126  {
127  --this->Index;
128  return *this;
129  }
130 
132  {
133  return vtkTypedDataArrayIterator(this->Data, this->Index++);
134  }
135 
137  {
138  return vtkTypedDataArrayIterator(this->Data, this->Index--);
139  }
140 
142  {
143  return vtkTypedDataArrayIterator(this->Data, this->Index + n);
144  }
145 
147  {
148  return vtkTypedDataArrayIterator(this->Data, this->Index - n);
149  }
150 
152  {
153  return this->Index - other.Index;
154  }
155 
157  {
158  this->Index += n;
159  return *this;
160  }
161 
163  {
164  this->Index -= n;
165  return *this;
166  }
167 
168 private:
170  vtkIdType Index;
171 };
172 
173 #endif // vtkTypedDataArrayIterator_h
174 
175 // VTK-HeaderTest-Exclude: vtkTypedDataArrayIterator.h
bool operator<(const vtkTypedDataArrayIterator< Scalar > &o) const
vtkTypedDataArrayIterator operator-(const difference_type &n) const
vtkTypedDataArrayIterator & operator=(vtkTypedDataArrayIterator< Scalar > o)
vtkTypedDataArrayIterator & operator--()
vtkTypedDataArrayIterator & operator+=(const difference_type &n)
vtkTypedDataArrayIterator(const vtkTypedDataArrayIterator &o)
vtkTypedDataArrayIterator & operator++()
difference_type operator-(const vtkTypedDataArrayIterator &other) const
int vtkIdType
Definition: vtkType.h:347
vtkTypedDataArrayIterator operator+(const difference_type &n) const
vtkTypedDataArrayIterator & operator-=(const difference_type &n)
vtkTypedDataArrayIterator(vtkTypedDataArray< Scalar > *arr, const vtkIdType index=0)
vtkTypedDataArrayIterator operator--(int)
std::random_access_iterator_tag iterator_category
bool operator<=(const vtkTypedDataArrayIterator< Scalar > &o) const
Scalar & operator[](const difference_type &n)
Extend vtkDataArray with abstract type-specific API.
vtkTypedDataArrayIterator operator++(int)
bool operator>(const vtkTypedDataArrayIterator< Scalar > &o) const
bool operator==(const vtkTypedDataArrayIterator< Scalar > &o) const
STL-style random access iterator for vtkTypedDataArrays.
bool operator!=(const vtkTypedDataArrayIterator< Scalar > &o) const
bool operator>=(const vtkTypedDataArrayIterator< Scalar > &o) const