$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mutable_extension_ima.hh
1 // Copyright (C) 2008, 2009, 2010, 2014 EPITA Research and Development
2 // Laboratory (LRDE).
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH
28 # define MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH
29 
34 
35 # include <mln/core/internal/image_identity.hh>
36 
37 
38 
39 namespace mln
40 {
41 
42  // Forward declaration.
43  template <typename I, typename J> class mutable_extension_ima;
44 
45 
46  namespace internal
47  {
48 
50  template <typename I, typename J>
51  struct data< mutable_extension_ima<I, J> >
52  {
53  data(I& ima, J& ext);
54 
55  I ima_;
56  J ext_;
57  };
58 
59  } // end of namespace mln::internal
60 
61 
62  namespace trait
63  {
64 
65  template <typename I, typename J>
66  struct image_< mutable_extension_ima<I, J> > : image_< I > // Same as I except...
67  {
68  // ...these changes.
69  typedef trait::image::category::identity_morpher category;
70  typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
71  typedef trait::image::value_access::indirect value_access;
72 
73  // extended domain
74  typedef trait::image::ext_domain::extendable ext_domain;
75  typedef trait::image::ext_value::multiple ext_value;
76  typedef trait::image::ext_io::read_only ext_io;
77  };
78 
79  template <typename I, typename J, typename V>
80  struct ch_value< mutable_extension_ima<I, J>, V >
81  {
82  typedef mlc_converts_to(mln_value(J), V) keep_ext;
83  typedef mln_ch_value(I, V) Iv;
84  typedef mutable_extension_ima<Iv, J> Iv_ext;
85  typedef mlc_if(keep_ext, Iv_ext, Iv) ret;
86  };
87 
88  } // end of namespace mln::trait
89 
90 
91 
95  //
96  template <typename I, typename J>
98 
99  : public internal::image_identity< I, mln_domain(I), mutable_extension_ima<I, J> >,
100  private mlc_converts_to(mln_value(J), mln_value(I))::check_t
101  {
102  public:
103 
106 
108  typedef mln_value(I) value;
109 
111  typedef mln_value(I) rvalue;
112 
115 
117  mutable_extension_ima(I& ima, J& ext);
118 
121  void init_(I& ima, J& ext);
122 
123 
125  // Tech note: the 'template' allows for multiple input.
126  template <typename P>
127  bool has(const P& p) const;
128 
129 
131  mln_value(I) operator()(const mln_psite(I)& p) const;
132 
134  mln_lvalue(I) operator()(const mln_psite(I)& p);
135 
136 
138  J& extension() ;
139  };
140 
141 
142  // init_
143 
144  template <typename I, typename J, typename M>
145  void init_(tag::image_t, mutable_extension_ima<I,J>& target, const M& model);
146 
147  template <typename J, typename I>
148  void init_(tag::extension_t, J& target, const mutable_extension_ima<I,J>& model);
149 
150 
151 
152 # ifndef MLN_INCLUDE_ONLY
153 
154  // internal::data< mutable_extension_ima<I,S> >
155 
156  namespace internal
157  {
158 
159  template <typename I, typename J>
160  inline
162  : ima_(ima),
163  ext_(ext)
164  {
165  }
166 
167  } // end of namespace mln::internal
168 
169  // mutable_extension_ima<I, J>
170 
171  template <typename I, typename J>
172  inline
174  {
175  }
176 
177  template <typename I, typename J>
178  inline
179  mutable_extension_ima<I, J>::mutable_extension_ima(I& ima, J& ext)
180  {
181  init_(ima, ext);
182  }
183 
184  template <typename I, typename J>
185  inline
186  void
187  mutable_extension_ima<I, J>::init_(I& ima, J& ext)
188  {
189  this->data_ = new internal::data< mutable_extension_ima<I, J> >(ima, ext);
190  }
191 
192  template <typename I, typename J>
193  template <typename P>
194  inline
195  bool
196  mutable_extension_ima<I, J>::has(const P& p) const
197  {
198  mln_precondition(this->is_valid());
199  mln_precondition(this->data_->ext_.is_valid());
200  return
201  this->data_->ima_.domain().has(p)
202  || this->data_->ext_.has(p);
203  }
204 
205  template <typename I, typename J>
206  inline
207  mln_value(I)
208  mutable_extension_ima<I, J>::operator()(const mln_psite(I)& p) const
209  {
210  mln_precondition(this->is_valid());
211  mln_precondition(has(p));
212  // if-else is preferred to the ternary op to allow for the
213  // function result to convert towards the expected return type.
214  if (this->data_->ima_.domain().has(p))
215  return this->data_->ima_(p);
216  else
217  return this->data_->ext_(p);
218  }
219 
220  template <typename I, typename J>
221  inline
222  mln_lvalue(I)
223  mutable_extension_ima<I, J>::operator()(const mln_psite(I)& p)
224  {
225  mln_precondition(this->is_valid());
226  mln_precondition(has(p));
227  // if-else is preferred to the ternary op to allow for the
228  // function result to convert towards the expected return type.
229  if (this->data_->ima_.domain().has(p))
230  return this->data_->ima_(p);
231  else
232  return this->data_->ext_(p);
233  }
234 
235  template <typename I, typename J>
236  inline
237  J&
238  mutable_extension_ima<I, J>::extension()
239  {
240  mln_precondition(this->is_valid());
241  return this->data_->ext_;
242  }
243 
244  // init_
245 
246  template <typename I, typename J, typename M>
247  inline
248  void init_(tag::image_t, mutable_extension_ima<I,J>& target, const M& model)
249  {
250  I ima;
251  init_(tag::image, ima, model);
252  J ext;
253  init_(tag::extension, ext, model);
254  target.init_(ima, ext);
255  }
256 
257  template <typename J, typename I>
258  inline
259  void init_(tag::extension_t, J& target, const mutable_extension_ima<I,J>& model)
260  {
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);
264  target_ = ext_;
265  }
266 
267 # endif // ! MLN_INCLUDE_ONLY
268 
269 } // end of namespace mln
270 
271 
272 #endif // ! MLN_CORE_IMAGE_DMORPH_MUTABLE_EXTENSION_IMA_HH