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
00026
00027 #ifndef POINTERATOR_H
00028 #define POINTERATOR_H
00029
00030 #ifndef NO_PARTIAL_SPECIALIZATION
00031 #include <iterator>
00032 #else
00033 #include <cstddef>
00034 #endif
00035
00036 #ifndef NO_PARTIAL_SPECIALIZATION
00037 template <typename Iter>
00038 #else
00039 template <typename Iter, typename Val>
00040 #endif // NO_PARTIAL_SPECIALIZATION
00041 class pointerator
00042 {
00043 public:
00044
00045 #ifndef NO_PARTIAL_SPECIALIZATION
00046 typedef pointerator<Iter> its_type;
00047 template <typename T> struct dereference {typedef void type;};
00048 template <typename T> struct dereference<T*> {typedef T type;};
00049 typedef typename dereference<typename Iter::value_type>::type Val;
00050 typedef typename std::iterator_traits<Iter>::iterator_category iterator_category;
00051 typedef typename std::iterator_traits<Iter>::difference_type difference_type;
00052 #else
00053 typedef pointerator<Iter,Val> its_type;
00054 typedef ptrdiff_t difference_type;
00055 #endif // NO_PARTIAL_SPECIALIZATION
00056
00057 typedef Val value_type;
00058 typedef Val& reference;
00059 typedef const Val& const_reference;
00060 typedef Val* pointer;
00061 typedef const Val* const_pointer;
00062
00063 pointerator() {}
00064 pointerator(Iter i) : itsIter(i) {}
00065 Iter get_iterator() const {return itsIter;}
00066
00067 reference operator*() const {return **itsIter;}
00068 pointer operator->() const {return *itsIter;}
00069 reference operator[](difference_type n) const {return **itsIter[n];}
00070
00071 its_type& operator++() {++itsIter; return *this;}
00072 its_type& operator--() {--itsIter; return *this;}
00073 its_type operator++(int) {its_type t(*this); ++itsIter; return t;}
00074 its_type operator--(int) {its_type t(*this); --itsIter; return t;}
00075 its_type& operator+=(difference_type n) {itsIter+=n; return *this;}
00076 its_type& operator-=(difference_type n) {itsIter-=n; return *this;}
00077 its_type operator+(difference_type n) const {return its_type(itsIter+n);}
00078 its_type operator-(difference_type n) const {return its_type(itsIter-n);}
00079
00080 bool operator==(const its_type& r) const {return itsIter == r.itsIter;}
00081 bool operator!=(const its_type& r) const {return itsIter != r.itsIter;}
00082 bool operator<(const its_type& r) const {return itsIter < r.itsIter;}
00083
00084 private:
00085 Iter itsIter;
00086 };
00087
00088 #ifndef NO_PARTIAL_SPECIALIZATION
00089 # define POINTERATOR pointerator<Iter>
00090 # define TEMPLATE_ARGS template <typename Iter>
00091 #else
00092 # define POINTERATOR pointerator<Iter, T>
00093 # define TEMPLATE_ARGS template <typename Iter, typename T>
00094 #endif
00095
00096 TEMPLATE_ARGS inline POINTERATOR
00097 operator+(POINTERATOR ::difference_type n, const POINTERATOR& r)
00098 {
00099 return POINTERATOR(x.get_iterator() - n);
00100 }
00101
00102 TEMPLATE_ARGS inline POINTERATOR ::difference_type
00103 operator-(const POINTERATOR& l, const POINTERATOR& r)
00104 {
00105 return l.get_iterator() - r.get_iterator();
00106 }
00107
00108 TEMPLATE_ARGS inline POINTERATOR
00109 make_pointerator(Iter it)
00110 {
00111 return POINTERATOR(it);
00112 }
00113
00114 #undef POINTERATOR
00115 #undef TEMPLATE_ARGS
00116
00117 #endif // POINTERATOR_H