00001
00002
00008 #if !defined(__ads_MemFunIterator_h__)
00009 #define __ads_MemFunIterator_h__
00010
00011 #include "AdaptedIterator.h"
00012
00013 #include "../../third-party/loki/TypeManip.h"
00014
00015 BEGIN_NAMESPACE_ADS
00016
00018
00021 template<typename _Iterator, class Pointee, typename Result, bool Const = true>
00022 class MemFunIterator :
00023 public AdaptedIterator<
00024 _Iterator,
00025 typename std::iterator_traits<_Iterator>::iterator_category,
00026 Result,
00027 typename std::iterator_traits<_Iterator>::difference_type,
00028 void,
00029 void> {
00030
00031
00032
00033
00034 private:
00035
00036 typedef AdaptedIterator<
00037 _Iterator,
00038 typename std::iterator_traits<_Iterator>::iterator_category,
00039 Result,
00040 typename std::iterator_traits<_Iterator>::difference_type,
00041 void,
00042 void>
00043 Base;
00044
00045
00046
00047
00048
00049 public:
00050
00051
00052
00054 typedef typename Base::iterator_category iterator_category;
00056 typedef typename Base::value_type value_type;
00058 typedef typename Base::difference_type difference_type;
00060 typedef typename Base::pointer pointer;
00062 typedef typename Base::reference reference;
00063
00065 typedef typename Base::Iterator Iterator;
00066
00067
00068
00069
00071
00072
00073
00074
00075
00076
00077 private:
00078
00080 typedef value_type (Pointee::*mem_fun)();
00082 typedef value_type (Pointee::*mem_fun_const)() const;
00083
00084
00085
00086
00087
00088 public:
00089
00091 typedef typename Loki::Select<Const, mem_fun_const, mem_fun>::Result
00092 MemberFunction;
00093
00094
00095
00096
00097
00098 private:
00099
00101 MemberFunction _f;
00102
00103 public:
00104
00105
00107
00108
00110 MemFunIterator() :
00111 Base(),
00112 _f()
00113 {}
00114
00116 MemFunIterator(MemberFunction f) :
00117 Base(),
00118 _f(f)
00119 {}
00120
00122 MemFunIterator(MemberFunction f, const Iterator& i) :
00123 Base(i),
00124 _f(f)
00125 {}
00126
00128 MemFunIterator(const MemFunIterator& x) :
00129 Base(x),
00130 _f(x._f)
00131 {}
00132
00134 MemFunIterator&
00135 operator=(const MemFunIterator& other) {
00136 Base::operator=(other);
00137 _f = other._f;
00138 return *this;
00139 }
00140
00142 MemFunIterator&
00143 operator=(const Iterator& i) {
00144 Base::operator=(i);
00145 return *this;
00146 }
00147
00149 MemFunIterator&
00150 operator=(MemberFunction f) {
00151 _f = f;
00152 return *this;
00153 }
00154
00156
00158
00159
00161 const Iterator&
00162 base() const {
00163 return Base::base();
00164 }
00165
00167 operator Iterator() const {
00168 return Base::base();
00169 }
00170
00172
00174
00175
00176
00177
00178
00179
00181 value_type
00182 operator*() const {
00183
00184
00185 return ((*Base::_iterator).*_f)();
00186 }
00187
00188
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00202 MemFunIterator&
00203 operator++() {
00204 ++Base::_iterator;
00205 return *this;
00206 }
00207
00209 MemFunIterator
00210 operator++(int) {
00211 MemFunIterator tmp = *this;
00212 ++Base::_iterator;
00213 return tmp;
00214 }
00215
00216
00217
00218
00219
00221 MemFunIterator&
00222 operator--() {
00223 --Base::_iterator;
00224 return *this;
00225 }
00226
00228 MemFunIterator
00229 operator--(int) {
00230 MemFunIterator tmp = *this;
00231 --Base::_iterator;
00232 return tmp;
00233 }
00234
00235
00236
00237
00238
00240 value_type
00241 operator[](const difference_type& n) const {
00242 return Base::_iterator[n]._f();
00243 }
00244
00246 MemFunIterator&
00247 operator+=(const difference_type& n) {
00248 Base::_iterator += n;
00249 return *this;
00250 }
00251
00253 MemFunIterator
00254 operator+(const difference_type& n) const {
00255 MemFunIterator x(*this);
00256 x += n;
00257 return x;
00258 }
00259
00261 MemFunIterator&
00262 operator-=(const difference_type& n) {
00263 Base::_iterator -= n;
00264 return *this;
00265 }
00266
00268 MemFunIterator
00269 operator-(const difference_type& n) const {
00270 MemFunIterator x(*this);
00271 x -= n;
00272 return x;
00273 }
00274
00276 };
00277
00278
00279
00280
00281
00283
00286 template<typename Iterator, class Pointee, typename Result, bool Const>
00287 inline
00288 MemFunIterator<Iterator,Pointee,Result,Const>
00289 operator+(typename MemFunIterator<Iterator,Pointee,Result,Const>::
00290 difference_type n,
00291 const MemFunIterator<Iterator,Pointee,Result,Const>& x) {
00292 return x + n;
00293 }
00294
00295
00296 #if 0
00297
00298
00301 template<typename _Iterator, typename Result>
00302 inline
00303 MemFunIterator<_Iterator,Result>
00304 constructMemFunIterator
00305 (Result ((typename MemFunIterator<_Iterator,Result>::pointee_type)::*f)()) {
00306 return MemFunIterator<_Iterator,Result>(f);
00307 }
00308
00310
00313 template<typename _Iterator, typename Result>
00314 inline
00315 MemFunIterator<_Iterator,Result>
00316 constructMemFunIterator
00317 (Result ((typename MemFunIterator<_Iterator,Result>::pointee_type)::*f)(),
00318 const _Iterator& i) {
00319 return MemFunIterator<_Iterator,Result>(f, i);
00320 }
00321 #endif
00322
00323 END_NAMESPACE_ADS
00324
00325 #endif