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

p_centered.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_SITE_SET_P_CENTERED_HH
00027 # define MLN_CORE_SITE_SET_P_CENTERED_HH
00028 
00036 
00037 
00038 # include <mln/core/internal/site_set_base.hh>
00039 # include <mln/core/internal/site_set_iterator_base.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   // Fwd decls.
00046   template <typename W> class p_centered;
00047   template <typename W> class p_centered_piter;
00048 
00049 
00050   namespace trait
00051   {
00052 
00053     template <typename W>
00054     struct site_set_< p_centered<W> >
00055     {
00056       typedef trait::site_set::nsites::unknown nsites;
00057       typedef trait::site_set::bbox::unknown   bbox;
00058       typedef trait::site_set::contents::fixed contents;
00059       typedef trait::site_set::arity::unique   arity;
00060     };
00061 
00062 //     template <typename W>
00063 //     struct set_precise_unary_< op::ord, p_centered<W> >
00064 //     {
00065 //       typedef set_precise_unary_< op::ord, p_centered<W> > ret; // Itself.
00066 //       bool strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const;
00067 //     };
00068 
00069   } // end of namespace mln::trait
00070 
00071 
00075   //
00076   template <typename W>
00077   class p_centered : public internal::site_set_base_< mln_psite(W), p_centered<W> >,
00078                      private mlc_is_a(W, Window)::check_t
00079   {
00080   public:
00081 
00083     typedef mln_psite(W) psite;
00084 
00086     typedef mln_site(W) site;
00087 
00088 
00090     typedef psite element;
00091 
00092 
00094     typedef p_centered_piter<W> fwd_piter;
00095 
00097     typedef p_centered_piter<W> bkd_piter; // FIXME
00098 
00100     typedef fwd_piter piter;
00101 
00102 
00104     p_centered();
00105 
00107     p_centered(const W& win, const mln_psite(W)& c);
00108 
00109 
00111     template <typename P>
00112     bool has(const P& p) const;
00113 
00115     bool is_valid() const;
00116 
00118     std::size_t memory_size() const;
00119 
00121     const mln_psite(W)& center() const;
00122 
00124     const W& window() const;
00125 
00126   protected:
00127 
00128     W win_;
00129     mln_psite(W) c_;
00130   };
00131 
00132 
00133   template <typename W>
00134   class p_centered_piter : public internal::site_set_iterator_base< p_centered<W>,
00135                                                                     p_centered_piter<W> >
00136   {
00137     typedef p_centered_piter<W> self_;
00138     typedef internal::site_set_iterator_base< p_centered<W>, self_ > super_;
00139   public:
00140 
00142     p_centered_piter();
00143 
00145     p_centered_piter(const p_centered<W>& s);
00146 
00148     bool is_valid_() const;
00149 
00151     void invalidate_();
00152 
00154     void start_();
00155 
00157     void next_();
00158 
00159   protected:
00160     using super_::p_;
00161     using super_::s_;
00162 
00163     mln_fwd_qiter(W) q_;
00164   };
00165 
00166 
00167 
00168 # ifndef MLN_INCLUDE_ONLY
00169 
00170   // p_centered<W>
00171 
00172   template <typename W>
00173   inline
00174   bool
00175   p_centered<W>::is_valid() const
00176   {
00177     return true; // FIXME
00178   }
00179 
00180   template <typename W>
00181   inline
00182   p_centered<W>::p_centered()
00183   {
00184   }
00185 
00186   template <typename W>
00187   inline
00188   p_centered<W>::p_centered(const W& win, const mln_psite(W)& c)
00189     : win_(win),
00190       c_(c)
00191   {
00192     mln_precondition(is_valid());
00193   }
00194 
00195   template <typename W>
00196   template <typename P>
00197   inline
00198   bool
00199   p_centered<W>::has(const P&) const
00200   {
00201     mln_precondition(is_valid());
00202     return true; // FIXME
00203   }
00204 
00205   template <typename W>
00206   inline
00207   std::size_t
00208   p_centered<W>::memory_size() const
00209   {
00210     return sizeof(*this);
00211   }
00212 
00213   template <typename W>
00214   inline
00215   const mln_psite(W)&
00216   p_centered<W>::center() const
00217   {
00218     return c_;
00219   }
00220 
00221   template <typename W>
00222   inline
00223   const W&
00224   p_centered<W>::window() const
00225   {
00226     return win_;
00227   }
00228 
00229 //   namespace trait
00230 //   {
00231 
00232 //     template <typename W>
00233 //     inline
00234 //     bool
00235 //     set_precise_unary_< op::ord, p_centered<W> >::strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const
00236 //     {
00237 //       // Lexicographical over "pmin then pmax".
00238 //       return util::ord_lexi_strict(lhs.pmin(), lhs.pmax(),
00239 //                                 rhs.pmin(), rhs.pmax());
00240 //     }
00241 
00242 //   } // end of namespace mln::trait
00243 
00244 
00245   // p_centered_piter<W>
00246 
00247   template <typename W>
00248   inline
00249   p_centered_piter<W>::p_centered_piter()
00250   {
00251   }
00252 
00253   template <typename W>
00254   inline
00255   p_centered_piter<W>::p_centered_piter(const p_centered<W>& s)
00256   {
00257     this->change_target(s);
00258     q_.center_at(s.center());
00259     q_.change_target(s.window_());
00260   }
00261 
00262   template <typename W>
00263   inline
00264   bool
00265   p_centered_piter<W>::is_valid_() const
00266   {
00267     return q_.is_valid();
00268   }
00269 
00270   template <typename W>
00271   inline
00272   void
00273   p_centered_piter<W>::invalidate_()
00274   {
00275     q_.invalidate();
00276   }
00277 
00278   template <typename W>
00279   inline
00280   void
00281   p_centered_piter<W>::start_()
00282   {
00283     q_.start();
00284     if (is_valid_())
00285       p_ = q_;
00286   }
00287 
00288   template <typename W>
00289   inline
00290   void
00291   p_centered_piter<W>::next_()
00292   {
00293     q_.next();
00294     if (is_valid_())
00295       p_ = q_;
00296   }
00297 
00298 # endif // ! MLN_INCLUDE_ONLY
00299 
00300 } // end of namespace mln
00301 
00302 
00303 #endif // ! MLN_CORE_SITE_SET_P_CENTERED_HH

Generated on Fri Sep 16 2011 16:33:46 for Milena (Olena) by  doxygen 1.7.1