Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
pw/internal/image_base.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_PW_INTERNAL_IMAGE_BASE_HH
27 # define MLN_PW_INTERNAL_IMAGE_BASE_HH
28 
32 
33 # include <mln/core/internal/image_primary.hh>
34 # include <mln/core/routine/init.hh>
35 # include <mln/metal/unqualif.hh>
36 # include <mln/metal/not_equal.hh>
37 # include <mln/value/set.hh>
38 
39 
40 namespace mln
41 {
42 
43 
44  // Forward declaration.
45  namespace pw
46  {
47 
48  namespace internal
49  {
50 
51  template <typename F, typename S, typename E>
52  class image_base;
53 
54  } // end of namespace mln::pw::internal
55 
56  } // end of namespace mln::pw
57 
58  namespace trait
59  {
60 
61  // FIXME: the result type should *not* be qualified
62 
63  template <typename F, typename S, typename E>
64  struct pw_image_
65  : default_image_<mln_result(F),E>
66  {
67  private:
68  typedef typename F::mutable_result mutable_result;
69  typedef mlc_not_equal(mutable_result, void) is_mutable;
70 
71  public:
72  // misc
73  typedef trait::image::category::primary category;
74  typedef trait::image::speed::fast speed;
75  typedef trait::image::size::regular size;
76 
77  // value
78  typedef trait::image::vw_io::none vw_io;
79  typedef trait::image::vw_set::none vw_set;
80  typedef trait::image::value_access::computed value_access;
81  typedef trait::image::value_storage::disrupted value_storage;
82  typedef trait::image::value_browsing::site_wise_only value_browsing;
83  typedef trait::image::value_alignment::irrelevant value_alignment;
84  typedef mlc_if(is_mutable,
85  trait::image::value_io::read_write,
86  trait::image::value_io::read_only) value_io;
87 
88  // site / domain
89  typedef mlc_if(is_mutable,
90  trait::image::pw_io::read_write,
91  trait::image::pw_io::read) pw_io;
92  typedef /* FIXME: depends on S */ undef localization;
93  typedef /* FIXME: depends on S */ undef dimension;
94 
95  // extended domain
96  typedef trait::image::ext_domain::none ext_domain;
97  typedef trait::image::ext_value::irrelevant ext_value;
98  typedef trait::image::ext_io::irrelevant ext_io;
99  };
100 
101  } // end of namespace mln::trait
102 
103 
104  namespace pw
105  {
106 
107  namespace internal
108  {
109 
113  template <typename F, typename S, typename E>
114  class image_base
115  : public mln::internal::image_primary<mln_result(F), S, E >
116  {
117  typedef typename F::mutable_result mutable_result;
118  typedef mlc_not_equal(mutable_result, void) is_mutable;
119 
120  public:
122  typedef F function_t;
123 
125  typedef mln_result(F) value;
126 
128  typedef mln_result(F) rvalue;
129 
131  typedef mlc_if(is_mutable, mutable_result, mln_result(F)) lvalue;
132 
134  void init_(const Function_v2v<F>& f, const Site_Set<S>& ps);
135 
137  const S& domain() const;
138 
140  F function() const;
141 
143  rvalue operator()(const mln_psite(S)& p) const;
144 
147  lvalue operator()(const mln_psite(S)& p);
148 
149  protected:
150  image_base();
151  image_base(const Function_v2v<F>& f, const Site_Set<S>& ps);
152  };
153 
154  } // end of namespace mln::pw::internal
155 
156  } // end of namespace mln::pw
157 
158 
159  // init_
160 
161  template <typename F, typename S, typename E>
162  void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model);
163 
164  template <typename F1, typename F2, typename S, typename E>
165  void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model);
166 
167 
168 # ifndef MLN_INCLUDE_ONLY
169 
170  // init_
171 
172  template <typename F, typename S, typename E>
173  void init_(tag::function_t, F& f, const pw::internal::image_base<F,S,E>& model)
174  {
175  f = model.function();
176  }
177 
178  template <typename F1, typename F2, typename S, typename E>
179  void init_(tag::function_t, F1& f, const pw::internal::image_base<F2,S,E>& model)
180  {
181  init_(tag::function, f, model.function());
182  }
183 
184 
185  namespace pw
186  {
187 
188  namespace internal
189  {
190 
191  template <typename F, typename S, typename E>
192  inline
193  image_base<F,S,E>::image_base()
194  {
195  }
196 
197  template <typename F, typename S, typename E>
198  inline
199  image_base<F,S,E>::image_base(const Function_v2v<F>& f, const Site_Set<S>& ps)
200  {
201  this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
202  }
203 
204  template <typename F, typename S, typename E>
205  inline
206  void
207  image_base<F,S,E>::init_(const Function_v2v<F>& f, const Site_Set<S>& ps)
208  {
209  this->data_ = new mln::internal::data<E>(exact(f), exact(ps));
210  }
211 
212  template <typename F, typename S, typename E>
213  inline
214  const S&
215  image_base<F,S,E>::domain() const
216  {
217  return this->data_->domain_;
218  }
219 
220  template <typename F, typename S, typename E>
221  inline
222  F
223  image_base<F,S,E>:: function() const
224  {
225  return this->data_->f_;
226  }
227 
228 
229  template <typename F, typename S, typename E>
230  inline
231  typename image_base<F,S,E>::rvalue
232  image_base<F,S,E>::operator()(const mln_psite(S)& p) const
233  {
234  mln_precondition(this->data_->domain_.has(p));
235  return this->data_->f_(p);
236  }
237 
238  template <typename F, typename S, typename E>
239  inline
240  typename image_base<F,S,E>::lvalue
241  image_base<F,S,E>::operator()(const mln_psite(S)& p)
242  {
243  mln_precondition(this->data_->domain_.has(p));
244  return this->data_->f_(p);
245  }
246 
247  } // end of namespace mln::pw::internal
248 
249  } // end of namespace mln::pw
250 
251 # endif // ! MLN_INCLUDE_ONLY
252 
253 } // end of namespace mln
254 
255 
256 #endif // ! MLN_PW_INTERNAL_IMAGE_BASE_HH