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

image_base.hh

00001 // Copyright (C) 2009, 2010 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_PW_INTERNAL_IMAGE_BASE_HH
00027 # define MLN_PW_INTERNAL_IMAGE_BASE_HH
00028 
00032 
00033 # include <mln/core/internal/image_primary.hh>
00034 # include <mln/core/routine/init.hh>
00035 # include <mln/metal/unqualif.hh>
00036 # include <mln/metal/not_equal.hh>
00037 # include <mln/value/set.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043 
00044   // Forward declaration.
00045   namespace pw
00046   {
00047 
00048     namespace internal
00049     {
00050 
00051       template <typename F, typename S, typename E>
00052       class image_base;
00053 
00054     } // end of namespace mln::pw::internal
00055 
00056   } // end of namespace mln::pw
00057 
00058   namespace trait
00059   {
00060 
00061     // FIXME: the result type should *not* be qualified
00062 
00063     template <typename F, typename S, typename E>
00064       struct pw_image_
00065       : default_image_<mln_result(F),E>
00066     {
00067       private:
00068         typedef typename F::mutable_result mutable_result;
00069         typedef mlc_not_equal(mutable_result, void) is_mutable;
00070 
00071       public:
00072         // misc
00073         typedef trait::image::category::primary category;
00074         typedef trait::image::speed::fast       speed;
00075         typedef trait::image::size::regular     size;
00076 
00077         // value
00078         typedef trait::image::vw_io::none                    vw_io;
00079         typedef trait::image::vw_set::none                   vw_set;
00080         typedef trait::image::value_access::computed         value_access;
00081         typedef trait::image::value_storage::disrupted       value_storage;
00082         typedef trait::image::value_browsing::site_wise_only value_browsing;
00083         typedef trait::image::value_alignment::irrelevant    value_alignment;
00084         typedef mlc_if(is_mutable,
00085             trait::image::value_io::read_write,
00086             trait::image::value_io::read_only)    value_io;
00087 
00088         // site / domain
00089         typedef mlc_if(is_mutable,
00090             trait::image::pw_io::read_write,
00091             trait::image::pw_io::read) pw_io;
00092         typedef /* FIXME: depends on S */  undef  localization;
00093         typedef /* FIXME: depends on S */  undef  dimension;
00094 
00095         // extended domain
00096         typedef trait::image::ext_domain::none      ext_domain;
00097         typedef trait::image::ext_value::irrelevant ext_value;
00098         typedef trait::image::ext_io::irrelevant    ext_io;
00099     };
00100 
00101   } // end of namespace mln::trait
00102 
00103 
00104   namespace pw
00105   {
00106 
00107     namespace internal
00108     {
00109 
00113       template <typename F, typename S, typename E>
00114       class image_base
00115         : public mln::internal::image_primary<mln_result(F), S, E >
00116       {
00117         typedef typename F::mutable_result mutable_result;
00118         typedef mlc_not_equal(mutable_result, void) is_mutable;
00119 
00120       public:
00122         typedef F function_t;
00123 
00125         typedef mln_result(F) value;
00126 
00128         typedef mln_result(F) rvalue;
00129 
00131         typedef mlc_if(is_mutable, mutable_result, mln_result(F)) lvalue;
00132 
00134         void init_(const Function_v2v<F>& f, const Site_Set<S>& ps);
00135 
00137         const S& domain() const;
00138 
00140         F function() const;
00141 
00143         rvalue operator()(const mln_psite(S)& p) const;
00144 
00147         lvalue operator()(const mln_psite(S)& p);
00148 
00149       protected:
00150         image_base();
00151         image_base(const Function_v2v<F>& f, const Site_Set<S>& ps);
00152       };
00153 
00154     } // end of namespace mln::pw::internal
00155 
00156   } // end of namespace mln::pw
00157 
00158 
00159   // init_
00160 
00161   template <typename F, typename S, typename E>
00162   void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model);
00163 
00164   template <typename F1, typename F2, typename S, typename E>
00165   void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model);
00166 
00167 
00168 # ifndef MLN_INCLUDE_ONLY
00169 
00170   // init_
00171 
00172   template <typename F, typename S, typename E>
00173   void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model)
00174   {
00175     f = model.function();
00176   }
00177 
00178   template <typename F1, typename F2, typename S, typename E>
00179   void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model)
00180   {
00181     init_(tag::function, f, model.function());
00182   }
00183 
00184 
00185   namespace pw
00186   {
00187 
00188     namespace internal
00189     {
00190 
00191       template <typename F, typename S, typename E>
00192       inline
00193       image_base<F,S,E>::image_base()
00194       {
00195       }
00196 
00197       template <typename F, typename S, typename E>
00198       inline
00199       image_base<F,S,E>::image_base(const Function_v2v<F>& f, const Site_Set<S>& ps)
00200       {
00201         this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
00202       }
00203 
00204       template <typename F, typename S, typename E>
00205       inline
00206       void
00207       image_base<F,S,E>::init_(const Function_v2v<F>& f, const Site_Set<S>& ps)
00208       {
00209         this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
00210       }
00211 
00212       template <typename F, typename S, typename E>
00213       inline
00214       const S&
00215       image_base<F,S,E>::domain() const
00216       {
00217         return this->data_->domain_;
00218       }
00219 
00220       template <typename F, typename S, typename E>
00221       inline
00222       F
00223       image_base<F,S,E>:: function() const
00224       {
00225         return this->data_->f_;
00226       }
00227 
00228 
00229       template <typename F, typename S, typename E>
00230       inline
00231       typename image_base<F,S,E>::rvalue
00232       image_base<F,S,E>::operator()(const mln_psite(S)& p) const
00233       {
00234         mln_precondition(this->data_->domain_.has(p));
00235         return this->data_->f_(p);
00236       }
00237 
00238       template <typename F, typename S, typename E>
00239       inline
00240       typename image_base<F,S,E>::lvalue
00241       image_base<F,S,E>::operator()(const mln_psite(S)& p)
00242       {
00243         mln_precondition(this->data_->domain_.has(p));
00244         return this->data_->f_(p);
00245       }
00246 
00247     } // end of namespace mln::pw::internal
00248 
00249   } // end of namespace mln::pw
00250 
00251 # endif // ! MLN_INCLUDE_ONLY
00252 
00253 } // end of namespace mln
00254 
00255 
00256 #endif // ! MLN_PW_INTERNAL_IMAGE_BASE_HH

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