1 #ifndef BALL_LINALG_RANDOMACCESSITERATOR_H
2 #define BALL_LINALG_RANDOMACCESSITERATOR_H
4 #ifndef BALL_CONCEPT_BIDIRECTIONALITERATOR_H
19 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
20 class ConstRandomAccessIterator
21 :
public ConstBidirectionalIterator<Container, DataType, Position, Traits>
186 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
187 ConstRandomAccessIterator<Container, DataType, Position, Traits>
operator +
188 (
Distance distance,
const ConstRandomAccessIterator<Container, DataType, Position, Traits>& iterator)
190 ConstRandomAccessIterator<Container, DataType, Position, Traits> tmp_iterator(iterator);
191 return (tmp_iterator += distance);
200 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
201 Distance ConstRandomAccessIterator<Container, DataType, Position, Traits>::operator -
202 (
const ConstRandomAccessIterator<Container, DataType, Position, Traits>& b)
const
204 if (!Base::getTraits().isValid())
206 Exception::InvalidIterator e;
209 if (!b.getTraits().isValid())
211 Exception::InvalidIterator e;
214 if (Base::getTraits().getContainer() != b.getTraits().getContainer())
216 Exception::IncompatibleIterators e;
219 return Base::getTraits().getDistance(b.getTraits());
222 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
223 ConstRandomAccessIterator<Container, DataType, Position, Traits>&
226 if (!Base::getTraits().isValid())
228 Exception::InvalidIterator e;
233 return (*
this -= -distance);
235 Base::getTraits().forward(distance);
239 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
240 ConstRandomAccessIterator<Container, DataType, Position, Traits>&
243 if (Base::getTraits().isSingular())
245 Exception::InvalidIterator e;
250 return (*
this += -distance);
252 if (Base::getTraits().isEnd() ==
true)
255 Base::getTraits().backward(distance - 1);
259 Base::getTraits().backward(distance);
264 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
265 ConstRandomAccessIterator<Container, DataType, Position, Traits>
268 ConstRandomAccessIterator iterator(*
this);
269 return (iterator += distance);
272 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
273 ConstRandomAccessIterator<Container, DataType, Position, Traits>
276 ConstRandomAccessIterator iterator(*
this);
277 return (iterator -= distance);
280 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
281 bool ConstRandomAccessIterator<Container, DataType, Position, Traits>::operator <
282 (
const ConstRandomAccessIterator& iterator)
const
284 if (!Base::getTraits().isValid())
286 Exception::InvalidIterator e;
289 if (!iterator.isValid())
291 Exception::InvalidIterator e;
294 if (Base::getTraits().getContainer() != iterator.getContainer())
296 Exception::IncompatibleIterators e;
300 return (Base::getTraits().operator < (iterator.getTraits()));
303 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
304 bool ConstRandomAccessIterator<Container, DataType, Position, Traits>::operator <=
305 (
const ConstRandomAccessIterator& iterator)
const
307 if (!Base::getTraits().isValid())
309 Exception::InvalidIterator e;
312 if (!iterator.isValid())
314 Exception::InvalidIterator e;
317 if (Base::getTraits().getContainer() != iterator.getContainer())
319 Exception::IncompatibleIterators e;
322 return !(Base::getTraits().operator > (iterator.getTraits()));
325 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
326 bool ConstRandomAccessIterator<Container, DataType, Position, Traits>::operator >=
327 (
const ConstRandomAccessIterator& iterator)
const
329 if (!Base::getTraits().isValid())
331 Exception::InvalidIterator e;
334 if (!iterator.isValid())
336 Exception::InvalidIterator e;
339 if (Base::getTraits().getContainer() != iterator.getContainer())
341 Exception::IncompatibleIterators e;
345 return !(Base::getTraits().operator < (iterator.getTraits()));
348 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
349 bool ConstRandomAccessIterator<Container, DataType, Position, Traits>::operator >
350 (
const ConstRandomAccessIterator& iterator)
const
352 if (!Base::getTraits().isValid())
354 Exception::InvalidIterator e;
357 if (!iterator.isValid())
359 Exception::InvalidIterator e;
362 if (Base::getTraits().getContainer() != iterator.getContainer())
364 Exception::IncompatibleIterators e;
368 return (Base::getTraits().operator > (iterator.getTraits()));
372 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
375 if (!Base::getTraits().isValid())
377 Exception::InvalidIterator e;
381 return Base::getTraits().getData(index);
384 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
385 ConstRandomAccessIterator<Container, DataType, Position, Traits>
388 ConstRandomAccessIterator iterator(container);
393 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
394 ConstRandomAccessIterator<Container, DataType, Position, Traits>
397 ConstRandomAccessIterator iterator(container);
402 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
403 ConstRandomAccessIterator<Container, DataType, Position, Traits>
406 ConstRandomAccessIterator iterator(container);
411 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
412 ConstRandomAccessIterator<Container, DataType, Position, Traits>
415 ConstRandomAccessIterator iterator(container);
427 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
428 class RandomAccessIterator
429 :
public ConstRandomAccessIterator<Container, DataType, Position, Traits>
512 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
513 RandomAccessIterator<Container, DataType, Position, Traits>
516 RandomAccessIterator iterator(container);
521 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
522 RandomAccessIterator<Container, DataType, Position, Traits>
525 RandomAccessIterator iterator(container);
530 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
531 RandomAccessIterator<Container, DataType, Position, Traits>
534 RandomAccessIterator iterator(container);
539 template <
typename Container,
typename DataType,
typename Position,
typename Traits>
540 RandomAccessIterator<Container, DataType, Position, Traits>
543 RandomAccessIterator iterator(container);
550 #endif // BALL_KERNEL_RANDOMACCESSITERATOR_H