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

complex_window_piter.hh

00001 // Copyright (C) 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_IMAGE_COMPLEX_WINDOW_PITER_HH
00027 # define MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH
00028 
00031 
00032 # include <mln/core/internal/site_relative_iterator_base.hh>
00033 
00034 // FIXME: These might be factor-able, both between fwd/bkd and nbh/win.
00035 
00036 /* FIXME: Do we really want to inherit from
00037    internal::site_relative_iterator_base?  I might duplicate things,
00038    since most of the implementation of this iterator is delegated to
00039    the underlying complex iter.  Moreover, change_target_() is
00040    useless, and center_at() ``hides'' an existing method in (one of)
00041    the super class(es) which is not sound, IMHO.  Think about
00042    introducing base class replacement.  */
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   /*------------------------------------.
00049   | complex_window_fwd_piter<I, G, W>.  |
00050   `------------------------------------*/
00051 
00053   template <typename I, typename G, typename W>
00054   class complex_window_fwd_piter
00055     : public internal::site_relative_iterator_base< W,
00056                                                     complex_window_fwd_piter<I, G, W> >
00057   {
00058     typedef complex_window_fwd_piter<I, G, W> self_;
00059     typedef internal::site_relative_iterator_base< W, self_ > super_;
00060 
00061   public:
00063     typedef mln_psite(W) psite;
00065     typedef typename W::complex_fwd_iter iter_type;
00066 
00067   public:
00070     complex_window_fwd_piter();
00071     template <typename Pref>
00072     complex_window_fwd_piter(const Window<W>& win, const Pref& p_ref);
00074 
00078     bool is_valid_() const;
00080     void invalidate_();
00081 
00083     void do_start_();
00085     void do_next_();
00086 
00088     template <typename Pref>
00089     void center_at_(const Pref& c);
00090 
00092     psite compute_p_() const;
00094 
00097     const iter_type& iter() const;
00098     iter_type& iter();
00100 
00101   private:
00103     iter_type iter_;
00104   };
00105 
00106 
00108   template <typename I, typename G, typename W>
00109   std::ostream&
00110   operator<<(std::ostream& ostr,
00111              const complex_window_fwd_piter<I, G, W>& p);
00112 
00113 
00114   /*------------------------------------.
00115   | complex_window_bkd_piter<I, G, W>.  |
00116   `------------------------------------*/
00117 
00119   template <typename I, typename G, typename W>
00120   class complex_window_bkd_piter
00121     : public internal::site_relative_iterator_base< W,
00122                                                     complex_window_bkd_piter<I, G, W> >
00123   {
00124     typedef complex_window_bkd_piter<I, G, W> self_;
00125     typedef internal::site_relative_iterator_base< W, self_ > super_;
00126 
00127   public:
00129     typedef mln_psite(W) psite;
00131     typedef typename W::complex_bkd_iter iter_type;
00132 
00133   public:
00136     complex_window_bkd_piter();
00137     template <typename Pref>
00138     complex_window_bkd_piter(const Window<W>& win, const Pref& p_ref);
00140 
00144     bool is_valid_() const;
00146     void invalidate_();
00147 
00149     void do_start_();
00151     void do_next_();
00152 
00154     template <typename Pref>
00155     void center_at_(const Pref& c);
00156 
00158     psite compute_p_() const;
00160 
00163     const iter_type& iter() const;
00164     iter_type& iter();
00166 
00167   private:
00169     iter_type iter_;
00170   };
00171 
00172 
00174   template <typename I, typename G, typename W>
00175   std::ostream&
00176   operator<<(std::ostream& ostr,
00177              const complex_window_bkd_piter<I, G, W>& p);
00178 
00179 
00180 
00181 # ifndef MLN_INCLUDE_ONLY
00182 
00183   /*------------------------------------.
00184   | complex_window_fwd_piter<I, G, W>.  |
00185   `------------------------------------*/
00186 
00187   template <typename I, typename G, typename W>
00188   inline
00189   complex_window_fwd_piter<I, G, W>::complex_window_fwd_piter()
00190   {
00191   }
00192 
00193   template <typename I, typename G, typename W>
00194   template <typename Pref>
00195   inline
00196   complex_window_fwd_piter<I, G, W>::complex_window_fwd_piter(const Window<W>& win,
00197                                                               const Pref& p_ref)
00198   {
00199     this->change_target(exact(win));
00200     center_at(p_ref);
00201     mln_postcondition(!this->is_valid());
00202   }
00203 
00204   template <typename I, typename G, typename W>
00205   inline
00206   bool
00207   complex_window_fwd_piter<I, G, W>::is_valid_() const
00208   {
00209     return iter_.is_valid();
00210   }
00211 
00212   template <typename I, typename G, typename W>
00213   inline
00214   void
00215   complex_window_fwd_piter<I, G, W>::invalidate_()
00216   {
00217     iter_.invalidate();
00218   }
00219 
00220   template <typename I, typename G, typename W>
00221   inline
00222   void
00223   complex_window_fwd_piter<I, G, W>::do_start_()
00224   {
00225     iter_.start();
00226   }
00227 
00228   template <typename I, typename G, typename W>
00229   inline
00230   void
00231   complex_window_fwd_piter<I, G, W>::do_next_()
00232   {
00233     iter_.next();
00234   }
00235 
00236   template <typename I, typename G, typename W>
00237   template <typename Pref>
00238   inline
00239   void
00240   complex_window_fwd_piter<I, G, W>::center_at_(const Pref&)
00241   {
00242     iter_.center_at(this->center().face());
00243   }
00244 
00245   template <typename I, typename G, typename W>
00246   inline
00247   mln_psite(W)
00248   complex_window_fwd_piter<I, G, W>::compute_p_() const
00249   {
00250     return psite(this->center().site_set(), iter_);
00251   }
00252 
00253   template <typename I, typename G, typename W>
00254   inline
00255   const typename W::complex_fwd_iter&
00256   complex_window_fwd_piter<I, G, W>::iter() const
00257   {
00258     return iter_;
00259   }
00260 
00261   template <typename I, typename G, typename W>
00262   inline
00263   typename W::complex_fwd_iter&
00264   complex_window_fwd_piter<I, G, W>::iter()
00265   {
00266     return iter_;
00267   }
00268 
00269 
00270   template <typename I, typename G, typename W>
00271   inline
00272   std::ostream&
00273   operator<<(std::ostream& ostr,
00274              const complex_window_fwd_piter<I, G, W>& p)
00275   {
00276     return ostr << p.unproxy_();
00277   }
00278 
00279 
00280   /*------------------------------------.
00281   | complex_window_bkd_piter<I, G, W>.  |
00282   `------------------------------------*/
00283 
00284   template <typename I, typename G, typename W>
00285   inline
00286   complex_window_bkd_piter<I, G, W>::complex_window_bkd_piter()
00287   {
00288   }
00289 
00290   template <typename I, typename G, typename W>
00291   template <typename Pref>
00292   inline
00293   complex_window_bkd_piter<I, G, W>::complex_window_bkd_piter(const Window<W>& win,
00294                                                               const Pref& p_ref)
00295   {
00296     this->change_target(exact(win));
00297     center_at(p_ref);
00298     mln_postcondition(!this->is_valid());
00299   }
00300 
00301   template <typename I, typename G, typename W>
00302   inline
00303   bool
00304   complex_window_bkd_piter<I, G, W>::is_valid_() const
00305   {
00306     return iter_.is_valid();
00307   }
00308 
00309   template <typename I, typename G, typename W>
00310   inline
00311   void
00312   complex_window_bkd_piter<I, G, W>::invalidate_()
00313   {
00314     iter_.invalidate();
00315   }
00316 
00317   template <typename I, typename G, typename W>
00318   inline
00319   void
00320   complex_window_bkd_piter<I, G, W>::do_start_()
00321   {
00322     iter_.start();
00323   }
00324 
00325   template <typename I, typename G, typename W>
00326   inline
00327   void
00328   complex_window_bkd_piter<I, G, W>::do_next_()
00329   {
00330     iter_.next();
00331   }
00332 
00333   template <typename I, typename G, typename W>
00334   template <typename Pref>
00335   inline
00336   void
00337   complex_window_bkd_piter<I, G, W>::center_at_(const Pref& c)
00338   {
00339     iter_.center_at(this->center().face());
00340   }
00341 
00342   template <typename I, typename G, typename W>
00343   inline
00344   mln_psite(W)
00345   complex_window_bkd_piter<I, G, W>::compute_p_() const
00346   {
00347     return psite(this->center().site_set(), iter_);
00348   }
00349 
00350   template <typename I, typename G, typename W>
00351   inline
00352   const typename W::complex_bkd_iter&
00353   complex_window_bkd_piter<I, G, W>::iter() const
00354   {
00355     return iter_;
00356   }
00357 
00358   template <typename I, typename G, typename W>
00359   inline
00360   typename W::complex_bkd_iter&
00361   complex_window_bkd_piter<I, G, W>::iter()
00362   {
00363     return iter_;
00364   }
00365 
00366 
00367   template <typename I, typename G, typename W>
00368   inline
00369   std::ostream&
00370   operator<<(std::ostream& ostr,
00371              const complex_window_bkd_piter<I, G, W>& p)
00372   {
00373     return ostr << p.unproxy_();
00374   }
00375 
00376 # endif // ! MLN_INCLUDE_ONLY
00377 
00378 } // end of namespace mln
00379 
00380 #endif // ! MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH

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