00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #ifndef __VGTL_INTADAPT_H_
00032 #define __VGTL_INTADAPT_H_
00033
00034 #include <vgtl_helpers.h>
00035
00036 __VGTL_BEGIN_NAMESPACE
00037
00038
00040
00046 template <class _Compare>
00047 class pointer_adaptor : public _Compare
00048 {
00049 private:
00050 typedef pointer_adaptor<_Compare> _Self;
00051 typedef typename _Compare::first_argument_type __a1;
00052 typedef typename _Compare::second_argument_type __a2;
00053
00054 public:
00056
00057 typedef __a1* first_argument_type;
00058 typedef __a2* second_argument_type;
00059 typedef typename _Compare::result_type result_type;
00061
00062 public:
00064 result_type operator()(__a1* arg1, __a2* arg2) const
00065 { return _Compare(*arg1, *arg2); }
00066 };
00067
00069
00077 template <class _Iterator>
00078 class pair_adaptor
00079 {
00080 private:
00081 typedef pair_adaptor<_Iterator> _Self;
00082
00083 public:
00085
00086 typedef typename std::iterator_traits<_Iterator>::iterator_category iterator_category;
00087 typedef typename std::iterator_traits<_Iterator>::difference_type difference_type;
00088 typedef typename std::iterator_traits<_Iterator>::value_type p_value_type;
00089 typedef typename std::iterator_traits<_Iterator>::pointer p_pointer;
00090 typedef typename std::iterator_traits<_Iterator>::reference p_reference;
00091
00092 typedef typename p_value_type::second_type value_type;
00093 typedef value_type& reference;
00094 typedef value_type* pointer;
00096
00098
00099 typedef typename p_value_type::first_type key_type;
00100 typedef key_type& key_reference;
00101 typedef key_type* key_pointer;
00103
00104 typedef _Iterator iterator_type;
00105 protected:
00107 _Iterator current;
00108
00109 public:
00111 pair_adaptor() : current() {}
00113 explicit pair_adaptor(iterator_type __x) : current(__x) {}
00114
00116 pair_adaptor(const _Self& __x) : current(__x.current) {}
00117
00118 #ifdef __VGTL_MEMBER_TEMPLATES
00120 template <class _Iter>
00121 pair_adaptor(const pair_adaptor<_Iter>& __x)
00122 : current(__x.base()) {}
00123 #endif
00124
00126 iterator_type base() const { return current; }
00127
00129 reference operator*() const {
00130 _Iterator __tmp = current;
00131 return (*__tmp).second;
00132 }
00133 #ifndef __SGI_STL_NO_ARROW_OPERATOR
00135 pointer operator->() const { return &(operator*()); }
00136 #endif
00137
00139
00140 _Self& operator++() {
00141 ++current;
00142 return *this;
00143 }
00144 _Self operator++(int) {
00145 _Self __tmp = *this;
00146 ++current;
00147 return __tmp;
00148 }
00149 _Self& operator--() {
00150 --current;
00151 return *this;
00152 }
00153 _Self operator--(int) {
00154 _Self __tmp = *this;
00155 --current;
00156 return __tmp;
00157 }
00159
00161
00162 _Self operator+(difference_type __n) const {
00163 return _Self(current + __n);
00164 }
00165
00166 _Self& operator+=(difference_type __n) {
00167 current += __n;
00168 return *this;
00169 }
00170 _Self operator-(difference_type __n) const {
00171 return _Self(current - __n);
00172 }
00173 _Self& operator-=(difference_type __n) {
00174 current -= __n;
00175 return *this;
00176 }
00177 reference operator[](difference_type __n) const { return *(*this + __n); }
00179
00181 key_reference operator~() const {
00182 _Iterator __tmp = current;
00183 return (*__tmp).first;
00184 }
00185
00187 _Self& operator=(const iterator_type& __x) {
00188 current = __x;
00189 return *this;
00190 }
00191
00193
00194 bool operator==(const iterator_type& __x) { return current == __x; }
00195 bool operator!=(const iterator_type& __x) { return current != __x; }
00197 };
00198
00200
00209 template <class _Tp>
00210 class __one_iterator
00211 {
00212 private:
00213 typedef __one_iterator<_Tp> _Self;
00214
00215 public:
00217
00218 typedef std::random_access_iterator_tag iterator_category;
00219 typedef ptrdiff_t difference_type;
00220 typedef _Tp value_type;
00221 typedef value_type* pointer;
00222 typedef value_type& reference;
00224
00225 protected:
00227 pointer __value_;
00229 bool __at;
00230
00231 public:
00233 __one_iterator() : __value_(NULL), __at(false) {}
00235 explicit __one_iterator(const value_type* __x)
00236 { __value_ = __x; __at = true; }
00237
00239 __one_iterator(const _Self& __x) : __value_(__x.__value_), __at(__x.__at) {}
00241 __one_iterator(const pointer& __v, bool __a) : __value_(__v), __at(__a) {}
00242
00244 reference operator*() const {
00245 if(__at)
00246 return *__value_;
00247 else
00248 return _Tp();
00249 }
00250
00252
00253 _Self& operator++() {
00254 if(__at) __at = false;
00255 return *this;
00256 }
00257 _Self operator++(int) {
00258 _Self __tmp = *this;
00259 if(__at) __at = false;
00260 return __tmp;
00261 }
00262 _Self& operator--() {
00263 if(!__at) __at = true;
00264 return *this;
00265 }
00266 _Self operator--(int) {
00267 _Self __tmp = *this;
00268 if(!__at) __at = true;
00269 return __tmp;
00270 }
00271
00272 _Self operator+(difference_type __n) const {
00273 bool __h = __at;
00274 if(__h && __n != 0) __h = false;
00275 return _Self(__value_, __h);
00276 }
00277
00278 _Self& operator+=(difference_type __n) {
00279 if(__at && __n != 0) __at = false;
00280 return *this;
00281 }
00282 _Self operator-(difference_type __n) const {
00283 bool __h = __at;
00284 if(!__h && __n == 1) __h = true;
00285 return _Self(__value_, __h);
00286 }
00287 _Self& operator-=(difference_type __n) {
00288 if(!__at && __n == 0) __at = true;
00289 return *this;
00290 }
00291 reference operator[](difference_type __n) const
00292 { if(__n == 0) return *__value_;
00293 return NULL;
00294 }
00296
00298
00299 bool operator==(const _Self& __x)
00300 { return (__value_ == NULL && !__x.__at) ||
00301 (__x.__value_ == NULL && !__at) ||
00302 (__value_ == __x.__value_ && __at == __x.__at); }
00303 bool operator!=(const _Self& __x)
00304 { return (__value_ != NULL || __x.__at) &&
00305 (__x.__value_ != NULL || __at) &&
00306 (__value_ != __x.__value_ || __at != __x.__at); }
00308 };
00309
00311
00316 template <class Predicate, class _Node>
00317 class _G_compare_adaptor : public std::binary_function<const void *, const void *, bool>
00318 {
00319 protected:
00320 Predicate pred;
00321
00322 typedef _Node* node_ptr;
00323 public:
00325 _G_compare_adaptor(const Predicate& __p) : pred(__p) {}
00326
00328 bool operator() (const void *r, const void *l) const
00329 {
00330 return pred(((node_ptr) r)->_C_data, ((node_ptr) l)->_C_data);
00331 }
00332 };
00333
00334 __VGTL_END_NAMESPACE
00335
00336 #endif