Changeset 884 for trunk/yat/utility/Iterator.h
 Timestamp:
 Sep 23, 2007, 12:53:38 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/utility/Iterator.h
r883 r884 46 46 47 47 /** 48 @brief Constructor48 \brief Default Constructor 49 49 */ 50 50 Iterator(void) {}; 51 52 /** 53 \brief Constructor 54 55 \param container iterator points to 56 \param index telling which element iterator points to 57 */ 51 58 Iterator(Container& container, difference_type index) 52 59 : container_(&container), index_(index) {} 53 60 61 /** 62 \return element 63 */ 54 64 return_type operator*(void) const { return container_>operator()(index_); } 55 const Iterator& operator++(void) { ++index_; return *this; } 65 66 /** 67 \brief preincrement 68 69 \return reference to *this 70 */ 71 Iterator& operator++(void) { ++index_; return *this; } 72 73 /** 74 \brief postincrement 75 76 \return copy of iterator prior increment 77 */ 56 78 Iterator operator++(int) 57 79 { Iterator<return_type, Container> tmp(*this); ++index_; return tmp;} 80 81 /** 82 \brief iterate \f$ n \f$ steps forward 83 84 \return reference to resulting iterator 85 */ 58 86 Iterator& operator+=(int n) { index_+=n; return *this; } 59 Iterator operator+(int n) 60 { return Iterator<return_type, Container>(*container_, index_+n); } 87 88 /** 89 \brief postdecrement 90 91 \return copy of iterator prior decrement 92 */ 61 93 Iterator operator(int) 62 94 { Iterator<return_type, Container> tmp(*this); index_; return tmp;} 63 Iterator operator(void) { index_; return *this; } 95 96 /** 97 \brief predecrement 98 99 \return reference to resulting iterator 100 */ 101 Iterator& operator(void) { index_; return *this; } 102 103 /** 104 \brief iterate \f$ n \f$ steps backwards 105 106 \return reference to resulting iterator 107 */ 64 108 Iterator& operator=(int n) { index_=n; return *this; } 65 Iterator operator(size_t n) 66 { return Iterator<return_type, Container>(*container_, index_n); } 67 size_t operator(const Iterator& rhs) 68 { return index_rhs.index_; } 69 70 bool less(const Iterator<return_type, Container>& other) const 71 { return index_<other.index_; } 72 109 110 /** 111 \brief addition operator 112 113 \return copy of resulting iterator 114 */ 115 friend Iterator operator+(const Iterator& lhs, size_t n) 116 { return Iterator<return_type, Container>(*lhs.container_, lhs.index_+n); } 117 118 /** 119 \brief subtraction operator 120 121 \return copy of resulting iterator 122 */ 123 friend Iterator operator(const Iterator& lhs, size_t n) 124 { return Iterator<return_type, Container>(*lhs.container_, lhs.index_n); } 125 126 /** 127 \brief difference operator 128 129 \return distance between \a lhs and \a rhs 130 */ 131 friend difference_type operator(const Iterator& lhs, const Iterator& rhs) 132 { return lhs.index_rhs.index_; } 133 134 135 /** 136 \brief Conversion operator 137 138 This operator allows automatic conversion from iterator to 139 const_iterator 140 */ 73 141 operator Iterator<const double, const Container> () 74 142 { return Iterator<const double, const Container>(*container_, index_); } 75 143 76 144 /** 145 \brief Equality operator 146 147 \return True if \a lhs and \rhs are pointing to same element 148 */ 149 friend bool operator==(const Iterator<return_type, Container>& lhs, 150 const Iterator<return_type, Container>& rhs) 151 { return lhs.container_==rhs.container_ && lhs.index_==rhs.index_; } 152 153 /** 154 \brief Nonequality operator 155 156 \return False if \a lhs and \rhs are pointing to same element 157 */ 158 friend bool operator!=(const Iterator<return_type, Container>& lhs, 159 const Iterator<return_type, Container>& rhs) 160 { return !(lhs.container_==rhs.container_ && lhs.index_==rhs.index_); } 161 162 /** 163 \brief Less operator 164 */ 165 friend bool operator<(const Iterator<return_type, Container>& lhs, 166 const Iterator<return_type, Container>& rhs) 167 { return lhs.index_<rhs.index_; } 168 169 /** 170 \brief Less equal operator 171 */ 172 friend bool operator<=(const Iterator<return_type, Container>& lhs, 173 const Iterator<return_type, Container>& rhs) 174 { return lhs.index_<=rhs.index_; } 175 176 /** 177 \brief Larger operator 178 */ 179 friend bool operator>(const Iterator<return_type, Container>& lhs, 180 const Iterator<return_type, Container>& rhs) 181 { return lhs.index_>rhs.index_; } 182 183 /** 184 \brief Larger equal operator 185 */ 186 friend bool operator>=(const Iterator<return_type, Container>& lhs, 187 const Iterator<return_type, Container>& rhs) 188 { return lhs.index_>=rhs.index_; } 189 77 190 private: 78 191 Container* container_; 79 192 size_t index_; 193 80 194 // Using compiler generated copy 81 195 //Iterator(const Iterator&); 82 196 //Iterator& operator=(const Iterator&); 83 84 85 public:86 friend bool operator==(const Iterator<return_type, Container>& lhs,87 const Iterator<return_type, Container>& rhs)88 { return lhs.container_==rhs.container_ && lhs.index_==rhs.index_; }89 90 friend bool operator!=(const Iterator<return_type, Container>& lhs,91 const Iterator<return_type, Container>& rhs)92 { return !(lhs.container_==rhs.container_ && lhs.index_==rhs.index_); }93 94 friend bool operator<(const Iterator<return_type, Container>& lhs,95 const Iterator<return_type, Container>& rhs)96 { return lhs.index_<rhs.index_; }97 98 friend bool operator<=(const Iterator<return_type, Container>& lhs,99 const Iterator<return_type, Container>& rhs)100 { return lhs.index_<=rhs.index_; }101 102 friend bool operator>(const Iterator<return_type, Container>& lhs,103 const Iterator<return_type, Container>& rhs)104 { return lhs.index_>rhs.index_; }105 106 friend bool operator>=(const Iterator<return_type, Container>& lhs,107 const Iterator<return_type, Container>& rhs)108 { return lhs.index_>=rhs.index_; }109 110 111 112 197 }; 113 198 114 /*115 template <typename T1, typename T2>116 bool operator==(const Iterator<T1,T2>& lhs,117 const Iterator<T1,T2>& rhs)118 {119 return lhs.equal(rhs);120 }121 122 template <typename T1, typename T2>123 bool operator!=(const Iterator<T1,T2>& lhs,124 const Iterator<T1,T2>& rhs)125 {126 return !(lhs==rhs);127 }128 129 130 template <typename T1, typename T2>131 bool operator<(const Iterator<T1,T2>& lhs,132 const Iterator<T1,T2>& rhs)133 {134 return lhs<rhs;135 }136 137 138 template <typename T1, typename T2>139 bool operator<=(const Iterator<T1,T2>& lhs,140 const Iterator<T1,T2>& rhs)141 {142 return !(rhs<lhs);143 }144 145 146 template <typename T1, typename T2>147 bool operator>(const Iterator<T1,T2>& lhs,148 const Iterator<T1,T2>& rhs)149 {150 return rhs<lhs;151 }152 153 154 template <typename T1, typename T2>155 bool operator>=(const Iterator<T1,T2>& lhs,156 const Iterator<T1,T2>& rhs)157 {158 return !(lhs<rhs);159 }160 */161 162 199 }}} // of namespace utility, yat, and theplu 163 200
Note: See TracChangeset
for help on using the changeset viewer.