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