Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
c.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_FUN_C_HH
27 # define MLN_FUN_C_HH
28 
36 
37 # include <mln/fun/internal/selector.hh>
38 # include <mln/metal/unqualif.hh>
39 
40 
41 namespace mln
42 {
43 
45  template <typename E>
46  struct C_Function;
47 
48 
50  template <typename R, typename A>
51  struct category< R (*)(A) >
52  {
53  typedef C_Function<void> ret;
54  };
55 
56 
57 
58  // Forward declaration.
59  namespace fun { template <typename F> struct C; }
60 
61 
62 
63  namespace trait
64  {
65 
66  template <template <class> class Op,
67  typename R, typename A>
68  struct set_unary_< Op, C_Function, R (*)(A) >
69  {
70  typedef Op< fun::C<R (*)(A)> > Op_;
71  typedef typename Op_::ret ret;
72  };
73 
74  template <template <class, class> class Op,
75  typename O,
76  typename R, typename A>
77  struct set_binary_< Op,
78  Object, O,
79  C_Function, R (*)(A) >
80  {
81  typedef Op< O, fun::C<R (*)(A)> > Op_;
82  typedef typename Op_::ret ret;
83  };
84 
85  } // end of namespace trait
86 
87 
88 
89  namespace fun
90  {
91 
92  template <typename F> struct C;
93 
94 
95  // FIXME: Doc!
96  template <typename R, typename A>
97  struct C< R (*)(A) >
98  :
99  fun::internal::selector_< R, A, C<R(*)(A)> >::ret
100  {
101  C();
102  C(R (*f)(A));
103  typedef R result;
104  R operator()(const mlc_unqualif(A)& a) const;
105  protected:
106  R (*f_)(A);
107  };
108 
109 
110 # ifndef MLN_INCLUDE_ONLY
111 
112  template <typename R, typename A>
113  inline
114  C<R(*)(A)>::C()
115  {
116  }
117 
118  template <typename R, typename A>
119  inline
120  C<R(*)(A)>::C(R (*f)(A))
121  : f_(f)
122  {
123  }
124 
125  template <typename R, typename A>
126  inline
127  R
128  C<R(*)(A)>::operator()(const mlc_unqualif(A)& a) const
129  {
130  return f_(a);
131  }
132 
133 # endif // ! MLN_INCLUDE_ONLY
134 
135  } // end of namespace mln::fun
136 
137 } // end of namespace mln
138 
139 
140 #endif // ! MLN_FUN_C_HH