• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

dpsites_piter.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_DPSITES_PITER_HH
00028 # define MLN_CORE_DPSITES_PITER_HH
00029 
00034 
00035 # include <vector>
00036 # include <mln/core/internal/site_relative_iterator_base.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00047   template <typename V>
00048   class dpsites_fwd_piter
00049     : public internal::site_relative_iterator_base< V, dpsites_fwd_piter<V> >
00050   {
00051   public:
00052 
00057     template <typename P>
00058     dpsites_fwd_piter(const V& v, const P& c);
00059 
00061     template <typename P>
00062     void init_(const V& v, const P& c);
00063 
00065     dpsites_fwd_piter();
00066 
00068     bool is_valid_() const;
00069 
00071     void invalidate_();
00072 
00074     void do_start_();
00075 
00077     void do_next_();
00078 
00080     mln_psite(V) compute_p_() const;
00081 
00082   protected:
00083 
00084     unsigned i_;
00085   };
00086 
00087 
00093   template <typename V>
00094   class dpsites_bkd_piter :
00095     public internal::site_relative_iterator_base< V, dpsites_bkd_piter<V> >
00096   {
00097   public:
00098 
00103     template <typename P>
00104     dpsites_bkd_piter(const V& v, const P& c);
00105 
00107     dpsites_bkd_piter();
00108 
00110     template <typename P>
00111     void init_(const V& v, const P& c);
00112 
00114     bool is_valid_() const;
00115 
00117     void invalidate_();
00118 
00120     void do_start_();
00121 
00123     void do_next_();
00124 
00126     mln_psite(V) compute_p_() const;
00127 
00128   protected:
00129 
00130     int i_;
00131   };
00132 
00133 
00134 
00135 # ifndef MLN_INCLUDE_ONLY
00136 
00137 
00138   // Forward.
00139 
00140   template <typename V>
00141   inline
00142   dpsites_fwd_piter<V>::dpsites_fwd_piter()
00143   {
00144   }
00145 
00146   template <typename V>
00147   template <typename P>
00148   inline
00149   dpsites_fwd_piter<V>::dpsites_fwd_piter(const V& v, const P& c)
00150   {
00151     init_(v, c);
00152   }
00153 
00154   template <typename V>
00155   template <typename P>
00156   inline
00157   void
00158   dpsites_fwd_piter<V>::init_(const V& v, const P& c)
00159   {
00160     this->change_target(v);
00161     this->center_at(c);
00162   }
00163 
00164 
00165   template <typename V>
00166   inline
00167   bool
00168   dpsites_fwd_piter<V>::is_valid_() const
00169   {
00170     return i_ != this->s_->std_vector().size();
00171   }
00172 
00173   template <typename V>
00174   inline
00175   void
00176   dpsites_fwd_piter<V>::invalidate_()
00177   {
00178     i_ = this->s_->std_vector().size();
00179   }
00180 
00181   template <typename V>
00182   inline
00183   void
00184   dpsites_fwd_piter<V>::do_start_()
00185   {
00186     i_ = 0;
00187   }
00188 
00189   template <typename V>
00190   inline
00191   void
00192   dpsites_fwd_piter<V>::do_next_()
00193   {
00194     ++i_;
00195   }
00196 
00197   template <typename V>
00198   inline
00199   mln_psite(V)
00200   dpsites_fwd_piter<V>::compute_p_() const
00201   {
00202     return *this->c_ + this->s_->std_vector()[i_];
00203   }
00204 
00205 
00206   // Backward.
00207 
00208   template <typename V>
00209   inline
00210   dpsites_bkd_piter<V>::dpsites_bkd_piter()
00211   {
00212   }
00213 
00214   template <typename V>
00215   template <typename P>
00216   inline
00217   dpsites_bkd_piter<V>::dpsites_bkd_piter(const V& v, const P& c)
00218   {
00219     init_(v, c);
00220   }
00221 
00222   template <typename V>
00223   template <typename P>
00224   inline
00225   void
00226   dpsites_bkd_piter<V>::init_(const V& v, const P& c)
00227   {
00228     this->change_target(v);
00229     this->center_at(c);
00230   }
00231 
00232 
00233   template <typename V>
00234   inline
00235   bool
00236   dpsites_bkd_piter<V>::is_valid_() const
00237   {
00238     return i_ != -1;
00239   }
00240 
00241   template <typename V>
00242   inline
00243   void
00244   dpsites_bkd_piter<V>::invalidate_()
00245   {
00246     i_ = -1;
00247   }
00248 
00249   template <typename V>
00250   inline
00251   void
00252   dpsites_bkd_piter<V>::do_start_()
00253   {
00254     i_ = this->s_->std_vector().size() - 1;
00255   }
00256 
00257   template <typename V>
00258   inline
00259   void
00260   dpsites_bkd_piter<V>::do_next_()
00261   {
00262     --i_;
00263   }
00264 
00265   template <typename V>
00266   inline
00267   mln_psite(V)
00268   dpsites_bkd_piter<V>::compute_p_() const
00269   {
00270     return *this->c_ + this->s_->std_vector()[i_];
00271   }
00272 
00273 # endif // ! MLN_INCLUDE_ONLY
00274 
00275 } // end of namespace mln
00276 
00277 
00278 #endif // ! MLN_CORE_DPSITES_PITER_HH

Generated on Tue Oct 4 2011 15:23:42 for Milena (Olena) by  doxygen 1.7.1