00001
00002
00008 #if !defined(__ads_TransformIterator_h__)
00009 #define __ads_TransformIterator_h__
00010
00011 #include "AdaptedIterator.h"
00012
00013 #include "../functor/index.h"
00014
00015 BEGIN_NAMESPACE_ADS
00016
00018
00022 template<typename _Iterator, class _Transform>
00023 class TransformIterator :
00024 public AdaptedIterator<
00025 _Iterator,
00026 typename std::iterator_traits<_Iterator>::iterator_category,
00027 typename _Transform::result_type,
00028 typename std::iterator_traits<_Iterator>::difference_type,
00029 void,
00030 void> {
00031 private:
00032
00033
00034
00035
00036
00037 typedef AdaptedIterator<
00038 _Iterator,
00039 typename std::iterator_traits<_Iterator>::iterator_category,
00040 typename _Transform::result_type,
00041 typename std::iterator_traits<_Iterator>::difference_type,
00042 void,
00043 void> Base;
00044
00045 public:
00046
00047
00048
00049
00050
00052 typedef typename Base::Iterator Iterator;
00054 typedef _Transform Transform;
00055
00056
00057
00059 typedef typename Base::iterator_category iterator_category;
00061 typedef typename Base::value_type value_type;
00063 typedef typename Base::difference_type difference_type;
00065 typedef typename Base::pointer pointer;
00067 typedef typename Base::reference reference;
00068
00069 private:
00070
00071
00072
00073
00074
00075 Transform _transform;
00076
00077 public:
00078
00079
00081
00082
00084 TransformIterator() :
00085 Base(),
00086 _transform()
00087 {}
00088
00090 TransformIterator(const TransformIterator& x) :
00091 Base(x),
00092 _transform(x._transform)
00093 {}
00094
00096 TransformIterator&
00097 operator=(const TransformIterator& x) {
00098
00099 Base::operator=(x);
00100 return *this;
00101 }
00102
00104 explicit
00105 TransformIterator(const Iterator& i) :
00106 Base(i),
00107 _transform()
00108 {}
00109
00111 TransformIterator(const Transform& t) :
00112 Base(),
00113 _transform(t)
00114 {}
00115
00117 TransformIterator(const Iterator& i, const Transform& t) :
00118 Base(i),
00119 _transform(t)
00120 {}
00121
00123 TransformIterator&
00124 operator=(const Iterator& i) {
00125 Base::operator=(i);
00126 return *this;
00127 }
00128
00130
00132
00133
00135 const Iterator&
00136 base() const {
00137 return Base::base();
00138 }
00139
00141 const Transform&
00142 transform() const {
00143 return _transform;
00144 }
00145
00147
00153
00154
00155
00156
00157
00159 value_type
00160 operator*() const {
00161 return _transform(*Base::_iterator);
00162 }
00163
00164
00165
00166
00167
00169 TransformIterator&
00170 operator++() {
00171 ++Base::_iterator;
00172 return *this;
00173 }
00174
00176 TransformIterator
00177 operator++(int) {
00178 TransformIterator tmp = *this;
00179 ++Base::_iterator;
00180 return tmp;
00181 }
00182
00183
00184
00185
00186
00188 TransformIterator&
00189 operator--() {
00190 --Base::_iterator;
00191 return *this;
00192 }
00193
00195 TransformIterator
00196 operator--(int) {
00197 TransformIterator tmp = *this;
00198 --Base::_iterator;
00199 return tmp;
00200 }
00201
00202
00203
00204
00205
00207 value_type
00208 operator[](const difference_type& n) const {
00209 return _transform(Base::_iterator[n]);
00210 }
00211
00213 TransformIterator&
00214 operator+=(const difference_type& n) {
00215 Base::_iterator += n;
00216 return *this;
00217 }
00218
00220 TransformIterator
00221 operator+(const difference_type& n) const {
00222 return TransformIterator(Base::_iterator + n);
00223 }
00224
00226 TransformIterator&
00227 operator-=(const difference_type& n) {
00228 Base::_iterator -= n;
00229 return *this;
00230 }
00231
00233 TransformIterator
00234 operator-(const difference_type& n) const {
00235 return TransformIterator(Base::_iterator - n);
00236 }
00237
00239 };
00240
00241
00242
00243
00244
00246
00249 template<typename _Iterator, class _Transform>
00250 inline
00251 TransformIterator<_Iterator,_Transform>
00252 operator+(typename TransformIterator<_Iterator,_Transform>::difference_type n,
00253 const TransformIterator<_Iterator,_Transform>& x) {
00254 return x + n;
00255 }
00256
00258
00261 template<typename _Iterator, class _Transform>
00262 inline
00263 TransformIterator<_Iterator,_Transform>
00264 constructTransformIterator() {
00265 return TransformIterator<_Iterator,_Transform>();
00266 }
00267
00269
00272 template<typename _Iterator, class _Transform>
00273 inline
00274 TransformIterator<_Iterator,_Transform>
00275 constructTransformIterator
00276 (const typename TransformIterator<_Iterator,_Transform>::Iterator& i) {
00277 return TransformIterator<_Iterator,_Transform>(i);
00278 }
00279
00281
00284 template<typename _Iterator, class _Transform>
00285 inline
00286 TransformIterator<_Iterator,_Transform>
00287 constructTransformIterator
00288 (const typename TransformIterator<_Iterator,_Transform>::Transform& t) {
00289 return TransformIterator<_Iterator,_Transform>(t);
00290 }
00291
00293
00296 template<typename _Iterator, class _Transform>
00297 inline
00298 TransformIterator<_Iterator,_Transform>
00299 constructTransformIterator
00300 (const typename TransformIterator<_Iterator,_Transform>::Iterator& i,
00301 const typename TransformIterator<_Iterator,_Transform>::Transform& t) {
00302 return TransformIterator<_Iterator,_Transform>(i, t);
00303 }
00304
00306
00312 template<typename IntIter, typename DataIter>
00313 inline
00314 TransformIterator<IntIter, IndexIterUnary<DataIter> >
00315 constructArrayIndexingIterator(IntIter i, DataIter d) {
00316 IndexIterUnary<DataIter> f(d);
00317 return TransformIterator<IntIter, IndexIterUnary<DataIter> >(i, f);
00318 }
00319
00320 END_NAMESPACE_ADS
00321
00322 #endif