$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
meta_function.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 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_CONCEPT_META_FUNCTION_HH
28 # define MLN_CORE_CONCEPT_META_FUNCTION_HH
29 
33 
34 # include <mln/core/concept/object.hh>
35 # include <mln/core/concept/function.hh>
36 
37 # define mln_fun_with(F, T) \
38 typename F::template with< T >::ret
39 
40 # define mln_fun_with_(F, T) \
41 F::with< T >::ret
42 
43 # define mln_fun_withbin(F, T1, T2) \
44 typename F::template with< T1, T2 >::ret
45 
46 # define mln_fun_withbin_(F, T1, T2) \
47 F::with< T1, T2 >::ret
48 
49 # define mln_fun_result(F, T) \
50 typename F::template with< T >::ret::result
51 
52 # define mln_fun_result_(F, T) \
53 F::with< T >::ret::result
54 
55 namespace mln
56 {
57 
58  // Fwd decl.
59  template <typename E> struct Meta_Function;
60  template <typename E> struct Meta_Function_v2v;
61  template <typename E> struct Meta_Function_vv2v;
62 
65  template <>
66  struct Meta_Function<void>
67  {
69  };
71 
72 
79  template <typename E>
80  struct Meta_Function : public Object<E>
81  {
83  protected:
84  Meta_Function();
85  };
86 
87  /*----------------------.
88  | Unary meta function. |
89  `----------------------*/
90 
92  template <>
93  struct Meta_Function_v2v<void> { typedef Meta_Function<void> super; };
95 
101  template <typename E>
102  struct Meta_Function_v2v : public Meta_Function<E>
103  {
105 
106  protected:
109  };
110 
111  /*-----------------------.
112  | Binary meta function. |
113  `-----------------------*/
114 
116  template <>
117  struct Meta_Function_vv2v<void> { typedef Meta_Function<void> super; };
119 
125  template <typename E>
127  {
129 
130  protected:
133  };
134 
135  namespace fun
136  {
137 
138  // To be specialized when some state (attributes) have to be transfered
139  // from the meta-function to the function.
140  // Warning: the first argument has to be an object with the exact type.
141  template <typename M, typename T>
142  mln_fun_with(M, T)
143  unmeta(const M&, T);
144 
145  template <typename M, typename T>
146  void
147  unmeta(const Meta_Function<M>&, T); // Safety.
148 
149  } // end of namespace mln::fun
150 
151 
152 
153 # ifndef MLN_INCLUDE_ONLY
154 
155  template <typename E>
156  inline
158  {
159  // FIXME: Check "with" on E.
160  }
161 
162  template <typename E>
163  inline
165  {
166  }
167 
168  template <typename E>
169  inline
170  Meta_Function_v2v<E>::Meta_Function_v2v(const Meta_Function_v2v<E>& rhs)
171  : Meta_Function<E>(rhs)
172  {
173  }
174 
175  template <typename E>
176  inline
178  {
179  }
180 
181  template <typename E>
182  inline
183  Meta_Function_vv2v<E>::Meta_Function_vv2v(const Meta_Function_vv2v<E>& rhs)
184  : Meta_Function<E>(rhs)
185  {
186  }
187 
188  namespace fun
189  {
190 
191  template <typename M, typename T>
192  inline
193  mln_fun_with(M, T)
194  unmeta(const M&, T)
195  {
196  mlc_is_a(M, Meta_Function)::check();
197  mln_fun_with(M, T) a;
198  return a;
199  }
200 
201  } // end of namespace mln::fun
202 
203 # endif // ! MLN_INCLUDE_ONLY
204 
205 } // end of namespace mln
206 
207 
208 #endif // ! MLN_CORE_CONCEPT_META_FUNCTION_HH