Debian Codegraph @

sigc++/adaptors/macros/retype.h.m4

raw
1 dnl Copyright 2003, The libsigc++ Development Team
2 dnl
3 dnl This library is free software; you can redistribute it and/or
4 dnl modify it under the terms of the GNU Lesser General Public
5 dnl License as published by the Free Software Foundation; either
6 dnl version 2.1 of the License, or (at your option) any later version.
7 dnl
8 dnl This library is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 dnl Lesser General Public License for more details.
12 dnl
13 dnl You should have received a copy of the GNU Lesser General Public
14 dnl License along with this library; if not, write to the Free Software
15 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 dnl
17 divert(-1)
18
19 include(template.macros.m4)
20
21 define([RETYPE_OPERATOR],[dnl
22 ifelse($1,0,[dnl
23 result_type operator()();
24
25 ],[dnl
26 template <LOOP(class T_arg%1, $1)>
27 typename deduce_result_type<LOOP(T_arg%1,$1)>::type
28 operator()(LOOP(T_arg%1 _A_a%1, $1))
29 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(type_trait_take_t<T_type%1>, $1)>
30 (LOOP([[static_cast<T_type%1>(_A_a%1)]], $1));
31 }
32
33 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
34 template <LOOP(class T_arg%1, $1)>
35 typename deduce_result_type<LOOP(T_arg%1,$1)>::type
36 sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
37 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(type_trait_take_t<T_type%1>, $1)>
38 (LOOP([[static_cast<T_type%1>(_A_a%1)]], $1));
39 }
40 #endif
41
42 ])dnl
43 ])
44 define([RETYPE_POINTER_FUNCTOR],[dnl
45 /** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor.
46 * This function template specialization works on sigc::pointer_functor.
47 *
48 * @param _A_functor Functor that should be wrapped.
49 * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on.
50 *
51 * @ingroup retype
52 */
53 template <LIST(LOOP(class T_arg%1, $1), class T_return)>
54 inline retype_functor<LIST(pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>, LOOP(T_arg%1, $1)) >
55 retype(const pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>& _A_functor)
56 { return retype_functor<LIST(pointer_functor$1<LIST(LOOP(T_arg%1, $1), T_return)>, LOOP(T_arg%1, $1)) >
57 (_A_functor); }
58
59 ])
60 define([RETYPE_MEM_FUNCTOR],[dnl
61 /** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor.
62 * This function template specialization works on sigc::$2[]mem_functor.
63 *
64 * @param _A_functor Functor that should be wrapped.
65 * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on.
66 *
67 * @ingroup retype
68 */
69 template <LIST(class T_return, class T_obj, LOOP(class T_arg%1, $1))>
70 inline retype_functor<LIST($2[]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>, LOOP(T_arg%1, $1)) >
71 retype(const $2[]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>& _A_functor)
72 { return retype_functor<LIST($2[]mem_functor$1<LIST(T_return, T_obj, LOOP(T_arg%1, $1))>, LOOP(T_arg%1, $1)) >
73 (_A_functor); }
74
75 ])
76
77 divert(0)dnl
78 _FIREWALL([ADAPTORS_RETYPE])
79 #include <sigc++/adaptors/adaptor_trait.h>
80 #include <sigc++/functors/ptr_fun.h>
81 #include <sigc++/functors/mem_fun.h>
82 #include <sigc++/functors/slot.h>
83
84 //TODO: See comment in functor_trait.h.
85 #if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
86 #define SIGC_NIL_HAS_BEEN_PUSHED 1
87 #pragma push_macro("nil")
88 #undef nil
89 #endif
90
91 namespace sigc {
92
93 /** @defgroup retype retype(), retype_return()
94 * sigc::retype() alters a sigc::pointer_functor, a sigc::mem_functor or a sigc::slot
95 * in that it makes C-style casts to the functor's parameter types
96 * of all parameters passed through operator()().
97 *
98 * Use this adaptor for inline conversion between numeric or other simple types.
99 * @par Example:
100 * @code
101 * void foo(int);
102 * sigc::retype(sigc::ptr_fun(&foo))(5.7F); // calls foo(5)
103 * @endcode
104 *
105 * The functor that sigc::retype() returns can be passed directly into
106 * sigc::signal::connect().
107 *
108 * @par Example:
109 * @code
110 * sigc::signal<void,float> some_signal;
111 * void foo(int);
112 * some_signal.connect(sigc::retype(sigc::ptr_fun(&foo)));
113 * @endcode
114 *
115 * This adaptor builds an exception in that it only works on sig::pointer_functor,
116 * sigc::mem_functor and sigc::slot because it needs sophisticated information about
117 * the parameter types that cannot be deduced from arbitrary functor types.
118 *
119 * sigc::retype_return() alters the return type of an arbitrary functor.
120 * Like in sigc::retype() a C-style cast is performed. Usage sigc::retype_return() is
121 * not restricted to libsigc++ functor types but you need to
122 * specify the new return type as a template parameter.
123 *
124 * @par Example:
125 * @code
126 * float foo();
127 * std::cout << sigc::retype_return<int>(&foo)(); // converts foo's return value to an integer
128 * @endcode
129 *
130 * @ingroup adaptors
131 */
132
133 /** Adaptor that performs C-style casts on the parameters passed on to the functor.
134 * Use the convenience function sigc::retype() to create an instance of retype_functor.
135 *
136 * The following template arguments are used:
137 * - @e T_functor Type of the functor to wrap.dnl
138 FOR(1, CALL_SIZE,[
139 * - @e T_type%1 Type of @e T_functor's %1th argument.])
140 *
141 * @ingroup retype
142 */
143 template <LIST(class T_functor, LOOP(class T_type%1=nil, CALL_SIZE))>
144 struct retype_functor
145 : public adapts<T_functor>
146 {
147 typedef typename adapts<T_functor>::adaptor_type adaptor_type;
148
149 #ifndef DOXYGEN_SHOULD_SKIP_THIS
150 template <LOOP(class T_arg%1=void, CALL_SIZE)>
151 struct deduce_result_type
152 { typedef typename adaptor_type::template deduce_result_type<LOOP(_P_(T_arg%1),CALL_SIZE)>::type type; };
153 #endif
154 typedef typename adapts<T_functor>::result_type result_type;
155
156 FOR(0,CALL_SIZE,[[RETYPE_OPERATOR(%1)]])dnl
157
158 /** Constructs a retype_functor object that performs C-style casts on the parameters passed on to the functor.
159 * @param _A_functor Functor to invoke from operator()().
160 */
161 explicit retype_functor(type_trait_take_t<T_functor> _A_functor)
162 : adapts<T_functor>(_A_functor)
163 {}
164 };
165
166 template <LIST(class T_functor, LOOP(class T_type%1, CALL_SIZE))>
167 typename retype_functor<LIST(T_functor, LOOP(T_type%1, CALL_SIZE))>::result_type
168 retype_functor<LIST(T_functor, LOOP(T_type%1, CALL_SIZE))>::operator()()
169 { return this->functor_(); }
170
171 #ifndef DOXYGEN_SHOULD_SKIP_THIS
172 //template specialization of visitor<>::do_visit_each<>(action, functor):
173 /** Performs a functor on each of the targets of a functor.
174 * The function overload for sigc::retype_functor performs a functor on the
175 * functor stored in the sigc::retype_functor object.
176 *
177 * @ingroup retype
178 */
179 template <LIST(class T_functor, LOOP(class T_type%1, CALL_SIZE))>
180 struct visitor<retype_functor<LIST(T_functor, LOOP(T_type%1, CALL_SIZE))> >
181 {
182 template <typename T_action>
183 static void do_visit_each(const T_action& _A_action,
184 const retype_functor<LIST(T_functor, LOOP(T_type%1, CALL_SIZE))>& _A_target)
185 {
186 sigc::visit_each(_A_action, _A_target.functor_);
187 }
188 };
189 #endif // DOXYGEN_SHOULD_SKIP_THIS
190
191 /** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor.
192 * This function template specialization works on sigc::slot.
193 *
194 * @param _A_functor Functor that should be wrapped.
195 * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on.
196 *
197 * @ingroup retype
198 */
199 template <LIST(class T_return, LOOP(class T_arg%1, CALL_SIZE))>
200 inline retype_functor<LIST(slot<LIST(T_return, LOOP(T_arg%1, CALL_SIZE))>, LOOP(T_arg%1, CALL_SIZE)) >
201 retype(const slot<LIST(T_return, LOOP(T_arg%1, CALL_SIZE))>& _A_functor)
202 { return retype_functor<LIST(slot<LIST(T_return, LOOP(T_arg%1, CALL_SIZE))>, LOOP(T_arg%1, CALL_SIZE)) >
203 (_A_functor); }
204
205
206 FOR(0,CALL_SIZE,[[RETYPE_POINTER_FUNCTOR(%1)]])dnl
207
208 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[])]])dnl
209 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[const_])]])dnl
210 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[volatile_])]])dnl
211 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[const_volatile_])]])dnl
212 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_])]])dnl
213 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_const_])]])dnl
214 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_volatile_])]])dnl
215 FOR(0,CALL_SIZE,[[RETYPE_MEM_FUNCTOR(%1,[bound_const_volatile_])]])dnl
216
217 } /* namespace sigc */
218
219 #ifdef SIGC_NIL_HAS_BEEN_PUSHED
220 #undef SIGC_NIL_HAS_BEEN_PUSHED
221 #pragma pop_macro("nil")
222 #endif