NIST Biometric Evaluation Framework
Software components for biometric technology evaluations
be_memory_autoarrayiterator.h
Go to the documentation of this file.
1/*
2 * This software was developed at the National Institute of Standards and
3 * Technology (NIST) by employees of the Federal Government in the course
4 * of their official duties. Pursuant to Title 17 Section 105 of the
5 * United States Code, this software is not subject to copyright protection
6 * and is in the public domain. NIST assumes no responsibility whatsoever for
7 * its use by other parties, and makes no guarantees, expressed or implied,
8 * about its quality, reliability, or any other characteristic.
9 */
10
11#ifndef __BE_MEMORY_AUTOARRAYITERATOR_H__
12#define __BE_MEMORY_AUTOARRAYITERATOR_H__
13
14#include <iterator>
15#include <type_traits>
16
17namespace BiometricEvaluation
18{
19 namespace Memory
20 {
22 template <typename T> class AutoArray;
23
34 template <bool C, class T>
36 {
37 public:
38 /*
39 * Satisfy std::iterator_traits<> expectations.
40 */
41
44 std::random_access_iterator_tag;
46 using value_type = typename
47 std::conditional<C, const T, T>::type;
49 using difference_type = std::ptrdiff_t;
51 using pointer = typename
52 std::conditional<C, const T*, T*>::type;
54 using reference = typename
55 std::conditional<C, const T&, T&>::type;
56
62 using container = typename std::conditional<C,
63 const AutoArray<T>*, AutoArray<T>*>::type;
64
65 /*
66 * Constructors
67 */
68
80 container autoArray = nullptr,
81 difference_type offset = 0) :
82 _autoArray(autoArray),
83 _offset(offset)
84 {
85
86 }
87
90 const AutoArrayIterator &rhs) = default;
93 AutoArrayIterator &&rhs) = default;
95 ~AutoArrayIterator() = default;
96
97 /*
98 * Assignments
99 */
100
102 inline AutoArrayIterator&
104 pointer rhs)
105 {
106 _offset = rhs;
107 return (*this);
108 }
109
111 inline AutoArrayIterator&
113 const AutoArrayIterator &rhs) = default;
114
116 inline AutoArrayIterator&
118 const difference_type &rhs)
119 {
120 _offset += rhs;
121 return (*this);
122 }
123
125 inline AutoArrayIterator&
127 const difference_type &rhs)
128 {
129 _offset -= rhs;
130 return (*this);
131 }
132
133 /*
134 * Dereferencing Content
135 */
136
138 inline reference
140 const
141 {
142 return (_autoArray->operator[](_offset));
143 }
144
146 inline pointer
148 const
149 {
150 return (&(_autoArray->operator[](_offset)));
151 }
152
154 inline reference
156 const difference_type &rhs)
157 const
158 {
159 return (_autoArray->operator[](rhs));
160 }
161
162 /*
163 * Arithmetic
164 */
165
167 inline AutoArrayIterator&
169 {
170 ++_offset;
171 return (*this);
172 }
173
175 inline AutoArrayIterator&
177 {
178 --_offset;
179 return (*this);
180 }
181
183 inline AutoArrayIterator
185 int)
186 {
187 const AutoArrayIterator previous(*this);
188 ++(*this);
189 return (previous);
190 }
191
193 inline AutoArrayIterator
195 int)
196 {
197 AutoArrayIterator previous(*this);
198 --(*this);
199 return (previous);
200 }
201
206 inline AutoArrayIterator
208 const AutoArrayIterator &rhs)
209 const
210 {
211 return (AutoArrayIterator(_offset +
212 rhs._offset));
213 }
214
216 inline difference_type
218 const AutoArrayIterator<C, T> &rhs)
219 const
220 {
221 return (_offset - rhs._offset);
222 }
223
225 inline AutoArrayIterator
227 const difference_type &rhs)
228 const
229 {
230 return (AutoArrayIterator(_autoArray,
231 _offset + rhs));
232 }
233
235 inline AutoArrayIterator
237 const difference_type &rhs)
238 const
239 {
240 return (AutoArrayIterator(_autoArray,
241 _offset - rhs));
242 }
243
245 friend inline AutoArrayIterator
247 const difference_type &lhs,
248 const AutoArrayIterator &rhs)
249 {
250 return (AutoArrayIterator(rhs._autoArray,
251 lhs + rhs._offset));
252 }
253
258 friend inline AutoArrayIterator
260 const difference_type &lhs,
261 const AutoArrayIterator &rhs)
262 {
263 return (AutoArrayIterator(rhs._autoArray,
264 lhs - rhs._offset));
265 }
266
267 /*
268 * Comparisons
269 */
270
272 inline bool
274 const AutoArrayIterator &rhs)
275 const
276 {
277 return (_offset == rhs._offset);
278 }
279
281 inline bool
283 const AutoArrayIterator &rhs)
284 const
285 {
286 return (_offset != rhs._offset);
287 }
288
290 inline bool
292 const AutoArrayIterator &rhs)
293 const
294 {
295 return (_offset > rhs._offset);
296 }
297
299 inline bool
300 operator<(
301 const AutoArrayIterator &rhs)
302 const
303 {
304 return (_offset < rhs._offset);
305 }
306
308 inline bool
310 const AutoArrayIterator &rhs)
311 const
312 {
313 return (_offset >= rhs._offset);
314 }
315
317 inline bool
319 const AutoArrayIterator &rhs)
320 const
321 {
322 return (_offset <= rhs._offset);
323 }
324
325 private:
327 container _autoArray;
329 difference_type _offset;
330 };
331 }
332}
333
334#endif /* __BE_MEMORY_AUTOARRAYITERATOR_H__ */
A C-style array wrapped in the facade of a C++ STL container.
AutoArrayIterator operator-(const difference_type &rhs) const
std::ptrdiff_t difference_type
Type used to measure distance between iterators.
AutoArrayIterator(container autoArray=nullptr, difference_type offset=0)
Default constructor.
bool operator>=(const AutoArrayIterator &rhs) const
bool operator<(const AutoArrayIterator &rhs) const
typename std::conditional< C, const T *, T * >::type pointer
Pointer to the type iterated over.
bool operator<=(const AutoArrayIterator &rhs) const
bool operator==(const AutoArrayIterator &rhs) const
typename std::conditional< C, const T, T >::type value_type
Type when dereferencing iterators.
friend AutoArrayIterator operator+(const difference_type &lhs, const AutoArrayIterator &rhs)
AutoArrayIterator(const AutoArrayIterator &rhs)=default
Default copy constructor.
AutoArrayIterator operator+(const difference_type &rhs) const
typename std::conditional< C, const T &, T & >::type reference
Reference to the type iterated over.
AutoArrayIterator & operator=(const AutoArrayIterator &rhs)=default
Default assignment operator.
bool operator!=(const AutoArrayIterator &rhs) const
friend AutoArrayIterator operator-(const difference_type &lhs, const AutoArrayIterator &rhs)
difference_type operator-(const AutoArrayIterator< C, T > &rhs) const
reference operator[](const difference_type &rhs) const
AutoArrayIterator operator+(const AutoArrayIterator &rhs) const
bool operator>(const AutoArrayIterator &rhs) const
std::random_access_iterator_tag iterator_category
Type of iterator.
typename std::conditional< C, const AutoArray< T > *, AutoArray< T > * >::type container
Convenience definition for a reference to the iterated type with appropriate constness.
AutoArrayIterator(AutoArrayIterator &&rhs)=default
Default move constructor.
~AutoArrayIterator()=default
Default destructor.
AutoArrayIterator & operator+=(const difference_type &rhs)
AutoArrayIterator & operator-=(const difference_type &rhs)
This software was developed at the National Institute of Standards and Technology (NIST) by employees...