SkelGIS  3.0
/home/helene/Documents/These/SkelGIS/SkelGIS_Library/SkelGIS_V3/skelgis/iterators/DMatrix/iterator_cont.hpp
Go to the documentation of this file.
00001 /*! \file iterator_cont.hpp
00002  *  \brief Contiguous iterator object definition. Two template specializations. This iterator has to be used for contiguous moves in memory, element by element in the DMatrix. 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_CONT_H
00005 #define ITERATOR_CONT_H
00006 
00007 namespace skelgis{
00008 
00009   //================================================================================
00010   //!  Iterator contiguous class
00011   /*!
00012     template of the contiguous 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_cont
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_cont():_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_cont(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_cont(const iterator_cont<T,R>& it):_rank(it._rank),_width(it._width){}
00042     //-------------------------------------------------------------------------------
00043     //! Destructor of the iterator
00044     //-------------------------------------------------------------------------------
00045     ~iterator_cont(){}
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_cont<T,R>& operator++()
00054     //-------------------------------------------------------------------------------
00055     {
00056       if((_rank+1)%_width<(_width-R))
00057         ++_rank;
00058       else
00059         _rank = _rank+2*R+1;
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_cont<T,R>& operator++(int)
00070     //-------------------------------------------------------------------------------
00071     {
00072       iterator_cont<T,R> _tmp = *this;
00073       if((_rank+1)%_width<(_width-R))
00074         ++_rank;
00075       else
00076         _rank = _rank+2*R+1;
00077       return _tmp;
00078     }
00079     //-------------------------------------------------------------------------------
00080     //! operator = of the iterator
00081     /*!
00082       This operation assigns another iterator informations to the current one.
00083       \return a reference to the resulting iterator itself
00084     */
00085     //-------------------------------------------------------------------------------
00086     inline iterator_cont<T,R>& operator=(iterator_cont<T,R> right)
00087     //-------------------------------------------------------------------------------
00088     {
00089       _rank = right._rank;
00090       _width = right._width;
00091       return *this;
00092     }
00093     //-------------------------------------------------------------------------------
00094     //! operator == of the iterator
00095     /*!
00096       This operation checks the equality of two iterators with their rank values.
00097       \return true if the two iterator have the same rank. False otherwize.
00098     */
00099     //-------------------------------------------------------------------------------
00100     inline bool operator==(const iterator_cont<T,R>& toTest) {return _rank==toTest._rank;}
00101     //-------------------------------------------------------------------------------
00102     //! operator != of the iterator
00103     /*!
00104       This operation checks the inequality of two iterators with their rank values.
00105       \return true if the two iterator do not have the same rank. False otherwize.
00106     */
00107     //-------------------------------------------------------------------------------
00108     inline bool operator!=(const iterator_cont<T,R>& toTest) {return _rank!=toTest._rank;}
00109     //-------------------------------------------------------------------------------
00110     //! operator <= of the iterator
00111     /*!
00112       This operation checks if the current iterator rank is smaller or equal to the other one.
00113       \return true is the current iterator rank is smaller or equal. False otherwize.
00114     */
00115     //-------------------------------------------------------------------------------
00116     inline bool operator <=(const iterator_cont<T,R>& toComp) {return _rank<=toComp._rank;}
00117     //-------------------------------------------------------------------------------
00118     //! operator < of the iterator
00119     /*!
00120       This operation checks if the current iterator rank is smaller than the other one.
00121       \return true is the current iterator rank is smaller. False otherwize.
00122     */
00123     //-------------------------------------------------------------------------------
00124     inline bool operator <(const iterator_cont<T,R>& toComp) {return _rank<toComp._rank;}
00125     //-------------------------------------------------------------------------------
00126     //! operator >= of the iterator
00127     /*!
00128       This operation checks if the current iterator rank is biger or equal to the other one.
00129       \return true is the current iterator rank is biger or equal. False otherwize.
00130     */
00131     //-------------------------------------------------------------------------------
00132     inline bool operator >=(const iterator_cont<T,R>& toComp) {return _rank>=toComp._rank;}
00133     //-------------------------------------------------------------------------------
00134     //! operator > of the iterator
00135     /*!
00136       This operation checks if the current iterator rank is biger than the other one.
00137       \return true is the current iterator rank is biger. False otherwize.
00138     */
00139     //-------------------------------------------------------------------------------
00140     inline bool operator >(const iterator_cont<T,R>& toComp) {return _rank>toComp._rank;}
00141     //-------------------------------------------------------------------------------
00142   };
00143 
00144   //================================================================================
00145   //!  Iterator class
00146   /*!
00147     template of the contiguous iterator of SkelGIS. This is the second specialization of iterator class.
00148     \tparam T is the type of data stored in the DMatrix to manipulate with the iterator
00149     R is specialized with the value 0
00150   */
00151   //-------------------------------------------------------------------------------
00152   template<class T> struct iterator_cont<T,0>
00153   //-------------------------------------------------------------------------------
00154   {
00155   public:
00156     unsigned int _rank; /*!< current rank of the iterator */
00157 
00158     //! default constructor of the iterator
00159     //-------------------------------------------------------------------------------
00160     iterator_cont():_rank(0){}
00161     //-------------------------------------------------------------------------------
00162     //! constructor of the iterator
00163     /*!
00164       \param r is the initial rank to assign to the iterator
00165     */
00166     //-------------------------------------------------------------------------------
00167     iterator_cont(const unsigned int r):_rank(r){}
00168     //-------------------------------------------------------------------------------
00169     //! constructor of the iterator from another iterator
00170     /*!
00171       \param it is the other iterator instance from which to construct the new one
00172     */
00173     //-------------------------------------------------------------------------------
00174     iterator_cont(const iterator_cont<T,0>& it):_rank(it._rank){}
00175     //------------------------------------------------------------------------------
00176     //! Destructor of the iterator
00177     //-------------------------------------------------------------------------------
00178     ~iterator_cont(){}
00179     //-------------------------------------------------------------------------------
00180     //! operator ++ pre-incrementation of the iterator
00181     /*!
00182       This operation increments the position of the iterator in the DMatrix.
00183       \return a reference to the resulting iterator itself
00184     */
00185     //-------------------------------------------------------------------------------
00186     inline iterator_cont<T,0>& operator++(){++_rank;return *this;}
00187     //-------------------------------------------------------------------------------
00188     //! operator ++ post-incrementation of the iterator
00189     /*!
00190       This operation increments the position of the iterator in the DMatrix.
00191       \return a reference to the resulting iterator itself
00192     */
00193     //-------------------------------------------------------------------------------
00194     inline iterator_cont<T,0>& operator++(int){iterator_cont<T,0> _tmp=*this;++_rank;return _tmp;}
00195     //-------------------------------------------------------------------------------
00196     //! operator = of the iterator
00197     /*!
00198       This operation assigns another iterator informations to the current one.
00199       \return a reference to the resulting iterator itself
00200     */
00201     //-------------------------------------------------------------------------------
00202     inline iterator_cont<T,0>& operator=(iterator_cont<T,0> right)
00203     //-------------------------------------------------------------------------------
00204     {
00205       _rank = right._rank;
00206       return *this;
00207     }
00208     //-------------------------------------------------------------------------------
00209     //! operator = of the iterator
00210     /*!
00211       This operation assigns another iterator informations to the current one.
00212       \return a reference to the resulting iterator itself
00213     */
00214     //-------------------------------------------------------------------------------
00215     inline bool operator==(const iterator_cont<T,0>& toTest) {return _rank==toTest._rank;}
00216     //-------------------------------------------------------------------------------
00217     //! operator != of the iterator
00218     /*!
00219       This operation checks the inequality of two iterators with their rank values.
00220       \return true if the two iterator do not have the same rank. False otherwize.
00221     */
00222     //-------------------------------------------------------------------------------
00223     inline bool operator!=(const iterator_cont<T,0>& toTest) {return _rank!=toTest._rank;}
00224     //-------------------------------------------------------------------------------
00225     //! operator <= of the iterator
00226     /*!
00227       This operation checks if the current iterator rank is smaller or equal to the other one.
00228       \return true is the current iterator rank is smaller or equal. False otherwize.
00229     */
00230     //-------------------------------------------------------------------------------
00231     inline bool operator <=(const iterator_cont<T,0>& toComp) {return _rank<=toComp._rank;}
00232     //-------------------------------------------------------------------------------
00233     //! operator <= of the iterator
00234     /*!
00235       This operation checks if the current iterator rank is biger or equal to the other one.
00236       \return true is the current iterator rank is biger or equal. False otherwize.
00237     */
00238     //-------------------------------------------------------------------------------
00239     inline bool operator <(const iterator_cont<T,0>& toComp) {return _rank<toComp._rank;}
00240     //-------------------------------------------------------------------------------
00241     //! operator >= of the iterator
00242     /*!
00243       This operation checks if the current iterator rank is biger or equal to the other one.
00244       \return true is the current iterator rank is biger or equal. False otherwize.
00245     */
00246     //-------------------------------------------------------------------------------
00247     inline bool operator >=(const iterator_cont<T,0>& toComp) {return _rank>=toComp._rank;}
00248     //-------------------------------------------------------------------------------
00249     //! operator > of the iterator
00250     /*!
00251       This operation checks if the current iterator rank is biger than the other one.
00252       \return true is the current iterator rank is biger. False otherwize.
00253     */
00254     //-------------------------------------------------------------------------------
00255     inline bool operator >(const iterator_cont<T,0>& toComp) {return _rank>toComp._rank;}
00256     //-------------------------------------------------------------------------------
00257   };
00258 }
00259 
00260 #endif
00261 
00262 
00263 
00264 
 All Classes Files Functions Variables Defines