00001
00002
00008 #if !defined(__ads_iterator_AdaptedIterator_h__)
00009 #define __ads_iterator_AdaptedIterator_h__
00010
00011 #include "../defs.h"
00012
00013 #include <iterator>
00014
00015 BEGIN_NAMESPACE_ADS
00016
00018 template<typename _Iterator,
00019 typename IteratorCategory,
00020 typename ValueType,
00021 typename DifferenceType,
00022 typename Pointer,
00023 typename Reference>
00024 class AdaptedIterator :
00025 public std::iterator<IteratorCategory,
00026 ValueType,
00027 DifferenceType,
00028 Pointer,
00029 Reference> {
00030 private:
00031
00032
00033
00034
00035
00036 typedef std::iterator<IteratorCategory,
00037 ValueType,
00038 DifferenceType,
00039 Pointer,
00040 Reference>
00041 Base;
00042
00043 public:
00044
00045
00046
00047
00048
00050 typedef _Iterator Iterator;
00051
00052
00053
00055 typedef typename Base::iterator_category iterator_category;
00057 typedef typename Base::value_type value_type;
00059 typedef typename Base::difference_type difference_type;
00061 typedef typename Base::pointer pointer;
00063 typedef typename Base::reference reference;
00064
00065 protected:
00066
00067
00068
00069
00070
00072 Iterator _iterator;
00073
00074 protected:
00075
00076
00082
00084 AdaptedIterator() :
00085 _iterator()
00086 {}
00087
00089 AdaptedIterator(const AdaptedIterator& x) :
00090 _iterator(x._iterator)
00091 {}
00092
00094 AdaptedIterator&
00095 operator=(const AdaptedIterator& other) {
00096 if (&other != this) {
00097 _iterator = other._iterator;
00098 }
00099 return *this;
00100 }
00101
00103 explicit
00104 AdaptedIterator(const Iterator& i) :
00105 _iterator(i)
00106 {}
00107
00109 AdaptedIterator&
00110 operator=(const Iterator& i) {
00111 _iterator = i;
00112 return *this;
00113 }
00114
00116 ~AdaptedIterator()
00117 {}
00118
00120
00121 public:
00122
00123
00125
00126
00128 const Iterator&
00129 base() const {
00130 return _iterator;
00131 }
00132
00134 };
00135
00136
00137
00138
00139
00140
00141
00143
00146 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00147 typename DifferenceType1, typename Pointer1, typename Reference1,
00148 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00149 typename DifferenceType2, typename Pointer2, typename Reference2>
00150 inline
00151 bool
00152 operator==(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00153 DifferenceType1,Pointer1,Reference1>& x,
00154 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00155 DifferenceType2,Pointer2,Reference2>& y) {
00156 return x.base() == y.base();
00157 }
00158
00159
00161
00164 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00165 typename DifferenceType1, typename Pointer1, typename Reference1,
00166 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00167 typename DifferenceType2, typename Pointer2, typename Reference2>
00168 inline
00169 bool
00170 operator!=(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00171 DifferenceType1,Pointer1,Reference1>& x,
00172 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00173 DifferenceType2,Pointer2,Reference2>& y) {
00174 return ! (x == y);
00175 }
00176
00177
00178
00179
00180
00181
00182
00184
00187 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00188 typename DifferenceType1, typename Pointer1, typename Reference1,
00189 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00190 typename DifferenceType2, typename Pointer2, typename Reference2>
00191 inline
00192 bool
00193 operator<(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00194 DifferenceType1,Pointer1,Reference1>& x,
00195 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00196 DifferenceType2,Pointer2,Reference2>& y) {
00197 return x.base() < y.base();
00198 }
00199
00200
00202
00205 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00206 typename DifferenceType1, typename Pointer1, typename Reference1,
00207 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00208 typename DifferenceType2, typename Pointer2, typename Reference2>
00209 inline
00210 bool
00211 operator>(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00212 DifferenceType1,Pointer1,Reference1>& x,
00213 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00214 DifferenceType2,Pointer2,Reference2>& y) {
00215 return x.base() > y.base();
00216 }
00217
00218
00220
00223 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00224 typename DifferenceType1, typename Pointer1, typename Reference1,
00225 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00226 typename DifferenceType2, typename Pointer2, typename Reference2>
00227 inline
00228 bool
00229 operator<=(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00230 DifferenceType1,Pointer1,Reference1>& x,
00231 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00232 DifferenceType2,Pointer2,Reference2>& y) {
00233 return x.base() <= y.base();
00234 }
00235
00236
00238
00241 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00242 typename DifferenceType1, typename Pointer1, typename Reference1,
00243 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00244 typename DifferenceType2, typename Pointer2, typename Reference2>
00245 inline
00246 bool
00247 operator>=(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00248 DifferenceType1,Pointer1,Reference1>& x,
00249 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00250 DifferenceType2,Pointer2,Reference2>& y) {
00251 return x.base() >= y.base();
00252 }
00253
00254
00256
00259 template<typename Iterator1, typename IteratorCategory1, typename ValueType1,
00260 typename DifferenceType1, typename Pointer1, typename Reference1,
00261 typename Iterator2, typename IteratorCategory2, typename ValueType2,
00262 typename DifferenceType2, typename Pointer2, typename Reference2>
00263 inline
00264 typename AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00265 DifferenceType1,Pointer1,Reference1>::difference_type
00266 operator-(const AdaptedIterator<Iterator1,IteratorCategory1,ValueType1,
00267 DifferenceType1,Pointer1,Reference1>& x,
00268 const AdaptedIterator<Iterator2,IteratorCategory2,ValueType2,
00269 DifferenceType2,Pointer2,Reference2>& y) {
00270 return x.base() - y.base();
00271 }
00272
00273
00274 END_NAMESPACE_ADS
00275
00276 #endif