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