SkelGIS
3.0
|
00001 /*! \file iterator_line.hpp 00002 * \brief line iterator object definition. Two template specializations. This iterator gives the possibility to read elements of a DMAtrix line by line. Users do not have to construct an iterator object directly (these objects are constructed in the DMatrix) however operators and methods of the iterator are used by the user. 00003 */ 00004 #ifndef ITERATOR_LINE_H 00005 #define ITERATOR_LINE_H 00006 00007 #include "iterator_cont.hpp" 00008 #include "iterator.hpp" 00009 00010 namespace skelgis{ 00011 00012 //================================================================================ 00013 //! Iterator class 00014 /*! 00015 template of the line iterator of SkelGIS. This is the first specialization of line iterator class. 00016 \tparam T is the type of data stored in the DMatrix to manipulate with the iterator 00017 \tparam R is the overlap distance needed by the calculation, and the same overlap than in the DMatrix to manipulate with this iterator. 00018 */ 00019 //------------------------------------------------------------------------------- 00020 template<class T,int R> struct iterator_line 00021 //------------------------------------------------------------------------------- 00022 { 00023 public: 00024 unsigned int _rank; /*!< current rank of the iterator */ 00025 unsigned int _width; /*!< width of the DMatrix associated to this iterator */ 00026 00027 //! default constructor of the iterator 00028 //------------------------------------------------------------------------------- 00029 iterator_line():_rank(0),_width(0){} 00030 //------------------------------------------------------------------------------- 00031 //! constructor of the iterator 00032 /*! 00033 \param r is the initial rank to assign to the iterator 00034 \param w is the DMatrix width to assign to the iterator 00035 */ 00036 //------------------------------------------------------------------------------- 00037 iterator_line(const unsigned int r,const unsigned int w):_rank(r),_width(w){} 00038 //------------------------------------------------------------------------------- 00039 //! constructor of the iterator from another iterator 00040 /*! 00041 \param it is the other iterator instance from which to construct the new one 00042 */ 00043 //------------------------------------------------------------------------------- 00044 iterator_line(const iterator_line<T,R>& it):_rank(it._rank),_width(it._width){} 00045 //------------------------------------------------------------------------------- 00046 //! Destructor of the iterator 00047 //------------------------------------------------------------------------------- 00048 ~iterator_line(){} 00049 //------------------------------------------------------------------------------- 00050 //! operator ++ pre-incrementation of the iterator 00051 /*! 00052 This operation increments the position of the iterator in the DMatrix. 00053 \return a reference to the resulting iterator itself 00054 */ 00055 //------------------------------------------------------------------------------- 00056 iterator_line<T,R>& operator++() 00057 //------------------------------------------------------------------------------- 00058 { 00059 _rank = _rank + _width; 00060 return *this; 00061 } 00062 //------------------------------------------------------------------------------- 00063 //! operator ++ post-incrementation of the iterator 00064 /*! 00065 This operation increments the position of the iterator in the DMatrix. 00066 \return a reference to the resulting iterator itself 00067 */ 00068 //------------------------------------------------------------------------------- 00069 iterator_line<T,R>& operator++(int) 00070 //------------------------------------------------------------------------------- 00071 { 00072 iterator_line<T,R> _tmp = *this; 00073 _rank = _rank + _width; 00074 return _tmp; 00075 } 00076 //------------------------------------------------------------------------------- 00077 //! operator -- pre-decrementation of the iterator 00078 /*! 00079 This operation decrements the position of the iterator in the DMatrix. 00080 \return a reference to the resulting iterator itself 00081 */ 00082 //------------------------------------------------------------------------------- 00083 iterator_line<T,R>& operator--() 00084 //------------------------------------------------------------------------------- 00085 { 00086 _rank = _rank - _width; 00087 return *this; 00088 } 00089 //------------------------------------------------------------------------------- 00090 //! operator -- post-decrementation of the iterator 00091 /*! 00092 This operation decrements the position of the iterator in the DMatrix. 00093 \return a reference to the resulting iterator itself 00094 */ 00095 //------------------------------------------------------------------------------- 00096 iterator_line<T,R>& operator--(int) 00097 //------------------------------------------------------------------------------- 00098 { 00099 iterator_line<T,R> _tmp = *this; 00100 _rank = _rank - _width; 00101 return _tmp; 00102 } 00103 //------------------------------------------------------------------------------- 00104 //! operator = of the iterator 00105 /*! 00106 This operation assigns another iterator informations to the current one. 00107 \return a reference to the resulting iterator itself 00108 */ 00109 //------------------------------------------------------------------------------- 00110 inline iterator_line<T,R>& operator=(iterator_line<T,R> right) 00111 //------------------------------------------------------------------------------- 00112 { 00113 _rank = right._rank; 00114 _width = right._width; 00115 return *this; 00116 } 00117 //------------------------------------------------------------------------------- 00118 //! operator == of the iterator 00119 /*! 00120 This operation checks the equality of two iterators with their rank values. 00121 \return true if the two iterator have the same rank. False otherwize. 00122 */ 00123 //------------------------------------------------------------------------------- 00124 inline bool operator==(const iterator_line<T,R>& toTest) {return _rank==toTest._rank;} 00125 //------------------------------------------------------------------------------- 00126 //! operator != of the iterator 00127 /*! 00128 This operation checks the inequality of two iterators with their rank values. 00129 \return true if the two iterator do not have the same rank. False otherwize. 00130 */ 00131 //------------------------------------------------------------------------------- 00132 inline bool operator!=(const iterator_line<T,R>& toTest) {return _rank!=toTest._rank;} 00133 //------------------------------------------------------------------------------- 00134 //! operator <= of the iterator 00135 /*! 00136 This operation checks if the current iterator rank is smaller or equal to the other one. 00137 \return true is the current iterator rank is smaller or equal. False otherwize. 00138 */ 00139 //------------------------------------------------------------------------------- 00140 inline bool operator <=(const iterator_line<T,R>& toComp) {return _rank<=toComp._rank;} 00141 //------------------------------------------------------------------------------- 00142 //! operator < of the iterator 00143 /*! 00144 This operation checks if the current iterator rank is smaller than the other one. 00145 \return true is the current iterator rank is smaller. False otherwize. 00146 */ 00147 //------------------------------------------------------------------------------- 00148 inline bool operator <(const iterator_line<T,R>& toComp) {return _rank<toComp._rank;} 00149 //------------------------------------------------------------------------------- 00150 //! operator >= of the iterator 00151 /*! 00152 This operation checks if the current iterator rank is biger or equal to the other one. 00153 \return true is the current iterator rank is biger or equal. False otherwize. 00154 */ 00155 //------------------------------------------------------------------------------- 00156 inline bool operator >=(const iterator_line<T,R>& toComp) {return _rank>=toComp._rank;} 00157 //------------------------------------------------------------------------------- 00158 //! operator > of the iterator 00159 /*! 00160 This operation checks if the current iterator rank is biger than the other one. 00161 \return true is the current iterator rank is biger. False otherwize. 00162 */ 00163 //------------------------------------------------------------------------------- 00164 inline bool operator >(const iterator_line<T,R>& toComp) {return _rank>toComp._rank;} 00165 //------------------------------------------------------------------------------- 00166 //! begin method of the line iterator 00167 /*! 00168 This method returns an iterator on the first element of the current line of the DMatrix. This iterator is then used until the end() method of the line iterator is reached. 00169 \return an iterator on the first element of the current line on the DMatrix 00170 */ 00171 //------------------------------------------------------------------------------- 00172 inline iterator<T,R> begin(){return iterator<T,R>(_rank,_width);} 00173 //------------------------------------------------------------------------------- 00174 //! begin_cont method of the line iterator 00175 /*! 00176 This method returns an iterator contiguous on the first element of the current line of the DMatrix. This iterator is then used until the end() method of the line iterator is reached. 00177 \return an iterator_cont on the first element of the current line on the DMatrix 00178 */ 00179 //------------------------------------------------------------------------------- 00180 inline iterator_cont<T,R> begin_cont(){return iterator_cont<T,R>(_rank,_width);} 00181 //------------------------------------------------------------------------------- 00182 //! end method of the line iterator 00183 /*! 00184 This method returns the end iterator on the current line of the DMatrix. 00185 \return the end iterator of the current line on the DMatrix 00186 */ 00187 //------------------------------------------------------------------------------- 00188 inline iterator<T,R> end(){return iterator<T,R>(_rank+_width-2*R-1,_width);} 00189 //------------------------------------------------------------------------------- 00190 //! end_cont method of the line iterator 00191 /*! 00192 This method returns the end contiguous iterator on the current line of the DMatrix. 00193 \return the end_cont iterator of the current line on the DMatrix 00194 */ 00195 //------------------------------------------------------------------------------- 00196 inline iterator_cont<T,R> end_cont(){return iterator_cont<T,R>(_rank+_width-2*R-1,_width);} 00197 //------------------------------------------------------------------------------- 00198 }; 00199 00200 //================================================================================ 00201 //! Iterator class 00202 /*! 00203 template of the line iterator of SkelGIS. This is the first specialization of line iterator class. 00204 \tparam T is the type of data stored in the DMatrix to manipulate with the iterator 00205 R is specialized with the value 0 00206 */ 00207 //------------------------------------------------------------------------------- 00208 template<class T> struct iterator_line<T,0> 00209 //------------------------------------------------------------------------------- 00210 { 00211 public: 00212 unsigned int _rank; /*!< current rank of the iterator */ 00213 unsigned int _width; /*!< width of the DMatrix associated to this iterator */ 00214 00215 //! default constructor of the iterator 00216 //------------------------------------------------------------------------------- 00217 iterator_line():_rank(0),_width(0){} 00218 //------------------------------------------------------------------------------- 00219 //! constructor of the iterator 00220 /*! 00221 \param r is the initial rank to assign to the iterator 00222 \param w is the DMatrix width to assign to the iterator 00223 */ 00224 //------------------------------------------------------------------------------- 00225 iterator_line(const unsigned int r,const unsigned int w):_rank(r),_width(w){} 00226 //------------------------------------------------------------------------------- 00227 //! constructor of the iterator from another iterator 00228 /*! 00229 \param it is the other iterator instance from which to construct the new one 00230 */ 00231 //------------------------------------------------------------------------------- 00232 iterator_line(const iterator_line<T,0>& it):_rank(it._rank),_width(it._width){} 00233 //------------------------------------------------------------------------------- 00234 //! Destructor of the iterator 00235 //------------------------------------------------------------------------------- 00236 ~iterator_line(){} 00237 //------------------------------------------------------------------------------- 00238 //! operator ++ pre-incrementation of the iterator 00239 /*! 00240 This operation increments the position of the iterator in the DMatrix. 00241 \return a reference to the resulting iterator itself 00242 */ 00243 //------------------------------------------------------------------------------- 00244 iterator_line<T,0>& operator++() 00245 //------------------------------------------------------------------------------- 00246 { 00247 _rank = _rank + _width; 00248 return *this; 00249 } 00250 //------------------------------------------------------------------------------- 00251 //! operator ++ post-incrementation of the iterator 00252 /*! 00253 This operation increments the position of the iterator in the DMatrix. 00254 \return a reference to the resulting iterator itself 00255 */ 00256 //------------------------------------------------------------------------------- 00257 iterator_line<T,0>& operator++(int) 00258 //------------------------------------------------------------------------------- 00259 { 00260 iterator_line<T,0> _tmp = *this; 00261 _rank = _rank + _width; 00262 return _tmp; 00263 } 00264 //------------------------------------------------------------------------------- 00265 //! operator -- pre-decrementation of the iterator 00266 /*! 00267 This operation decrements the position of the iterator in the DMatrix. 00268 \return a reference to the resulting iterator itself 00269 */ 00270 //------------------------------------------------------------------------------- 00271 iterator_line<T,0>& operator--() 00272 //------------------------------------------------------------------------------- 00273 { 00274 _rank = _rank - _width; 00275 return *this; 00276 } 00277 //------------------------------------------------------------------------------- 00278 //! operator -- post-decrementation of the iterator 00279 /*! 00280 This operation decrements the position of the iterator in the DMatrix. 00281 \return a reference to the resulting iterator itself 00282 */ 00283 //------------------------------------------------------------------------------- 00284 iterator_line<T,0>& operator--(int) 00285 //------------------------------------------------------------------------------- 00286 { 00287 iterator_line<T,0> _tmp = *this; 00288 _rank = _rank - _width; 00289 return _tmp; 00290 } 00291 //------------------------------------------------------------------------------- 00292 //! operator = of the iterator 00293 /*! 00294 This operation assigns another iterator informations to the current one. 00295 \return a reference to the resulting iterator itself 00296 */ 00297 //------------------------------------------------------------------------------- 00298 inline iterator_line<T,0>& operator=(iterator_line<T,0> right) 00299 //------------------------------------------------------------------------------- 00300 { 00301 _rank = right._rank; 00302 _width = right._width; 00303 return *this; 00304 } 00305 //------------------------------------------------------------------------------- 00306 //! operator == of the iterator 00307 /*! 00308 This operation checks the equality of two iterators with their rank values. 00309 \return true if the two iterator have the same rank. False otherwize. 00310 */ 00311 //------------------------------------------------------------------------------- 00312 inline bool operator==(const iterator_line<T,0>& toTest) {return _rank==toTest._rank;} 00313 //------------------------------------------------------------------------------- 00314 //! operator != of the iterator 00315 /*! 00316 This operation checks the inequality of two iterators with their rank values. 00317 \return true if the two iterator do not have the same rank. False otherwize. 00318 */ 00319 //------------------------------------------------------------------------------- 00320 inline bool operator!=(const iterator_line<T,0>& toTest) {return _rank!=toTest._rank;} 00321 //------------------------------------------------------------------------------- 00322 //! operator <= of the iterator 00323 /*! 00324 This operation checks if the current iterator rank is smaller or equal to the other one. 00325 \return true is the current iterator rank is smaller or equal. False otherwize. 00326 */ 00327 //------------------------------------------------------------------------------- 00328 inline bool operator <=(const iterator_line<T,0>& toComp) {return _rank<=toComp._rank;} 00329 //------------------------------------------------------------------------------- 00330 //! operator < of the iterator 00331 /*! 00332 This operation checks if the current iterator rank is smaller than the other one. 00333 \return true is the current iterator rank is smaller. False otherwize. 00334 */ 00335 //------------------------------------------------------------------------------- 00336 inline bool operator <(const iterator_line<T,0>& toComp) {return _rank<toComp._rank;} 00337 //------------------------------------------------------------------------------- 00338 //! operator >= of the iterator 00339 /*! 00340 This operation checks if the current iterator rank is biger or equal to the other one. 00341 \return true is the current iterator rank is biger or equal. False otherwize. 00342 */ 00343 //------------------------------------------------------------------------------- 00344 inline bool operator >=(const iterator_line<T,0>& toComp) {return _rank>=toComp._rank;} 00345 //------------------------------------------------------------------------------- 00346 //! operator > of the iterator 00347 /*! 00348 This operation checks if the current iterator rank is biger than the other one. 00349 \return true is the current iterator rank is biger. False otherwize. 00350 */ 00351 //------------------------------------------------------------------------------- 00352 inline bool operator >(const iterator_line<T,0>& toComp) {return _rank>toComp._rank;} 00353 //------------------------------------------------------------------------------- 00354 //! begin method of the line iterator 00355 /*! 00356 This method returns an iterator on the first element of the current line of the DMatrix. This iterator is then used until the end() method of the line iterator is reached. 00357 \return an iterator on the first element of the current line on the DMatrix 00358 */ 00359 //------------------------------------------------------------------------------- 00360 inline iterator<T,0> begin(){return iterator<T,0>(_rank);} 00361 //------------------------------------------------------------------------------- 00362 //! begin_cont method of the line iterator 00363 /*! 00364 This method returns an iterator contiguous on the first element of the current line of the DMatrix. This iterator is then used until the end() method of the line iterator is reached. 00365 \return an iterator_cont on the first element of the current line on the DMatrix 00366 */ 00367 //------------------------------------------------------------------------------- 00368 inline iterator_cont<T,0> begin_cont(){return iterator_cont<T,0>(_rank);} 00369 //------------------------------------------------------------------------------- 00370 //! end method of the line iterator 00371 /*! 00372 This method returns the end iterator on the current line of the DMatrix. 00373 \return the end iterator of the current line on the DMatrix 00374 */ 00375 //------------------------------------------------------------------------------- 00376 inline iterator<T,0> end(){return iterator<T,0>(_rank+_width-1);} 00377 //------------------------------------------------------------------------------- 00378 //! end_cont method of the line iterator 00379 /*! 00380 This method returns the end contiguous iterator on the current line of the DMatrix. 00381 \return the end_cont iterator of the current line on the DMatrix 00382 */ 00383 //------------------------------------------------------------------------------- 00384 inline iterator_cont<T,0> end_cont(){return iterator_cont<T,0>(_rank+_width-1);} 00385 //------------------------------------------------------------------------------- 00386 }; 00387 00388 } 00389 00390 #endif