00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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   
00045   namespace pw
00046   {
00047 
00048     namespace internal
00049     {
00050 
00051       template <typename F, typename S, typename E>
00052       class image_base;
00053 
00054     } 
00055 
00056   } 
00057 
00058   namespace trait
00059   {
00060 
00061     
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         
00073         typedef trait::image::category::primary category;
00074         typedef trait::image::speed::fast       speed;
00075         typedef trait::image::size::regular     size;
00076 
00077         
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         
00089         typedef mlc_if(is_mutable,
00090             trait::image::pw_io::read_write,
00091             trait::image::pw_io::read) pw_io;
00092         typedef   undef  localization;
00093         typedef   undef  dimension;
00094 
00095         
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   } 
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     } 
00155 
00156   } 
00157 
00158 
00159   
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   
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     } 
00248 
00249   } 
00250 
00251 # endif // ! MLN_INCLUDE_ONLY
00252 
00253 } 
00254 
00255 
00256 #endif // ! MLN_PW_INTERNAL_IMAGE_BASE_HH