IndexedIterator.h
Go to the documentation of this file.
1 #ifndef GfxTL__INDEXEDITERATOR_HEADER__
2 #define GfxTL__INDEXEDITERATOR_HEADER__
3 #include <iterator>
4 
5 namespace GfxTL
6 {
7  template <class IndexIteratorT, class IteratorT>
9  {
10  public:
11  typedef typename std::iterator_traits<IteratorT>::value_type value_type;
12  typedef typename std::iterator_traits<IteratorT>::pointer pointer;
13  typedef typename std::iterator_traits<IteratorT>::reference reference;
14  typedef typename std::iterator_traits<IndexIteratorT>::iterator_category iterator_category;
15  typedef typename std::iterator_traits<IndexIteratorT>::difference_type difference_type;
17  typedef typename std::iterator_traits<IndexIteratorT>::value_type IndexType;
18 
20  {
21  }
22 
23  IndexedIterator(const ThisType& it) : m_idxIt(it.m_idxIt), m_it(it.m_it)
24  {
25  }
26 
27  IndexedIterator(IndexIteratorT idxIt, IteratorT it) : m_idxIt(idxIt), m_it(it)
28  {
29  }
30 
31  template <class IdxItT, class ItT>
33  m_idxIt(it.IndexIterator()), m_it(it.Iterator())
34  {
35  }
36 
37  pointer
39  {
40  return &m_it[*m_idxIt];
41  }
42 
43  reference
45  {
46  return m_it[*m_idxIt];
47  }
48 
49  ThisType&
51  {
52  ++m_idxIt;
53  return *this;
54  }
55 
56  ThisType
58  {
59  ThisType cpy(*this);
60  ++m_idxIt;
61  return cpy;
62  }
63 
64  ThisType&
66  {
67  --m_idxIt;
68  return *this;
69  }
70 
71  ThisType
73  {
74  ThisType cpy(*this);
75  --m_idxIt;
76  return cpy;
77  }
78 
79  bool
80  operator==(const ThisType& i) const
81  {
82  return m_idxIt == i.m_idxIt && m_it == i.m_it;
83  }
84 
85  bool
86  operator!=(const ThisType& i) const
87  {
88  return !operator==(i);
89  }
90 
92  operator-(const ThisType& i) const
93  {
94  return m_idxIt - i.m_idxIt;
95  }
96 
97  ThisType
99  {
100  return ThisType(m_idxIt + d, m_it);
101  }
102 
103  ThisType
105  {
106  return ThisType(m_idxIt - d, m_it);
107  }
108 
109  reference
111  {
112  return m_it[m_idxIt[d]];
113  }
114 
115  IndexType
116  Index() const
117  {
118  return *m_idxIt;
119  }
120 
121  const IndexIteratorT&
123  {
124  return m_idxIt;
125  }
126 
127  const IteratorT&
128  Iterator() const
129  {
130  return m_it;
131  }
132 
133  template <class IdxItT, class ItT>
134  ThisType&
136  {
137  m_idxIt = it.IndexIterator();
138  m_it = it.Iterator();
139  return *this;
140  }
141 
142  bool
143  operator<(const ThisType& i) const
144  {
145  return m_idxIt < i.m_idxIt;
146  }
147 
148  bool
149  operator>(const ThisType& i) const
150  {
151  return m_idxIt > i.m_idxIt;
152  }
153 
154  bool
155  operator<=(const ThisType& i) const
156  {
157  return m_idxIt <= i.m_idxIt;
158  }
159 
160  bool
161  operator>=(const ThisType& i) const
162  {
163  return m_idxIt >= i.m_idxIt;
164  }
165 
166  private:
167  IndexIteratorT m_idxIt;
168  IteratorT m_it;
169  };
170 
171  template <class IndexIteratorT, class IteratorT>
172  IndexedIterator<IndexIteratorT, IteratorT>
173  IndexIterate(IndexIteratorT idxIt, IteratorT it)
174  {
176  }
177 
178 }; // namespace GfxTL
179 
180 #endif
GfxTL::IndexedIterator
Definition: IndexedIterator.h:8
GfxTL::IndexedIterator::IndexedIterator
IndexedIterator(const ThisType &it)
Definition: IndexedIterator.h:23
GfxTL::IndexedIterator::operator>
bool operator>(const ThisType &i) const
Definition: IndexedIterator.h:149
GfxTL::IndexedIterator::operator-
ThisType operator-(difference_type d) const
Definition: IndexedIterator.h:104
GfxTL::IndexedIterator::difference_type
std::iterator_traits< IndexIteratorT >::difference_type difference_type
Definition: IndexedIterator.h:15
GfxTL::IndexedIterator::operator<
bool operator<(const ThisType &i) const
Definition: IndexedIterator.h:143
GfxTL::IndexedIterator::IndexedIterator
IndexedIterator()
Definition: IndexedIterator.h:19
GfxTL::IndexedIterator::operator*
reference operator*()
Definition: IndexedIterator.h:44
GfxTL::IndexedIterator::operator->
pointer operator->()
Definition: IndexedIterator.h:38
GfxTL::IndexedIterator::Iterator
const IteratorT & Iterator() const
Definition: IndexedIterator.h:128
GfxTL::IndexedIterator::operator--
ThisType operator--(int)
Definition: IndexedIterator.h:72
GfxTL::IndexedIterator::operator<=
bool operator<=(const ThisType &i) const
Definition: IndexedIterator.h:155
GfxTL::IndexedIterator::reference
std::iterator_traits< IteratorT >::reference reference
Definition: IndexedIterator.h:13
GfxTL::IndexedIterator::IndexType
std::iterator_traits< IndexIteratorT >::value_type IndexType
Definition: IndexedIterator.h:17
GfxTL::IndexedIterator::operator==
bool operator==(const ThisType &i) const
Definition: IndexedIterator.h:80
GfxTL::IndexedIterator::IndexIterator
const IndexIteratorT & IndexIterator() const
Definition: IndexedIterator.h:122
GfxTL::IndexedIterator::Index
IndexType Index() const
Definition: IndexedIterator.h:116
GfxTL::IndexedIterator::operator[]
reference operator[](difference_type d)
Definition: IndexedIterator.h:110
GfxTL::IndexIterate
IndexedIterator< IndexIteratorT, IteratorT > IndexIterate(IndexIteratorT idxIt, IteratorT it)
Definition: IndexedIterator.h:173
GfxTL::IndexedIterator::ThisType
IndexedIterator< IndexIteratorT, IteratorT > ThisType
Definition: IndexedIterator.h:16
GfxTL::IndexedIterator::IndexedIterator
IndexedIterator(IndexIteratorT idxIt, IteratorT it)
Definition: IndexedIterator.h:27
GfxTL::IndexedIterator::operator++
ThisType & operator++()
Definition: IndexedIterator.h:50
GfxTL::IndexedIterator::operator-
difference_type operator-(const ThisType &i) const
Definition: IndexedIterator.h:92
GfxTL::IndexedIterator::operator!=
bool operator!=(const ThisType &i) const
Definition: IndexedIterator.h:86
GfxTL
Definition: AABox.h:9
GfxTL::IndexedIterator::operator++
ThisType operator++(int)
Definition: IndexedIterator.h:57
GfxTL::IndexedIterator::operator+
ThisType operator+(difference_type d) const
Definition: IndexedIterator.h:98
GfxTL::IndexedIterator::operator>=
bool operator>=(const ThisType &i) const
Definition: IndexedIterator.h:161
GfxTL::IndexedIterator::pointer
std::iterator_traits< IteratorT >::pointer pointer
Definition: IndexedIterator.h:12
GfxTL::IndexedIterator::IndexedIterator
IndexedIterator(const IndexedIterator< IdxItT, ItT > &it)
Definition: IndexedIterator.h:32
GfxTL::IndexedIterator::operator=
ThisType & operator=(const IndexedIterator< IdxItT, ItT > &it)
Definition: IndexedIterator.h:135
IndexIterator
Definition: IndexIterator.h:9
GfxTL::IndexedIterator::operator--
ThisType & operator--()
Definition: IndexedIterator.h:65
GfxTL::IndexedIterator::value_type
std::iterator_traits< IteratorT >::value_type value_type
Definition: IndexedIterator.h:11
GfxTL::IndexedIterator::iterator_category
std::iterator_traits< IndexIteratorT >::iterator_category iterator_category
Definition: IndexedIterator.h:14