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

graph_window_if_piter.hh

00001 // Copyright (C) 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_GRAPH_WINDOW_IF_PITER_HH
00027 # define MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH
00028 
00032 
00033 # include <mln/core/internal/is_masked_impl_selector.hh>
00034 # include <mln/core/internal/site_relative_iterator_base.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   // Forward declaration.
00041   template <typename S, typename I> class p_graph_piter;
00042 
00043 
00044 
00046   template <typename S, typename W, typename I>
00047   class graph_window_if_piter
00048     : public internal::site_relative_iterator_base< W,
00049                                                     graph_window_if_piter<S,W,I> >,
00050       public internal::is_masked_impl_selector< S,
00051                                                 typename W::mask_t::domain_t,
00052                                                 graph_window_if_piter<S,W,I> >
00053   {
00054     typedef graph_window_if_piter<S,W,I> self_;
00055     typedef internal::site_relative_iterator_base<W,self_> super_;
00056 
00057   public:
00060     typedef mln_result(S::fun_t) P;
00062 
00065     graph_window_if_piter();
00066     template <typename Pref>
00067     graph_window_if_piter(const Window<W>& win,
00068                           const Pref& p_ref);
00070 
00072     template <typename Pref>
00073     void init_(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     template <typename I2>
00093     void center_at_(const p_graph_piter<S, I2>& c);
00094 
00096     const mln_graph_element(S)& element() const;
00097 
00099     mln_psite(W) compute_p_() const;
00100 
00105     unsigned id() const;
00107 
00108   private:
00109     I iter_;
00110 
00111   protected:
00113     using super_::s_;
00114   };
00115 
00116 
00117 
00118 # ifndef MLN_INCLUDE_ONLY
00119 
00120   template <typename S, typename W, typename I>
00121   inline
00122   graph_window_if_piter<S,W,I>::graph_window_if_piter()
00123   {
00124   }
00125 
00126   template <typename S, typename W, typename I>
00127   template <typename Pref>
00128   inline
00129   graph_window_if_piter<S,W,I>::graph_window_if_piter(const Window<W>& win,
00130                                                       const Pref& p_ref)
00131   {
00132     init_(win, p_ref);
00133   }
00134 
00135   template <typename S, typename W, typename I>
00136   template <typename Pref>
00137   inline
00138   void
00139   graph_window_if_piter<S,W,I>::init_(const Window<W>& win,
00140                                       const Pref& p_ref)
00141   {
00142     this->center_at(p_ref);
00143     this->change_target(exact(win));
00144 
00145     mln_postcondition(!this->is_valid());
00146   }
00147 
00148   template <typename S, typename W, typename I>
00149   inline
00150   bool
00151   graph_window_if_piter<S,W,I>::is_valid_() const
00152   {
00153     return iter_.is_valid();
00154   }
00155 
00156   template <typename S, typename W, typename I>
00157   inline
00158   void
00159   graph_window_if_piter<S,W,I>::invalidate_()
00160   {
00161     iter_.invalidate();
00162   }
00163 
00164   template <typename S, typename W, typename I>
00165   inline
00166   void
00167   graph_window_if_piter<S,W,I>::do_start_()
00168   {
00169     iter_.start();
00170     while (iter_.is_valid() && is_masked(this->c_->element(), iter_))
00171       iter_.next();
00172   }
00173 
00174   template <typename S, typename W, typename I>
00175   inline
00176   void
00177   graph_window_if_piter<S,W,I>::do_next_()
00178   {
00179     iter_.next();
00180     while (iter_.is_valid() && is_masked(this->c_->element(), iter_))
00181       iter_.next();
00182   }
00183 
00184   template <typename S, typename W, typename I>
00185   template <typename Pref>
00186   inline
00187   void
00188   graph_window_if_piter<S,W,I>::center_at_(const Pref& c)
00189   {
00190     iter_.center_at(c.p_hook_());
00191   }
00192 
00193   template <typename S, typename W, typename I>
00194   template <typename I2>
00195   inline
00196   void
00197   graph_window_if_piter<S,W,I>::center_at_(const p_graph_piter<S, I2>& c)
00198   {
00199     iter_.center_at(c.hook_elt_());
00200   }
00201 
00202   template <typename S, typename W, typename I>
00203   inline
00204   mln_psite(W)
00205   graph_window_if_piter<S,W,I>::compute_p_() const
00206   {
00207     return mln_psite(S)(this->center().site_set(), iter_.id());
00208   }
00209 
00210   template <typename S, typename W, typename I>
00211   inline
00212   const mln_graph_element(S)&
00213   graph_window_if_piter<S,W,I>::element() const
00214   {
00215     return iter_;
00216   }
00217 
00218   template <typename S, typename W, typename I>
00219   inline
00220   unsigned
00221   graph_window_if_piter<S,W,I>::id() const
00222   {
00223     return iter_.id();
00224   }
00225 
00226 
00227 # endif // ! MLN_INCLUDE_ONLY
00228 
00229 } // end of namespace mln
00230 
00231 #endif // ! MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH

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