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

image.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_CONCEPT_IMAGE_HH
00028 # define MLN_CORE_CONCEPT_IMAGE_HH
00029 
00033 
00034 # include <mln/core/concept/site_set.hh>
00035 # include <mln/core/concept/mesh.hh>
00036 
00037 # include <mln/core/trait/all.hh> // FIXME: Move out of core!
00038 # include <mln/core/macros.hh>
00039 # include <mln/core/site_set/box.hh>
00040 
00041 # include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
00042 # include <mln/trait/images.hh>
00043 
00044 # include <mln/metal/abort.hh>
00045 # include <mln/metal/is_a.hh>
00046 # include <mln/metal/equal.hh>
00047 
00048 # include <mln/tag/init.hh>
00049 
00050 
00051 namespace mln
00052 {
00053 
00054 
00055   // Forward declaration.
00056   template <typename E> struct Image;
00057 
00058   // Image category flag type.
00059   template <>
00060   struct Image<void>
00061   {
00062     typedef Object<void> super;
00063   };
00064 
00065 
00070   template <typename E>
00071   struct Image : public Object<E>
00072   {
00073     typedef Image<void> category;
00074 
00075     template <typename J>
00076     Image<E>& operator=(const J& rhs);
00077 
00078     /*
00079       // provided by internal::image_base:
00080 
00081       typedef domain_t;
00082       typedef site;
00083       typedef psite;
00084 
00085       typedef piter;
00086       typedef fwd_piter;
00087       typedef bkd_piter;
00088 
00089       bool has(const psite& p) const;
00090       unsigned nsites() const; // If relevant.
00091 
00092       bool is_valid() const;
00093 
00094       typedef t_eligible_values_set;
00095       const t_eligible_values_set& values_eligible() const;
00096 
00097       typedef t_values_space;
00098       const t_values_space& values_space() const;
00099 
00100       typedef value;
00101 
00102       // to be provided in concrete image classes:
00103 
00104       typedef vset;
00105       const vset& values() const;
00106 
00107       typedef rvalue;
00108       typedef lvalue;
00109       rvalue operator()(const psite& p) const;
00110       lvalue operator()(const psite& p);
00111 
00112       const domain_t& domain() const;
00113 
00114       typedef skeleton;
00115      */
00116 
00117   protected:
00118     Image();
00119   };
00120 
00121 
00122   namespace convert
00123   {
00124 
00125     namespace over_load
00126     {
00127 
00128       template <typename V, unsigned S, typename I>
00129       void
00130       from_to_(const V (&values)[S], Image<I>& to);
00131 
00132     } // end of namespace mln::convert::over_load
00133 
00134   } // end of namespace mln::convert
00135 
00136 
00137 
00138 # ifndef MLN_INCLUDE_ONLY
00139 
00140 
00141   namespace internal
00142   {
00143 
00144     template <typename values_browsing_trait, typename E>
00145     struct image_values_interface_check
00146     {
00147       static void run() { /* No Requirement */}
00148     };
00149 
00150     template <typename E>
00151     struct image_values_interface_check<
00152       mln::trait::image::value_browsing::value_wise,
00153       E>
00154     {
00155       static void run()
00156       {
00157       }
00158     };
00159 
00160 
00161     // check_init
00162 
00163     template < typename E,
00164                typename A >
00165     int check_init(void (E::*)(A))
00166     {
00167       return 0;
00168     }
00169 
00170     template < typename E,
00171                typename A1, typename A2 >
00172     int check_init(void (E::*)(A1, A2))
00173     {
00174       return 0;
00175     }
00176 
00177     template < typename E,
00178                typename A1, typename A2, typename A3 >
00179     int check_init(void (E::*)(A1, A2, A3))
00180     {
00181       return 0;
00182     }
00183 
00184   } // end of namespace mln::internal
00185 
00186 
00187   template <typename E>
00188   template <typename J>
00189   inline
00190   Image<E>&
00191   Image<E>::operator=(const J&)
00192   {
00197     mlc_abort(E)::check();
00198     return *this;
00199   }
00200 
00201 
00202   template <typename E>
00203   inline
00204   Image<E>::Image()
00205   {
00206     // provided by internal::image_base:
00207 
00208     typedef mln_domain(E) domain_t;
00209     typedef mln_site(E)   site;
00210     typedef mln_psite(E)  psite;
00211 
00212     typedef mln_piter(E)     piter;
00213     typedef mln_fwd_piter(E) fwd_piter;
00214     typedef mln_bkd_piter(E) bkd_piter;
00215 
00216     bool (E::*m1)(const psite& p) const = & E::has;
00217     m1 = 0;
00218 
00219     // Only some image types feature the 'nsites' method.
00220 //     unsigned (E::*m2)() const = & E::nsites;
00221 //     m2 = 0;
00222 
00223     bool (E::*m3)() const = & E::is_valid;
00224     m3 = 0;
00225 
00226     typedef typename E::t_eligible_values_set t_eligible_values_set;
00227 
00228     const t_eligible_values_set& (E::*m4)() const = & E::values_eligible;
00229     m4 = 0;
00230 
00231     typedef typename E::t_values_space t_values_space;
00232 
00233     const t_values_space& (E::*m5)() const = & E::values_space;
00234     m5 = 0;
00235 
00236     // to be provided in concrete image classes:
00237 
00238     typedef mln_value(E)  value;
00239     typedef mln_rvalue(E) rvalue;
00240     typedef mln_lvalue(E) lvalue;
00241 
00242     // FIXME Doc
00243     //typedef mln_vset(E) vset;
00244     //const vset& (E::*m5)() const = & E::values;
00245     //m5 = 0;
00246 
00247     rvalue (E::*m6)(const psite& p) const = & E::operator();
00248     m6 = 0;
00249     lvalue (E::*m7)(const psite& p) = & E::operator();
00250     m7 = 0;
00251 
00252     const domain_t& (E::*m8)() const = & E::domain;
00253     m8 = 0;
00254 
00255     typedef typename E::skeleton skeleton;
00256 
00257     // Check E::init_ presence.  Since its signature varies from an
00258     // image type to another, that is the only thing we can ensure.
00259     internal::check_init(& E::init_);
00260 
00262     internal::image_values_interface_check<mln_trait_image_value_browsing(E),
00263       E>::run();
00264   }
00265 
00266 
00267   namespace convert
00268   {
00269 
00270     namespace over_load
00271     {
00272 
00273       template <typename V, unsigned S, typename I>
00274       void
00275       from_to_(const V (&values)[S], Image<I>& to_)
00276       {
00277         mlc_bool(S != 0)::check();
00278         mlc_converts_to(V, mln_value(I))::check();
00279         typedef mln_site(I) P;
00280         enum { d = P::dim,
00281           s = mlc_root(d, S)::value };
00282         metal::bool_<(mlc_pow_int(s, d) == S)>::check();
00283 
00284         I& to = exact(to_);
00285         mln_precondition(! to.is_valid());
00286 
00287         box<P> b(all_to(0), all_to(s - 1));
00288         to.init_(b);
00289         mln_fwd_piter(box<P>) p(b);
00290         unsigned i = 0;
00291         for_all(p)
00292           to(p) = values[i++];
00293       }
00294 
00295     } // end of namespace mln::convert::over_load
00296 
00297   } // end of namespace mln::convert
00298 
00299 # endif // ! MLN_INCLUDE_ONLY
00300 
00301 } // end of namespace mln
00302 
00303 
00304 # include <mln/core/routine/initialize.hh>
00305 
00306 
00307 #endif // ! MLN_CORE_CONCEPT_IMAGE_HH

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