Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
ch_value.hh
1 // Copyright (C) 2007, 2008, 2009 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_TRAIT_CH_VALUE_HH
28 # define MLN_TRAIT_CH_VALUE_HH
29 
33 
34 # include <mln/tag/skeleton.hh>
35 # include <mln/trait/image_from_grid.hh>
36 # include <mln/trait/ch_function_value.hh>
37 
38 
39 # define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret
40 # define mln_ch_value_(I, V) mln::trait::ch_value< I, V >::ret
41 
42 
43 
44 namespace mln
45 {
46 
47  // Forward declarations.
48  namespace algebra { template <unsigned n, typename T> class vec; }
49  template <typename G, typename F> class p_edges;
50  template <typename G, typename F> class p_vertices;
51  template <typename P, typename V, typename G> class vertex_image;
52  template <typename P, typename V, typename G> class edge_image;
53  template <typename I> class labeled_image;
54  namespace pw { template <typename F, typename S> class image; }
55 
56 
57 
58  namespace trait
59  {
60 
61  // Forward declaration.
62  template <typename I, typename V> struct ch_value;
63 
64 
65  namespace impl
66  {
67 
68  // Declaration.
69  template <typename I, typename V> struct ch_value_;
70 
71  template <typename I, typename V>
72  struct ch_value_< tag::image_<I>, V >
73  {
74  typedef mln_ch_value(I, V) ret;
75  };
76 
77  template < template <class> class M, typename T,
78  typename V >
79  struct ch_value_< M< tag::value_<T> >, V >
80  {
81  typedef M< V > ret;
82  };
83 
84  template < template <class> class M, typename I,
85  typename V >
86  struct ch_value_< M< tag::image_<I> >, V >
87  {
88  typedef M< mln_ch_value(I, V) > ret;
89  };
90 
91  template < template <class, class> class M, typename T, typename I,
92  typename V >
93  struct ch_value_< M< tag::value_<T>, tag::image_<I> >, V >
94  {
95  typedef mln_ch_value(I, V) ret;
96  };
97 
98  template < template <class, class> class M, typename P, typename T,
99  typename V >
100  struct ch_value_< M< tag::psite_<P>, tag::value_<T> >, V >
101  {
102  typedef M< P, V > ret;
103  };
104 
105  template < template <class, class> class M, typename I1, typename I2,
106  typename V >
107  struct ch_value_< M< tag::image_<I1>, tag::image_<I2> >, V >
108  {
109  typedef M< mln_ch_value(I1, V), mln_ch_value(I2, V) > ret;
110  };
111 
112  template < template <class, class> class M, typename I, typename E,
113  typename V >
114  struct ch_value_< M< tag::image_<I>, tag::ext_<E> >, V >
115  {
116  typedef M< mln_ch_value(I, V), E > ret;
117  };
118 
119 //<<lrde
120  // For mln::value::stack_image<n,I>.
121  template < template <unsigned, class> class M, unsigned n, typename I,
122  typename V >
123  struct ch_value_< M< n, tag::image_<I> >, V >
124  {
125  /* FIXME: The code used to read
126 
127  typedef algebra::vec<n, V> value;
128  typedef mln_ch_value(I, value) ret;
129 
130  here. But this is wrong IMHO (Roland). Changing the value
131  type of a stack image (in fact, a vectorial image) shall
132  alter the *value type* of the image, not the type of the
133  *components* of the vector. Hence the current definition. */
134  typedef mln_ch_value(I, V) ret;
135  };
136 //>>
137 
138  // For mln::complex_image<D, G, T>.
139  template < template <unsigned, class, class> class M,
140  unsigned D, typename G, typename T, typename V >
141  struct ch_value_< M< D, tag::psite_<G>, tag::value_<T> >, V >
142  {
143  typedef M< D, G, V > ret;
144  };
145 
146  // For mln::neighb::image<I, N>.
147  template < template <class, class> class M, typename I, typename N,
148  typename V >
149  struct ch_value_< M< tag::image_<I>, tag::neighb_<N> >, V >
150  {
151  typedef M < mln_ch_value(I, V), N > ret;
152  };
153 
154  template < template <class, class> class M, typename I, typename S,
155  typename V >
156  struct ch_value_< M< tag::image_<I>, tag::domain_<S> >, V >
157  {
158  typedef M< mln_ch_value(I, V), S > ret;
159  };
160 
161  template < template <class, class> class M, typename F, typename S,
162  typename V >
163  struct ch_value_< M< tag::function_<F>, tag::domain_<S> >, V >
164  {
165  // FIXME: what about S::site having no grid?
166  typedef mln_deduce(S, site, grid) grid;
167  typedef typename image_from_grid< grid, V >::ret ret;
168  };
169 
170 
171  // Graph image based on p_edges
172  template < typename F,
173  typename G, typename FP,
174  typename V >
175  struct ch_value_< pw::image< tag::function_<F>, tag::domain_<p_edges<G, FP> > >, V >
176  {
177  typedef pw::image< mln_ch_function_value(F, V), p_edges<G, FP> > ret;
178  };
179 
180  // Graph image based on p_vertices
181  template < typename F,
182  typename G, typename FP,
183  typename V >
184  struct ch_value_< pw::image< tag::function_<F>, tag::domain_<p_vertices<G, FP> > >, V >
185 
186  {
187  typedef pw::image< mln_ch_function_value(F, V), p_vertices<G, FP> > ret;
188  };
189 
190  // Vertex Image
191  template < typename P, typename V1, typename G, typename V2>
192  struct ch_value_< vertex_image< tag::psite_<P>,
193  tag::value_<V1>,
194  tag::graph_<G> >,
195  V2 >
196  {
197  typedef vertex_image< P, V2, G > ret;
198  };
199 
200  // Edge Image
201  template < typename P, typename V1, typename G, typename V2>
202  struct ch_value_< edge_image< tag::psite_<P>,
203  tag::value_<V1>,
204  tag::graph_<G> >,
205  V2 >
206  {
207  typedef edge_image< P, V2, G > ret;
208  };
209 
210  // Labeled image
211  template < typename I, typename V>
212  struct ch_value_< labeled_image< tag::image_<I> >,
213  V >
214  {
215  typedef mln_ch_value(I,V) ret;
216  };
217 
218 
219  template < template <class, class> class M, typename T, typename S,
220  typename V >
221  struct ch_value_< M< tag::value_<T>, tag::domain_<S> >, V >
222  {
223  // FIXME: what about S::site having no grid?
224  typedef mln_deduce(S, site, grid) grid;
225  typedef typename image_from_grid< grid, V >::ret ret;
226  };
227 
228 
229  template < template <class, class> class M, typename I, typename F,
230  typename V >
231  struct ch_value_< M< tag::image_<I>, tag::function_<F> >, V >
232  {
233  typedef M< mln_ch_value(I, V), F > ret;
234  };
235 
236  } // end of namespace mln::trait::impl
237 
238 
239  template <typename I, typename V>
240  struct ch_value
241  {
242  typedef typename I::skeleton skeleton;
243  typedef typename impl::ch_value_<skeleton, V>::ret ret;
244  };
245 
246  } // end of namespace mln::trait
247 
248 } // end of namespace mln
249 
250 
251 #endif // ! MLN_TRAIT_CH_VALUE_HH