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