• 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 
00074     bool is_valid_() const;
00076     void invalidate_();
00077 
00079     void do_start_();
00081     void do_next_();
00082 
00084     template <typename Pref>
00085     void center_at_(const Pref& c);
00086 
00088     template <typename I2>
00089     void center_at_(const p_graph_piter<S, I2>& c);
00090 
00092     const mln_graph_element(S)& element() const;
00093 
00095     mln_psite(W) compute_p_() const;
00096 
00101     unsigned id() const;
00103 
00104   private:
00105     I iter_;
00106 
00107   protected:
00109     using super_::s_;
00110   };
00111 
00112 
00113 
00114 # ifndef MLN_INCLUDE_ONLY
00115 
00116   template <typename S, typename W, typename I>
00117   inline
00118   graph_window_if_piter<S,W,I>::graph_window_if_piter()
00119   {
00120   }
00121 
00122   template <typename S, typename W, typename I>
00123   template <typename Pref>
00124   inline
00125   graph_window_if_piter<S,W,I>::graph_window_if_piter(const Window<W>& win,
00126                                                       const Pref& p_ref)
00127   {
00128     this->center_at(p_ref);
00129     this->change_target(exact(win));
00130 
00131     mln_postcondition(!this->is_valid());
00132   }
00133 
00134   template <typename S, typename W, typename I>
00135   inline
00136   bool
00137   graph_window_if_piter<S,W,I>::is_valid_() const
00138   {
00139     return iter_.is_valid();
00140   }
00141 
00142   template <typename S, typename W, typename I>
00143   inline
00144   void
00145   graph_window_if_piter<S,W,I>::invalidate_()
00146   {
00147     iter_.invalidate();
00148   }
00149 
00150   template <typename S, typename W, typename I>
00151   inline
00152   void
00153   graph_window_if_piter<S,W,I>::do_start_()
00154   {
00155     iter_.start();
00156     while (iter_.is_valid() && is_masked(this->c_->element(), iter_))
00157       iter_.next();
00158   }
00159 
00160   template <typename S, typename W, typename I>
00161   inline
00162   void
00163   graph_window_if_piter<S,W,I>::do_next_()
00164   {
00165     iter_.next();
00166     while (iter_.is_valid() && is_masked(this->c_->element(), iter_))
00167       iter_.next();
00168   }
00169 
00170   template <typename S, typename W, typename I>
00171   template <typename Pref>
00172   inline
00173   void
00174   graph_window_if_piter<S,W,I>::center_at_(const Pref& c)
00175   {
00176     iter_.center_at(c.p_hook_());
00177   }
00178 
00179   template <typename S, typename W, typename I>
00180   template <typename I2>
00181   inline
00182   void
00183   graph_window_if_piter<S,W,I>::center_at_(const p_graph_piter<S, I2>& c)
00184   {
00185     iter_.center_at(c.hook_elt_());
00186   }
00187 
00188   template <typename S, typename W, typename I>
00189   inline
00190   mln_psite(W)
00191   graph_window_if_piter<S,W,I>::compute_p_() const
00192   {
00193     return mln_psite(S)(this->center().site_set(), iter_.id());
00194   }
00195 
00196   template <typename S, typename W, typename I>
00197   inline
00198   const mln_graph_element(S)&
00199   graph_window_if_piter<S,W,I>::element() const
00200   {
00201     return iter_;
00202   }
00203 
00204   template <typename S, typename W, typename I>
00205   inline
00206   unsigned
00207   graph_window_if_piter<S,W,I>::id() const
00208   {
00209     return iter_.id();
00210   }
00211 
00212 
00213 # endif // ! MLN_INCLUDE_ONLY
00214 
00215 } // end of namespace mln
00216 
00217 #endif // ! MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH

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