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