Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
function.hh
1 // Copyright (C) 2007, 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_CONCEPT_FUNCTION_HH
28 # define MLN_CORE_CONCEPT_FUNCTION_HH
29 
33 
34 # include <mln/core/concept/object.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declarations.
41  template <typename E> struct Function;
42  template <typename E> struct Function_n2v;
43  template <typename E> struct Function_v2v;
44  template <typename E> struct Function_v2b;
45  template <typename E> struct Function_vv2v;
46  template <typename E> struct Function_vv2b;
47 
48 
50  template <>
51  struct Function<void>
52  {
53  typedef Object<void> super;
54  };
55 
56 
62  //
63  template <typename E>
64  struct Function : public Object<E>
65  {
66  typedef Function<void> category;
67 
70 
71  protected:
72  Function();
73  Function(const Function&);
74 
75  /* Workaround for Apple's llvm-gcc 4.2.1 (Mac OS X Lion 10.7.1)
76 
77  Apple's llvm-gcc has a bug causing memmove() errors if the copy
78  constructor is not declared along with operator=(). */
79  Function<E>& operator=(const Function<E>&);
80  };
81 
82 
83  /*---------------.
84  | Nil -> Value. |
85  `---------------*/
86 
87  template <>
88  struct Function_n2v<void> { typedef Function<void> super; };
89 
90 
97  //
98  template <typename E>
99  struct Function_n2v : public Function<E>
100  {
102  protected:
103  Function_n2v();
104  Function_n2v(const Function_n2v&);
105  };
106 
107 
108  /*-----------------.
109  | Value -> Value. |
110  `-----------------*/
111 
112  template <>
113  struct Function_v2v<void> { typedef Function<void> super; };
114 
115 
122  //
123  template <typename E>
124  struct Function_v2v : public Function<E>
125  {
127  typedef void mutable_result; // Meaning: no mutable result by default.
128  protected:
129  Function_v2v();
130  Function_v2v(const Function_v2v&);
131  };
132 
133 
134  /*----------------.
135  | Value -> bool. |
136  `----------------*/
137 
138  template <>
139  struct Function_v2b<void> { typedef Function_v2v<void> super; };
140 
141 
148  //
149  template <typename E>
150  struct Function_v2b : public virtual Function_v2v<E>
151  {
153  typedef bool result;
154  protected:
155  Function_v2b();
156  Function_v2b(const Function_v2b&);
157  };
158 
159 
160 
161  /*--------------------------.
162  | (Value, Value) -> Value. |
163  `--------------------------*/
164 
165  template <>
166  struct Function_vv2v<void> { typedef Function<void> super; };
167 
168 
175  //
176  template <typename E>
177  struct Function_vv2v : public Function<E>
178  {
180  protected:
181  Function_vv2v();
183  };
184 
185 
186  /*--------------------------.
187  | (Value, Value) -> Boolean.|
188  `--------------------------*/
189 
190  template <>
191  struct Function_vv2b<void> { typedef Function<void> super; };
192 
193 
200  //
201  template <typename E>
202  struct Function_vv2b : public Function<E>
203  {
204  typedef bool result;
206  protected:
207  Function_vv2b();
209  };
210 
211 
212 
213 # ifndef MLN_INCLUDE_ONLY
214 
215  // Function.
216 
217  template <typename E>
218  inline
220  {
221  typedef mln_result(E) result;
222  }
223 
224  template <typename E>
225  inline
227  : Object<E>(rhs)
228  {
229  }
230 
231  template <typename E>
232  inline
233  Function<E>&
234  Function<E>::operator=(const Function<E>&)
235  {
236  return *this;
237  }
238 
239  // Function_n2v.
240 
241  template <typename E>
242  inline
243  Function_n2v<E>::Function_n2v()
244  {
245  }
246 
247  template <typename E>
248  inline
249  Function_n2v<E>::Function_n2v(const Function_n2v<E>& rhs)
250  : Function<E>(rhs)
251  {
252  }
253 
254 
255  // Function_v2v.
256 
257  template <typename E>
258  inline
259  Function_v2v<E>::Function_v2v()
260  {
261  }
262 
263  template <typename E>
264  inline
265  Function_v2v<E>::Function_v2v(const Function_v2v<E>& rhs)
266  : Function<E>(rhs)
267  {
268  }
269 
270  // Function_v2b.
271 
272  template <typename E>
273  inline
274  Function_v2b<E>::Function_v2b()
275  {
276  }
277 
278  template <typename E>
279  inline
280  Function_v2b<E>::Function_v2b(const Function_v2b<E>& rhs)
281  : Function_v2v<E>(rhs)
282  {
283  }
284 
285  // Function_vv2v.
286 
287  template <typename E>
288  inline
289  Function_vv2v<E>::Function_vv2v()
290  {
291  }
292 
293  template <typename E>
294  inline
295  Function_vv2v<E>::Function_vv2v(const Function_vv2v<E>& rhs)
296  : Function<E>(rhs)
297  {
298  }
299 
300  // Function_vv2b.
301 
302  template <typename E>
303  inline
304  Function_vv2b<E>::Function_vv2b()
305  {
306  }
307 
308  template <typename E>
309  inline
310  Function_vv2b<E>::Function_vv2b(const Function_vv2b<E>& rhs)
311  : Function<E>(rhs)
312  {
313  }
314 
315 # endif // ! MLN_INCLUDE_ONLY
316 
317 } // end of namespace mln
318 
319 
320 #endif // ! MLN_CORE_CONCEPT_FUNCTION_HH