Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
flat_image.hh
1 // Copyright (C) 2008, 2009, 2011 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_FLAT_IMAGE_HH
28 # define MLN_CORE_IMAGE_FLAT_IMAGE_HH
29 
35 
36 # include <mln/core/internal/image_primary.hh>
37 # include <mln/value/set.hh>
38 
39 
40 namespace mln
41 {
42 
43 
44  // Forward declaration.
45  template <typename T, typename S> struct flat_image;
46 
47 
48  namespace internal
49  {
50 
52  template <typename T, typename S>
53  struct data< flat_image<T,S> >
54  {
55  data(const T& val, const S& pset);
56 
57  T val_;
58  S domain_;
59  };
60 
61  } // end of namespace mln::internal
62 
63 
64 
65  namespace trait
66  {
67 
68  template <typename T, typename S>
69  struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> >
70  {
71  // misc
72  typedef trait::image::category::primary category;
73  typedef trait::image::speed::fast speed;
74  typedef trait::image::size::regular size;
75 
76  // value
77  typedef trait::image::vw_io::read_write vw_io;
79  typedef trait::image::vw_set::none vw_set;
80  typedef trait::image::value_access::direct value_access;
81  typedef trait::image::value_storage::singleton value_storage;
82  typedef mln::trait::image::value_browsing::value_wise value_browsing;
83  typedef trait::image::value_alignment::with_grid value_alignment;
84  typedef trait::image::value_io::read_only value_io;
85 
86  // site / domain
87  typedef trait::image::pw_io::read pw_io;
88  typedef trait::image::localization::basic_grid localization; // FIXME
89  typedef trait::image::dimension::two_d dimension; // FIXME
90 
91  // extended domain
92  typedef trait::image::ext_domain::infinite ext_domain;
93  typedef trait::image::ext_value::single ext_value;
94  typedef trait::image::ext_io::read_only ext_io;
95  };
96 
97  } // end of namespace mln::trait
98 
99 
100 
104  //
105  template <typename T, typename S>
106  struct flat_image : public internal::image_primary< T, S, flat_image<T,S> >
107  {
109  typedef flat_image< tag::value_<T>, tag::domain_<S> > skeleton;
110 
111 
113  typedef T value;
114 
116  typedef const T& rvalue;
117 
119  typedef T& lvalue;
120 
121 
123  flat_image();
124 
126  flat_image(const T& val, const S& pset);
127 
129  void init_(const T& val, const S& pset);
130 
132  const S& domain() const;
133 
135  bool has(const mln_psite(S)& p) const;
136 
137 
139  const T& operator()(const mln_psite(S)& p) const;
140 
142  T& operator()(const mln_psite(S)& p);
143 
144 
146  const T& value_() const;
147  T& value_();
148  };
149 
150 
151 
152  template <typename T, typename S, typename J>
153  void init_(tag::image_t, flat_image<T,S>& target, const J& model);
154 
155 
156 
157 # ifndef MLN_INCLUDE_ONLY
158 
159  // init_
160 
161  template <typename T, typename S, typename J>
162  inline
163  void init_(tag::image_t, flat_image<T,S>& target, const J& model)
164  {
165  S pset;
166  init_(tag::domain, pset, model);
167  T dummy;
168  target.init_(dummy, pset);
169  }
170 
171 
172  // internal::data< flat_image<T,S> >
173 
174  namespace internal
175  {
176 
177  template <typename T, typename S>
178  inline
179  data< flat_image<T,S> >::data(const T& val, const S& pset)
180  : val_(val),
181  domain_(pset)
182  {
183  }
184 
185  } // end of namespace mln::internal
186 
187 
188  // flat_image<T,S>
189 
190  template <typename T, typename S>
191  inline
193  {
194  }
195 
196  template <typename T, typename S>
197  inline
198  flat_image<T,S>::flat_image(const T& val, const S& pset)
199  {
200  init_(val, pset);
201  }
202 
203  template <typename T, typename S>
204  inline
205  void
206  flat_image<T,S>::init_(const T& val, const S& pset)
207  {
208  mln_precondition(! this->is_valid());
209  this->data_ = new internal::data< flat_image<T,S> >(val, pset);
210  }
211 
212  template <typename T, typename S>
213  inline
214  const S&
216  {
217  return this->data_->domain_;
218  }
219 
220  template <typename T, typename S>
221  inline
222  bool
223  flat_image<T,S>::has(const mln_psite(S)&) const
224  {
225  return true;
226  }
227 
228  template <typename T, typename S>
229  inline
230  const T&
231  flat_image<T,S>::operator()(const mln_psite(S)&) const
232  {
233  mln_precondition(this->is_valid());
234  return this->data_->val_;
235  }
236 
237  template <typename T, typename S>
238  inline
239  T&
240  flat_image<T,S>::operator()(const mln_psite(S)&)
241  {
242  mln_precondition(this->is_valid());
243  return this->data_->val_;
244  }
245 
246  template <typename T, typename S>
247  inline
248  const T&
250  {
251  mln_precondition(this->is_valid());
252  return this->data_->val_;
253  }
254 
255  template <typename T, typename S>
256  inline
257  T&
258  flat_image<T,S>::value_()
259  {
260  mln_precondition(this->is_valid());
261  return this->data_->val_;
262  }
263 
264 
265 
266 # endif // ! MLN_INCLUDE_ONLY
267 
268 } // end of namespace mln
269 
270 
271 #endif // ! MLN_CORE_IMAGE_FLAT_IMAGE_HH