1 dnl Copyright 2003, The libsigc++ Development Team
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.
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.
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
19 include(template.macros.m4)
21 define([RETYPE_OPERATOR],[dnl
23 result_type operator()();
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));
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));
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.
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.
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)) >
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.
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.
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)) >
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>
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")
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()().
98 * Use this adaptor for inline conversion between numeric or other simple types.
102 * sigc::retype(sigc::ptr_fun(&foo))(5.7F); // calls foo(5)
105 * The functor that sigc::retype() returns can be passed directly into
106 * sigc::signal::connect().
110 * sigc::signal<void,float> some_signal;
112 * some_signal.connect(sigc::retype(sigc::ptr_fun(&foo)));
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.
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.
127 * std::cout << sigc::retype_return<int>(&foo)(); // converts foo's return value to an integer
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.
136 * The following template arguments are used:
137 * - @e T_functor Type of the functor to wrap.dnl
139 * - @e T_type%1 Type of @e T_functor's %1th argument.])
143 template <LIST(class T_functor, LOOP(class T_type%1=nil, CALL_SIZE))>
144 struct retype_functor
145 : public adapts<T_functor>
147 typedef typename adapts<T_functor>::adaptor_type adaptor_type;
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; };
154 typedef typename adapts<T_functor>::result_type result_type;
156 FOR(0,CALL_SIZE,[[RETYPE_OPERATOR(%1)]])dnl
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()().
161 explicit retype_functor(type_trait_take_t<T_functor> _A_functor)
162 : adapts<T_functor>(_A_functor)
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_(); }
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.
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))> >
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)
186 sigc::visit_each(_A_action, _A_target.functor_);
189 #endif // DOXYGEN_SHOULD_SKIP_THIS
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.
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.
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)) >
206 FOR(0,CALL_SIZE,[[RETYPE_POINTER_FUNCTOR(%1)]])dnl
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
217 } /* namespace sigc */
219 #ifdef SIGC_NIL_HAS_BEEN_PUSHED
220 #undef SIGC_NIL_HAS_BEEN_PUSHED
221 #pragma pop_macro("nil")