IndexedIterator.h
Go to the documentation of this file.
1#ifndef GfxTL__INDEXEDITERATOR_HEADER__
2#define GfxTL__INDEXEDITERATOR_HEADER__
3#include <iterator>
4
5namespace 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
39 {
40 return &m_it[*m_idxIt];
41 }
42
45 {
46 return m_it[*m_idxIt];
47 }
48
51 {
52 ++m_idxIt;
53 return *this;
54 }
55
58 {
59 ThisType cpy(*this);
60 ++m_idxIt;
61 return cpy;
62 }
63
66 {
67 --m_idxIt;
68 return *this;
69 }
70
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
99 {
100 return ThisType(m_idxIt + d, m_it);
101 }
102
105 {
106 return ThisType(m_idxIt - d, m_it);
107 }
108
111 {
112 return m_it[m_idxIt[d]];
113 }
114
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
std::iterator_traits< IndexIteratorT >::iterator_category iterator_category
std::iterator_traits< IteratorT >::pointer pointer
ThisType & operator=(const IndexedIterator< IdxItT, ItT > &it)
bool operator!=(const ThisType &i) const
std::iterator_traits< IndexIteratorT >::value_type IndexType
bool operator>=(const ThisType &i) const
IndexType Index() const
IndexedIterator(const IndexedIterator< IdxItT, ItT > &it)
std::iterator_traits< IndexIteratorT >::difference_type difference_type
std::iterator_traits< IteratorT >::value_type value_type
ThisType operator-(difference_type d) const
IndexedIterator(IndexIteratorT idxIt, IteratorT it)
IndexedIterator< IndexIteratorT, IteratorT > ThisType
IndexedIterator(const ThisType &it)
bool operator<=(const ThisType &i) const
reference operator[](difference_type d)
std::iterator_traits< IteratorT >::reference reference
bool operator<(const ThisType &i) const
ThisType operator+(difference_type d) const
bool operator==(const ThisType &i) const
difference_type operator-(const ThisType &i) const
bool operator>(const ThisType &i) const
Definition AABox.h:10
IndexedIterator< IndexIteratorT, IteratorT > IndexIterate(IndexIteratorT idxIt, IteratorT it)