27 #ifndef MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH
28 # define MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH
35 # include <mln/core/internal/image_identity.hh>
43 template <
typename I,
typename J>
class mutable_extension_ima;
50 template <
typename I,
typename J>
51 struct data< mutable_extension_ima<I, J> >
65 template <
typename I,
typename J>
66 struct image_< mutable_extension_ima<I, J> > : image_< I >
69 typedef trait::image::category::identity_morpher
category;
70 typedef mln_internal_trait_image_speed_from(I)
speed;
79 template <typename I, typename J, typename V>
82 typedef mlc_converts_to(mln_value(J), V)
keep_ext;
83 typedef mln_ch_value(I, V)
Iv;
85 typedef mlc_if(keep_ext, Iv_ext, Iv)
ret;
96 template <typename I, typename J>
100 private mlc_converts_to(mln_value(J), mln_value(I))::check_t
121 void init_(I& ima, J& ext);
126 template <typename P>
127 bool has(const P&
p) const;
131 mln_value(I) operator()(const mln_psite(I)&
p) const;
134 mln_lvalue(I) operator()(const mln_psite(I)&
p);
144 template <typename I, typename J, typename M>
147 template <typename J, typename I>
152 # ifndef MLN_INCLUDE_ONLY
159 template <
typename I,
typename J>
171 template <
typename I,
typename J>
177 template <
typename I,
typename J>
179 mutable_extension_ima<I, J>::mutable_extension_ima(I& ima, J& ext)
184 template <
typename I,
typename J>
189 this->data_ =
new internal::data< mutable_extension_ima<I, J> >(ima, ext);
192 template <
typename I,
typename J>
193 template <
typename P>
196 mutable_extension_ima<I, J>::has(
const P& p)
const
198 mln_precondition(this->is_valid());
199 mln_precondition(this->data_->ext_.is_valid());
201 this->data_->ima_.domain().has(p)
202 || this->data_->ext_.has(p);
205 template <
typename I,
typename J>
208 mutable_extension_ima<I, J>::operator()(const mln_psite(I)& p)
const
210 mln_precondition(this->is_valid());
211 mln_precondition(
has(p));
214 if (this->data_->ima_.domain().has(p))
215 return this->data_->ima_(p);
217 return this->data_->ext_(p);
220 template <
typename I,
typename J>
223 mutable_extension_ima<I, J>::operator()(const mln_psite(I)& p)
225 mln_precondition(this->is_valid());
226 mln_precondition(
has(p));
229 if (this->data_->ima_.domain().has(p))
230 return this->data_->ima_(p);
232 return this->data_->ext_(p);
235 template <
typename I,
typename J>
238 mutable_extension_ima<I, J>::extension()
240 mln_precondition(this->is_valid());
241 return this->data_->ext_;
246 template <
typename I,
typename J,
typename M>
248 void init_(tag::image_t, mutable_extension_ima<I,J>& target,
const M& model)
254 target.init_(ima, ext);
257 template <
typename J,
typename I>
259 void init_(tag::extension_t, J& target,
const mutable_extension_ima<I,J>& model)
261 typedef mlc_unconst(J) J_;
262 J_& ext_ = const_cast< mutable_extension_ima<I,J>& >(model).extension();
263 J_& target_ = const_cast<J_&>(target);
267 # endif // ! MLN_INCLUDE_ONLY
272 #endif // ! MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH