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 
32 #ifndef vtkTypedDataArrayIterator_h
33 #define vtkTypedDataArrayIterator_h
34 
35 #include <iterator> // For iterator traits
36 
37 #include "vtkTypedDataArray.h" // For vtkTypedDataArray
38 
39 template<class Scalar>
41 {
42 public:
43  typedef std::random_access_iterator_tag iterator_category;
44  typedef Scalar value_type;
45  typedef std::ptrdiff_t difference_type;
46  typedef Scalar& reference;
47  typedef Scalar* pointer;
48 
50  : Data(NULL), Index(0) {}
51 
53  const vtkIdType index = 0)
54  : Data(arr),
55  Index(index)
56  {
57  }
58 
60  : Data(o.Data),
61  Index(o.Index)
62  {
63  }
64 
67  {
68  std::swap(this->Data, o.Data);
69  std::swap(this->Index, o.Index);
70  return *this;
71  }
72 
74  {
75  return this->Data == o.Data && this->Index == o.Index;
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 
93  bool operator<(const vtkTypedDataArrayIterator<Scalar> &o) const
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  Scalar& operator*()
104  {
105  return this->Data->GetValueReference(this->Index);
106  }
107 
108  Scalar* operator->() const
109  {
110  return &this->Data->GetValueReference(this->Index);
111  }
112 
113  Scalar& operator[](const difference_type &n)
114  {
115  return this->Data->GetValueReference(this->Index + n);
116  }
117 
119  {
120  ++this->Index;
121  return *this;
122  }
123 
125  {
126  --this->Index;
127  return *this;
128  }
129 
131  {
132  return vtkTypedDataArrayIterator(this->Data, this->Index++);
133  }
134 
136  {
137  return vtkTypedDataArrayIterator(this->Data, this->Index--);
138  }
139 
140  vtkTypedDataArrayIterator operator+(const difference_type& n) const
141  {
142  return vtkTypedDataArrayIterator(this->Data, this->Index + n);
143  }
144 
145  vtkTypedDataArrayIterator operator-(const difference_type& n) const
146  {
147  return vtkTypedDataArrayIterator(this->Data, this->Index - n);
148  }
149 
150  difference_type operator-(const vtkTypedDataArrayIterator& other) const
151  {
152  return this->Index - other.Index;
153  }
154 
155  vtkTypedDataArrayIterator& operator+=(const difference_type& n)
156  {
157  this->Index += n;
158  return *this;
159  }
160 
161  vtkTypedDataArrayIterator& operator-=(const difference_type& n)
162  {
163  this->Index -= n;
164  return *this;
165  }
166 
167 private:
169  vtkIdType Index;
170 };
171 
172 #endif // vtkTypedDataArrayIterator_h
173 
174 // 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:275
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