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

neighb.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_NEIGHB_HH
00027 # define MLN_CORE_NEIGHB_HH
00028 
00036 
00037 # include <mln/core/internal/neighborhood_base.hh>
00038 # include <mln/core/internal/site_relative_iterator_base.hh>
00039 # include <mln/core/internal/neighb_niter_impl.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   // Forward declarations.
00046   template <typename W> class neighb_fwd_niter;
00047   template <typename W> class neighb_bkd_niter;
00048   template <typename W> class neighb;
00049 
00050 
00051   namespace convert
00052   {
00053 
00054     namespace over_load
00055     {
00056 
00057       template <typename W>
00058       void
00059       from_to_(const mln::neighb<W>& from, W& to);
00060 
00061       template <typename W>
00062       void
00063       from_to_(const W& from, mln::neighb<W>& to);
00064 
00065     } // end of namespace mln::convert::over_load
00066 
00067   } // end of namespace mln::convert
00068 
00069 
00070 
00072 
00073   template <typename W>
00074   class neighb : public internal::neighborhood_base< W, neighb<W> >,
00075                  private mlc_is_a(W, Window)::check_t
00076   {
00077   public:
00078 
00080     typedef neighb_fwd_niter<W> fwd_niter;
00081 
00083     typedef neighb_bkd_niter<W> bkd_niter;
00084 
00086     typedef fwd_niter niter;
00087 
00088 
00090     neighb();
00091 
00093     neighb(const W& win);
00094 
00096     const W& win() const;
00097 
00099     void change_window(const W& new_win);
00100 
00101 
00103     W& hook_win_();
00104 
00105   private:
00106 
00107     W win_;
00108   };
00109 
00110 
00111 
00112   // neighb_fwd_niter<W>
00113 
00114   template <typename W>
00115   class neighb_fwd_niter
00116     : public internal::site_relative_iterator_base< neighb<W>,
00117                                                     neighb_fwd_niter<W> >,
00118       public internal::neighb_niter_impl<W, neighb_fwd_niter<W> >
00119   {
00120   public:
00121 
00123     neighb_fwd_niter();
00124 
00125     template <typename P>
00126     neighb_fwd_niter(const neighb<W>& nbh, const P& c);
00127 
00129     bool is_valid_() const;
00130 
00132     void invalidate_();
00133 
00135     void do_start_();
00136 
00138     void do_next_();
00139 
00141     mln_psite(W) compute_p_() const;
00142 
00143   protected:
00144 
00145     mln_fwd_qiter(W) i_;
00146   };
00147 
00148 
00149 
00150 // neighb_bkd_niter<W>
00151 
00152 template <typename W>
00153 class neighb_bkd_niter
00154   : public internal::site_relative_iterator_base< neighb<W>,
00155                                                   neighb_bkd_niter<W> >,
00156     public internal::neighb_niter_impl<W, neighb_fwd_niter<W> >
00157 {
00158 public:
00159 
00161   neighb_bkd_niter();
00162 
00163   template <typename P>
00164   neighb_bkd_niter(const neighb<W>& nbh, const P& c);
00165 
00167   bool is_valid_() const;
00168 
00170   void invalidate_();
00171 
00173   void do_start_();
00174 
00176   void do_next_();
00177 
00179   mln_psite(W) compute_p_() const;
00180 
00181 protected:
00182 
00183   mln_bkd_qiter(W) i_;
00184 };
00185 
00186 
00187 
00188 # ifndef MLN_INCLUDE_ONLY
00189 
00190   // neighb<W>
00191 
00192   template <typename W>
00193   inline
00194   neighb<W>::neighb()
00195   {
00196   }
00197 
00198   template <typename W>
00199   inline
00200   neighb<W>::neighb(const W& win)
00201   {
00202     change_window(win);
00203   }
00204 
00205   template <typename W>
00206   inline
00207   const W&
00208   neighb<W>::win() const
00209   {
00210     return win_;
00211   }
00212 
00213   template <typename W>
00214   inline
00215   void
00216   neighb<W>::change_window(const W& new_win)
00217   {
00218     mln_precondition(new_win.is_neighbable_());
00219     win_ = new_win;
00220   }
00221 
00222   template <typename W>
00223   inline
00224   W&
00225   neighb<W>::hook_win_()
00226   {
00227     return win_;
00228   }
00229 
00230 
00231   // mln::convert::from_to
00232 
00233   namespace convert
00234   {
00235 
00236     namespace over_load
00237     {
00238 
00239       template <typename W>
00240       void
00241       from_to_(const mln::neighb<W>& from, W& to)
00242       {
00243         to = from.win();
00244       }
00245 
00246       template <typename W>
00247       void
00248       from_to_(const W& from, mln::neighb<W>& to)
00249       {
00250         to.change_window(from);
00251       }
00252 
00253     } // end of namespace mln::convert::over_load
00254 
00255   } // end of namespace mln::convert
00256 
00257 
00258   // neighb_fwd_niter<W>
00259 
00260   template <typename W>
00261   inline
00262   neighb_fwd_niter<W>::neighb_fwd_niter()
00263   {
00264   }
00265 
00266   template <typename W>
00267   template <typename P>
00268   inline
00269   neighb_fwd_niter<W>::neighb_fwd_niter(const neighb<W>& nbh, const P& c)
00270   {
00271     this->change_target(nbh);
00272     this->center_at(c);
00273     i_.center_at(c); // Always before change_target for this kind of iter.
00274     i_.change_target(nbh.win());
00275   }
00276 
00277   template <typename W>
00278   inline
00279   bool
00280   neighb_fwd_niter<W>::is_valid_() const
00281   {
00282     return i_.is_valid();
00283   }
00284 
00285   template <typename W>
00286   inline
00287   void
00288   neighb_fwd_niter<W>::invalidate_()
00289   {
00290     i_.invalidate();
00291   }
00292 
00293   template <typename W>
00294   inline
00295   void
00296   neighb_fwd_niter<W>::do_start_()
00297   {
00298     i_.start();
00299   }
00300 
00301   template <typename W>
00302   inline
00303   void
00304   neighb_fwd_niter<W>::do_next_()
00305   {
00306     i_.next();
00307   }
00308 
00309   template <typename W>
00310   inline
00311   mln_psite(W)
00312   neighb_fwd_niter<W>::compute_p_() const
00313   {
00314     return i_.compute_p_();
00315   }
00316 
00317 
00318   // neighb_bkd_niter<W>
00319 
00320   template <typename W>
00321   inline
00322   neighb_bkd_niter<W>::neighb_bkd_niter()
00323   {
00324   }
00325 
00326   template <typename W>
00327   template <typename P>
00328   inline
00329   neighb_bkd_niter<W>::neighb_bkd_niter(const neighb<W>& nbh, const P& c)
00330   {
00331     this->change_target(nbh);
00332     this->center_at(c);
00333     i_.center_at(c); // Always before change_target for this kind of iter.
00334     i_.change_target(nbh.win());
00335   }
00336 
00337   template <typename W>
00338   inline
00339   bool
00340   neighb_bkd_niter<W>::is_valid_() const
00341   {
00342     return i_.is_valid();
00343   }
00344 
00345   template <typename W>
00346   inline
00347   void
00348   neighb_bkd_niter<W>::invalidate_()
00349   {
00350     i_.invalidate();
00351   }
00352 
00353   template <typename W>
00354   inline
00355   void
00356   neighb_bkd_niter<W>::do_start_()
00357   {
00358     i_.start();
00359   }
00360 
00361   template <typename W>
00362   inline
00363   void
00364   neighb_bkd_niter<W>::do_next_()
00365   {
00366     i_.next();
00367   }
00368 
00369   template <typename W>
00370   inline
00371   mln_psite(W)
00372   neighb_bkd_niter<W>::compute_p_() const
00373   {
00374     return i_.compute_p_();
00375   }
00376 
00377 # endif // ! MLN_INCLUDE_ONLY
00378 
00379 } // end of namespace mln
00380 
00381 
00382 #endif // ! MLN_CORE_NEIGHB_HH

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