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

dpsites_piter.hh

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

Generated on Thu Sep 8 2011 18:31:46 for Milena (Olena) by  doxygen 1.7.1