Honeycomb  0.1
Component-Model Framework
Iter.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
4 namespace honey { namespace matrix
5 {
6 
8 template<class Matrix>
9 class Iter
10 {
11 public:
13  typedef typename std::conditional<std::is_const<Matrix>::value, const typename Matrix::ElemT, typename Matrix::ElemT>::type
15 
16  typedef std::random_access_iterator_tag iterator_category;
17  typedef ElemT value_type;
19  typedef ElemT* pointer;
20  typedef ElemT& reference;
21 
22  Iter() : _m(nullptr) {}
23  Iter(Matrix& m, sdt i) : _m(&m), _i(i) {}
24 
25  Iter& operator++() { ++_i; return *this; }
26  Iter& operator--() { --_i; return *this; }
27  Iter operator++(int) { auto tmp = *this; ++*this; return tmp; }
28  Iter operator--(int) { auto tmp = *this; --*this; return tmp; }
29  Iter& operator+=(difference_type rhs) { _i += rhs; return *this; }
30  Iter& operator-=(difference_type rhs) { _i -= rhs; return *this; }
31  Iter operator+(difference_type rhs) const { auto tmp = *this; tmp+=rhs; return tmp; }
32  Iter operator-(difference_type rhs) const { auto tmp = *this; tmp-=rhs; return tmp; }
33  difference_type operator-(const Iter& rhs) const { return _i - rhs._i; }
34 
35  bool operator==(const Iter& rhs) const { return _i == rhs._i; }
36  bool operator!=(const Iter& rhs) const { return _i != rhs._i; }
37  bool operator< (const Iter& rhs) const { return _i < rhs._i; }
38  bool operator> (const Iter& rhs) const { return _i > rhs._i; }
39  bool operator<=(const Iter& rhs) const { return _i <= rhs._i; }
40  bool operator>=(const Iter& rhs) const { return _i >= rhs._i; }
41 
42  reference operator*() const { return (*_m)(_i); }
43  operator difference_type() const { return _i; }
44 
45 private:
46  Matrix* _m;
47  sdt _i;
48 };
49 
50 } }
Iter & operator--()
Definition: Iter.h:26
(m x n)-dimensional matrix
Definition: Matrix.h:24
bool operator==(const Iter &rhs) const
Definition: Iter.h:35
Iter(Matrix &m, sdt i)
Definition: Iter.h:23
difference_type operator-(const Iter &rhs) const
Definition: Iter.h:33
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
Iter & operator+=(difference_type rhs)
Definition: Iter.h:29
Iter & operator++()
Definition: Iter.h:25
bool operator>=(const Iter &rhs) const
Definition: Iter.h:40
std::random_access_iterator_tag iterator_category
Definition: Iter.h:16
Matrix element iterator.
Definition: Iter.h:9
ElemT * pointer
Definition: Iter.h:19
Iter()
Definition: Iter.h:22
reference operator*() const
Definition: Iter.h:42
Iter operator-(difference_type rhs) const
Definition: Iter.h:32
bool operator<(const Iter &rhs) const
Definition: Iter.h:37
ElemT & reference
Definition: Iter.h:20
sdt difference_type
Definition: Iter.h:18
Iter & operator-=(difference_type rhs)
Definition: Iter.h:30
bool operator>(const Iter &rhs) const
Definition: Iter.h:38
Iter operator--(int)
Definition: Iter.h:28
ElemT value_type
Definition: Iter.h:17
bool operator<=(const Iter &rhs) const
Definition: Iter.h:39
std::conditional< std::is_const< Matrix >::value, const typename Matrix::ElemT, typename Matrix::ElemT >::type ElemT
Our element access is const if matrix is const.
Definition: Iter.h:14
bool operator!=(const Iter &rhs) const
Definition: Iter.h:36
Global Honeycomb namespace.
Iter operator+(difference_type rhs) const
Definition: Iter.h:31
Iter operator++(int)
Definition: Iter.h:27