$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/internal/image_base.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013, 2014 EPITA Research and
2 // Development 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_INTERNAL_IMAGE_BASE_HH
28 # define MLN_CORE_INTERNAL_IMAGE_BASE_HH
29 
35 
36 
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/grids.hh>
39 # include <mln/core/trait/qlf_value.hh>
40 # include <mln/core/internal/check/image_all.hh>
41 # include <mln/core/internal/data.hh>
42 # include <mln/core/internal/morpher_lvalue.hh>
43 # include <mln/util/tracked_ptr.hh>
44 # include <mln/value/set.hh>
45 # include <mln/value/super_value.hh>
46 
47 
48 namespace mln
49 {
50 
51  namespace internal
52  {
53 
54 
55  template <typename E>
56  struct image_checked_
57  :
58  public check::image_all_<E>,
59  public Image<E>
60  {
61  };
62 
63 
85  template <typename T, typename S, typename E>
86  struct image_base
87  :
88  public image_checked_<E>
89 
90  {
92  typedef T value;
93 
96 
97  // Return the set of the image eligigle values
99 
101  typedef mln::value::set<
103 
105  const t_values_space& values_space() const;
106 
107 
109  typedef S domain_t;
110 
112  typedef mln_psite(S) psite;
113 
115  typedef mln_site(S) site;
116 
117 
119  typedef mln_fwd_piter(S) fwd_piter;
120 
122  typedef mln_bkd_piter(S) bkd_piter;
123 
124 
127  typedef fwd_piter piter;
128 
129 
130 
132  bool has(const psite& p) const;
133 
135  std::size_t nsites() const;
136 
138  bool is_valid() const;
139 
140  // FIXME: Add void init_data(..);
141 
142 
144  image_base& operator=(const image_base& rhs);
145 
147  image_base(const image_base& rhs);
148 
149 
151 
158  const void* id_() const;
159 
161  const mln::util::tracked_ptr< internal::data<E> >& hook_data_() const;
162 
164 
165 
167  void destroy();
168 
169  protected:
170 
172  image_base();
173 
176  mln::util::tracked_ptr< internal::data<E> > data_;
178  };
179 
180 
181 # ifndef MLN_INCLUDE_ONLY
182 
183  template <typename T, typename S, typename E>
184  inline
186  {
187  }
188 
189  template <typename T, typename S, typename E>
190  inline
191  image_base<T, S, E>::image_base(const image_base& rhs)
192  : image_checked_<E>()
193  {
194  mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive?
195  this->data_ = rhs.data_;
196  }
197 
198  template <typename T, typename S, typename E>
199  inline
200  image_base<T, S, E>&
201  image_base<T, S, E>::operator=(const image_base<T, S, E>& rhs)
202  {
203  mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive?
204  if (& rhs == this) // || ! exact(rhs).is_valid())
205  return *this;
206  this->data_ = rhs.data_;
207  return *this;
208  }
209 
210  template <typename T, typename S, typename E>
211  inline
212  const void*
213  image_base<T, S, E>::id_() const
214  {
215  return data_.ptr_;
216  }
217 
218  template <typename T, typename S, typename E>
219  inline
220  bool
221  image_base<T, S, E>::is_valid() const
222  {
223  return data_ != 0;
224  }
225 
226  template <typename T, typename S, typename E>
227  inline
228  bool
229  image_base<T, S, E>::has(const psite& p) const
230  {
231  mln_precondition(exact(this)->is_valid());
232  return exact(this)->domain().has(p);
233  }
234 
235  template <typename T, typename S, typename E>
236  inline
237  std::size_t
239  {
240  mlc_equal(mln_trait_site_set_nsites(S),
241  mln::trait::site_set::nsites::known)::check();
242  mln_precondition(exact(this)->is_valid());
243  return exact(this)->domain().nsites();
244  }
245 
246  template <typename T, typename S, typename E>
247  inline
248  const typename image_base<T, S, E>::t_eligible_values_set&
249  image_base<T, S, E>::values_eligible() const
250  {
251  return t_eligible_values_set::the();
252  }
253 
254  template <typename T, typename S, typename E>
255  inline
256  const typename image_base<T, S, E>::t_values_space&
257  image_base<T, S, E>::values_space() const
258  {
259  return t_values_space::the();
260  }
261 
262  template <typename T, typename S, typename E>
263  inline
264  void
265  image_base<T, S, E>::destroy()
266  {
267  data_.clean_();
268  }
269 
270  template <typename T, typename S, typename E>
271  inline
273  image_base<T, S, E>::hook_data_() const
274  {
275  return data_;
276  }
277 
278 # endif // ! MLN_INCLUDE_ONLY
279 
280  } // end of namespace mln::internal
281 
282 } // end of namespace mln
283 
284 #endif // ! MLN_CORE_INTERNAL_IMAGE_BASE_HH