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 
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(NULL), Index(0) {}
55 
57  const vtkIdType index = 0)
58  : Data(arr),
59  Index(index)
60  {
61  }
62 
64  : Data(o.Data),
65  Index(o.Index)
66  {
67  }
68 
71  {
72  std::swap(this->Data, o.Data);
73  std::swap(this->Index, o.Index);
74  return *this;
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  bool operator<(const vtkTypedDataArrayIterator<Scalar> &o) const
98  {
99  return this->Data == o.Data && this->Index < o.Index;
100  }
101 
102  bool operator<=(const vtkTypedDataArrayIterator<Scalar> &o) const
103  {
104  return this->Data == o.Data && this->Index <= o.Index;
105  }
106 
107  Scalar& operator*()
108  {
109  return this->Data->GetValueReference(this->Index);
110  }
111 
112  Scalar* operator->() const
113  {
114  return &this->Data->GetValueReference(this->Index);
115  }
116 
117  Scalar& operator[](const difference_type &n)
118  {
119  return this->Data->GetValueReference(this->Index + n);
120  }
121 
123  {
124  ++this->Index;
125  return *this;
126  }
127 
129  {
130  --this->Index;
131  return *this;
132  }
133 
135  {
136  return vtkTypedDataArrayIterator(this->Data, this->Index++);
137  }
138 
140  {
141  return vtkTypedDataArrayIterator(this->Data, this->Index--);
142  }
143 
144  vtkTypedDataArrayIterator operator+(const difference_type& n) const
145  {
146  return vtkTypedDataArrayIterator(this->Data, this->Index + n);
147  }
148 
149  vtkTypedDataArrayIterator operator-(const difference_type& n) const
150  {
151  return vtkTypedDataArrayIterator(this->Data, this->Index - n);
152  }
153 
154  difference_type operator-(const vtkTypedDataArrayIterator& other) const
155  {
156  return this->Index - other.Index;
157  }
158 
159  vtkTypedDataArrayIterator& operator+=(const difference_type& n)
160  {
161  this->Index += n;
162  return *this;
163  }
164 
165  vtkTypedDataArrayIterator& operator-=(const difference_type& n)
166  {
167  this->Index -= n;
168  return *this;
169  }
170 
171 private:
173  vtkIdType Index;
174 };
175 
176 #endif // vtkTypedDataArrayIterator_h
177 
178 // 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:287
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