00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef __VGTL_INTADAPT_H_
00031 #define __VGTL_INTADAPT_H_
00032
00033 #include <vgtl_helpers.h>
00034
00035 __VGTL_BEGIN_NAMESPACE
00036
00037
00039
00045 template <class _Compare>
00046 class pointer_adaptor : public _Compare
00047 {
00048 private:
00049 typedef pointer_adaptor<_Compare> _Self;
00050 typedef typename _Compare::first_argument_type __a1;
00051 typedef typename _Compare::second_argument_type __a2;
00052
00053 public:
00055
00056 typedef __a1* first_argument_type;
00057 typedef __a2* second_argument_type;
00058 typedef typename _Compare::result_type result_type;
00060
00061 public:
00063 result_type operator()(__a1* arg1, __a2* arg2) const
00064 { return _Compare(*arg1, *arg2); }
00065 };
00066
00068
00076 template <class _Iterator>
00077 class pair_adaptor
00078 {
00079 private:
00080 typedef pair_adaptor<_Iterator> _Self;
00081
00082 public:
00084
00085 typedef typename std::iterator_traits<_Iterator>::iterator_category iterator_category;
00086 typedef typename std::iterator_traits<_Iterator>::difference_type difference_type;
00087 typedef typename std::iterator_traits<_Iterator>::value_type p_value_type;
00088 typedef typename std::iterator_traits<_Iterator>::pointer p_pointer;
00089 typedef typename std::iterator_traits<_Iterator>::reference p_reference;
00090
00091 typedef typename p_value_type::second_type value_type;
00092 typedef value_type& reference;
00093 typedef value_type* pointer;
00095
00097
00098 typedef typename p_value_type::first_type key_type;
00099 typedef key_type& key_reference;
00100 typedef key_type* key_pointer;
00102
00103 typedef _Iterator iterator_type;
00104 protected:
00106 _Iterator current;
00107
00108 public:
00110 pair_adaptor() : current() {}
00112 explicit pair_adaptor(iterator_type __x) : current(__x) {}
00113
00115 pair_adaptor(const _Self& __x) : current(__x.current) {}
00116
00117 #ifdef __VGTL_MEMBER_TEMPLATES
00118
00119 template <class _Iter>
00120 pair_adaptor(const pair_adaptor<_Iter>& __x)
00121 : current(__x.base()) {}
00122 #endif
00123
00125 iterator_type base() const { return current; }
00126
00128 reference operator*() const {
00129 _Iterator __tmp = current;
00130 return (*__tmp).second;
00131 }
00132 #ifndef __SGI_STL_NO_ARROW_OPERATOR
00133
00134 pointer operator->() const { return &(operator*()); }
00135 #endif
00136
00138
00139 _Self& operator++() {
00140 ++current;
00141 return *this;
00142 }
00143 _Self operator++(int) {
00144 _Self __tmp = *this;
00145 ++current;
00146 return __tmp;
00147 }
00148 _Self& operator--() {
00149 --current;
00150 return *this;
00151 }
00152 _Self operator--(int) {
00153 _Self __tmp = *this;
00154 --current;
00155 return __tmp;
00156 }
00158
00160
00161 _Self operator+(difference_type __n) const {
00162 return _Self(current + __n);
00163 }
00164
00165 _Self& operator+=(difference_type __n) {
00166 current += __n;
00167 return *this;
00168 }
00169 _Self operator-(difference_type __n) const {
00170 return _Self(current - __n);
00171 }
00172 _Self& operator-=(difference_type __n) {
00173 current -= __n;
00174 return *this;
00175 }
00176 reference operator[](difference_type __n) const { return *(*this + __n); }
00178
00180 key_reference operator~() const {
00181 _Iterator __tmp = current;
00182 return (*__tmp).first;
00183 }
00184
00186 _Self& operator=(const iterator_type& __x) {
00187 current = __x;
00188 return *this;
00189 }
00190
00192
00193 bool operator==(const iterator_type& __x) { return current == __x; }
00194 bool operator!=(const iterator_type& __x) { return current != __x; }
00196 };
00197
00199
00208 template <class _Tp>
00209 class __one_iterator
00210 {
00211 private:
00212 typedef __one_iterator<_Tp> _Self;
00213
00214 public:
00216
00217 typedef std::random_access_iterator_tag iterator_category;
00218 typedef ptrdiff_t difference_type;
00219 typedef _Tp value_type;
00220 typedef value_type* pointer;
00221 typedef value_type& reference;
00223
00224 protected:
00226 pointer __value;
00228 bool __at;
00229
00230 public:
00232 __one_iterator() : __value(NULL), __at(false) {}
00234 explicit __one_iterator(const value_type* __x)
00235 { __value = __x; __at = true; }
00236
00238 __one_iterator(const _Self& __x) : __value(__x.__value), __at(__x.__at) {}
00240 __one_iterator(const pointer& __v, bool __a) : __value(__v), __at(__a) {}
00241
00243 reference operator*() const {
00244 if(__at)
00245 return *__value;
00246 else
00247 return _Tp();
00248 }
00249
00251
00252 _Self& operator++() {
00253 if(__at) __at = false;
00254 return *this;
00255 }
00256 _Self operator++(int) {
00257 _Self __tmp = *this;
00258 if(__at) __at = false;
00259 return __tmp;
00260 }
00261 _Self& operator--() {
00262 if(!__at) __at = true;
00263 return *this;
00264 }
00265 _Self operator--(int) {
00266 _Self __tmp = *this;
00267 if(!__at) __at = true;
00268 return __tmp;
00269 }
00270
00271 _Self operator+(difference_type __n) const {
00272 bool __h = __at;
00273 if(__h && __n != 0) __h = false;
00274 return _Self(__value, __h);
00275 }
00276
00277 _Self& operator+=(difference_type __n) {
00278 if(__at && __n != 0) __at = false;
00279 return *this;
00280 }
00281 _Self operator-(difference_type __n) const {
00282 bool __h = __at;
00283 if(!__h && __n == 1) __h = true;
00284 return _Self(__value, __h);
00285 }
00286 _Self& operator-=(difference_type __n) {
00287 if(!__at && __n == 0) __at = true;
00288 return *this;
00289 }
00290 reference operator[](difference_type __n) const
00291 { if(__n == 0) return *__value;
00292 return NULL;
00293 }
00295
00297
00298 bool operator==(const _Self& __x)
00299 { return (__value == NULL && !__x.__at) ||
00300 (__x.__value == NULL && !__at) ||
00301 (__value == __x.__value && __at == __x.__at); }
00302 bool operator!=(const _Self& __x)
00303 { return (__value != NULL || __x.__at) &&
00304 (__x.__value != NULL || __at) &&
00305 (__value != __x.__value || __at != __x.__at); }
00307 };
00308
00310
00315 template <class Predicate, class _Node>
00316 class _G_compare_adaptor : public std::binary_function<const void *, const void *, bool>
00317 {
00318 protected:
00319 Predicate pred;
00320
00321 typedef _Node* node_ptr;
00322 public:
00324 _G_compare_adaptor(const Predicate& __p) : pred(__p) {}
00325
00327 bool operator() (const void *r, const void *l) const
00328 {
00329 return pred(((node_ptr) r)->_C_data, ((node_ptr) l)->_C_data);
00330 }
00331 };
00332
00333 __VGTL_END_NAMESPACE
00334
00335 #endif