Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
sub_image_if.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_DMORPH_SUB_IMAGE_IF_HH
28 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH
29 
30 
36 
37 
38 # include <mln/core/internal/image_domain_morpher.hh>
39 # include <mln/core/site_set/p_if.hh>
40 # include <mln/fun/p2b/has.hh>
41 
42 # include <mln/debug/println.hh>
43 
44 
45 namespace mln
46 {
47 
48 
49  // Forward declaration.
50  template <typename I, typename S> struct sub_image_if;
51 
52 
53  namespace internal
54  {
55 
57  template <typename I, typename S>
58  struct data< sub_image_if<I,S> >
59  {
60  data(I& ima, const S& s);
61 
62  I ima_;
63  p_if< S, fun::p2b::has<I> > s_;
64  };
65 
66  } // end of namespace mln::internal
67 
68 
69 
70  namespace trait
71  {
72 
73  template <typename I, typename S>
74  struct image_< sub_image_if<I,S> > : default_image_morpher< I,
75  mln_value(I),
76  sub_image_if<I,S> >
77  {
78 // private:
79 // typedef mln_trait_image_data(I) I_data_;
80 // typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
81 // public:
82 
83  typedef trait::image::category::domain_morpher category;
84 
85  typedef trait::image::ext_domain::none ext_domain; // No extension of domain.
86  typedef trait::image::ext_value::irrelevant ext_value;
87  typedef trait::image::ext_io::irrelevant ext_io;
88 
89  typedef trait::image::value_storage::disrupted value_storage;
90  // HOT FIXME: except if S is a Box
91  };
92 
93  } // end of namespace mln::trait
94 
95 
96 
100  //
101  template <typename I, typename S>
102  struct sub_image_if : public internal::image_domain_morpher< I,
103  p_if< S, fun::p2b::has<I> >,
104  sub_image_if<I,S> >
105  {
107  typedef sub_image_if< tag::image_<I>, tag::domain_<S> > skeleton;
108 
110  sub_image_if();
111 
113  sub_image_if(I& ima, const S& s);
114 
116  void init_(I& ima, const S& s);
117 
119  const p_if< S, fun::p2b::has<I> >& domain() const;
120 
121 // /// Const promotion via conversion.
122 // operator sub_image_if<const I, S>() const;
123  };
124 
125 
126 
127 
128 
129  template <typename I, typename S>
131  operator / (const Image<I>& ima, const Site_Set<S>& s);
132 
133 
134  template <typename I, typename S>
136  operator / (Image<I>& ima, const Site_Set<S>& s);
137 
138 
139  template <typename I, typename S, typename J>
140  void init_(tag::image_t, sub_image_if<I,S>& target, const J& model);
141 
142 
143 
144 # ifndef MLN_INCLUDE_ONLY
145 
146  // init_
147 
148  template <typename I, typename S, typename J>
149  inline
150  void init_(tag::image_t, sub_image_if<I,S>& target, const J& model)
151  {
152  I ima;
153  init_(tag::image, ima, model);
154  S s;
155  init_(tag::domain, s, model);
156  target.init_(ima, s);
157  }
158 
159 
160  // internal::data< sub_image_if<I,S> >
161 
162  namespace internal
163  {
164 
165  template <typename I, typename S>
166  inline
167  data< sub_image_if<I,S> >::data(I& ima, const S& s)
168  : ima_(ima)
169  {
170  typedef fun::p2b::has<I> F;
171  F f(ima);
172  s_ = p_if<S,F>(s, f);
173  }
174 
175  } // end of namespace mln::internal
176 
177 
178  // sub_image_if<I,S>
179 
180  template <typename I, typename S>
181  inline
183  {
184  }
185 
186  template <typename I, typename S>
187  inline
189  {
190  init_(ima, s);
191  }
192 
193  template <typename I, typename S>
194  inline
195  void
196  sub_image_if<I,S>::init_(I& ima, const S& s)
197  {
198  mln_precondition(! this->is_valid());
199  this->data_ = new internal::data< sub_image_if<I,S> >(ima, s);
200  }
201 
202  template <typename I, typename S>
203  inline
204  const p_if< S, fun::p2b::has<I> >&
206  {
207  return this->data_->s_;
208  }
209 
210 // template <typename I, typename S>
211 // inline
212 // sub_image_if<I,S>::operator sub_image_if<const I, S>() const
213 // {
214 // sub_image_if<const I, S> tmp(this->data_->ima_,
215 // this->data_->s_);
216 // return tmp;
217 // }
218 
219 
220  // Operators.
221 
222  template <typename I, typename S>
223  inline
225  operator / (const Image<I>& ima, const Site_Set<S>& s)
226  {
227  // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
228  sub_image_if<const I, S> tmp(exact(ima), exact(s));
229  return tmp;
230  }
231 
232  template <typename I, typename S>
233  inline
234  sub_image_if<I, S>
235  operator / (Image<I>& ima, const Site_Set<S>& s)
236  {
237  // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
238  sub_image_if<I, S> tmp(exact(ima), exact(s));
239  return tmp;
240  }
241 
242 # endif // ! MLN_INCLUDE_ONLY
243 
244 } // end of namespace mln
245 
246 
247 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH