1 dnl Copyright 2002, 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)
22 ifelse($1,0,,$1)ifelse($1,0,[last],$1,1,[st],$1,2,[nd],$1,3,[rd],[th])[]dnl
24 define([DEDUCE_RESULT_TYPE],[dnl
25 ifelse(eval($1 < 2),1,[#ifndef DOXYGEN_SHOULD_SKIP_THIS
26 ],)dnl Only for the first two template specializations. ($1 = 0..CALL_SIZE)
27 template <LOOP(class T_arg%1=void, CALL_SIZE)>
28 struct deduce_result_type
30 { typedef typename adaptor_type::template deduce_result_type<LOOP(_P_(T_arg%1),eval($2-1))>::type type; };
32 { typedef typename adaptor_type::template deduce_result_type<LIST(LOOP(_P_(T_arg%1),eval($1-1)), FOR(eval($1+1),$2,[_P_(T_arg%1),]))>::type type; };
34 ifelse(eval($1 < 2),1,[#endif // DOXYGEN_SHOULD_SKIP_THIS
37 define([HIDE_OPERATOR],[dnl
40 /** Invokes the wrapped functor ignoring the only argument.
41 * @param _A_a1 Argument to be ignored.
42 * @return The return value of the functor invocation.
44 template <class T_arg1>
45 typename deduce_result_type<T_arg1>::type
47 { return this->functor_(); }
49 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
50 template <class T_arg1>
51 typename deduce_result_type<T_arg1>::type
52 sun_forte_workaround(T_arg1 _A_a1)
53 { return this->functor_(); }
57 /** Invokes the wrapped functor, ignoring the last argument.dnl
59 * @param _A_a%1 Argument to be passed on to the functor.])
60 * @param _A_a$2 Argument to be ignored.
61 * @return The return value of the functor invocation.
63 template <LOOP([class T_arg%1], $2)>
64 typename deduce_result_type<LOOP(T_arg%1, $2)>::type
65 operator()(LOOP(T_arg%1 _A_a%1, eval($2-1)), T_arg$2)
66 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(FOR(1,eval($2-1),[_P_(T_arg%1),]))>
67 (LIST(FOR(1,eval($2-1),[_A_a%1,]))); }
69 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
70 template <LOOP([class T_arg%1], $2)>
71 typename deduce_result_type<LOOP(T_arg%1, $2)>::type
72 sun_forte_workaround(LOOP(T_arg%1 _A_a%1, eval($2-1)), T_arg$2)
73 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(FOR(1,eval($2-1),[_P_(T_arg%1),]))>
74 (LIST(FOR(1,eval($2-1),[_A_a%1,]))); }
78 /** Invokes the wrapped functor, ignoring the ORDINAL($1) argument.dnl
80 * @param _A_a%1 Argument to be passed on to the functor.])
81 * @param _A_a$1 Argument to be ignored.dnl
83 * @param _A_a%1 Argument to be passed on to the functor.])
84 * @return The return value of the functor invocation.
86 template <LOOP([class T_arg%1], $2)>
87 typename deduce_result_type<LOOP(T_arg%1, $2)>::type
88 operator()(LIST(FOR(1,eval($1-1),[T_arg%1 _A_a%1,]),T_arg$1,FOR(eval($1+1),$2,[T_arg%1 _A_a%1,])))
89 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(FOR(1,eval($1-1),[_P_(T_arg%1),]),FOR(eval($1+1), $2,[_P_(T_arg%1),]))>
90 (LIST(FOR(1,eval($1-1),[_A_a%1,]),FOR(eval($1+1),$2,[_A_a%1,]))); }
92 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
93 template <LOOP([class T_arg%1], $2)>
94 typename deduce_result_type<LOOP(T_arg%1, $2)>::type
95 sun_forte_workaround(LIST(FOR(1,eval($1-1),[T_arg%1 _A_a%1,]),T_arg$1,FOR(eval($1+1),$2,[T_arg%1 _A_a%1,])))
96 { return this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LIST(FOR(1,eval($1-1),[_P_(T_arg%1),]),FOR(eval($1+1), $2,[_P_(T_arg%1),]))>
97 (LIST(FOR(1,eval($1-1),[_A_a%1,]),FOR(eval($1+1),$2,[_A_a%1,]))); }
101 ])dnl end HIDE_OPERATOR
103 define([HIDE_FUNCTOR],[dnl
104 ifelse($1,1,[#ifndef DOXYGEN_SHOULD_SKIP_THIS
105 ],)dnl Include only the first two template specializations in the documentation. ($1 = -1..CALL_SIZE-1)
106 /** Adaptor that adds a dummy parameter to the wrapped functor.
107 * This template specialization ignores the value of the ORDINAL(eval($1+1)) parameter in operator()().
111 template <class T_functor>
112 struct hide_functor <$1, T_functor> : public adapts<T_functor>
114 typedef typename adapts<T_functor>::adaptor_type adaptor_type;
116 DEDUCE_RESULT_TYPE(eval($1+1),CALL_SIZE)dnl
117 typedef typename adaptor_type::result_type result_type;
119 FOR(eval($1+1),CALL_SIZE,[[HIDE_OPERATOR(eval($1+1),%1)]])dnl
121 /** Constructs a hide_functor object that adds a dummy parameter to the passed functor.
122 * @param _A_func Functor to invoke from operator()().
124 explicit hide_functor(const T_functor& _A_func)
125 : adapts<T_functor>(_A_func)
128 ifelse($1,eval(CALL_SIZE-1),[#endif // DOXYGEN_SHOULD_SKIP_THIS
129 ],)dnl Include only the first two template specializations in the documentation. ($1 = -1..CALL_SIZE-1)
131 ])dnl end HIDE_FUNCTOR
134 _FIREWALL([ADAPTORS_HIDE])
135 #include <sigc++/adaptors/adaptor_trait.h>
139 /** @defgroup hide hide(), hide_return()
140 * sigc::hide() alters an arbitrary functor in that it adds a parameter
141 * whose value is ignored on invocation of the returned functor.
142 * Thus you can discard one argument of a signal.
144 * You may optionally specify the zero-based position of the parameter
145 * to ignore as a template argument. The default is to ignore the last
147 * (A value of @p -1 adds a parameter at the end so sigc::hide<-1>() gives the same result as sigc::hide().)
149 * The type of the parameter can optionally be specified if not deduced.
153 * void foo(int, int);
154 * // single argument hiding ...
155 * sigc::hide(&foo)(1,2,3); // adds a dummy parameter at the back and calls foo(1,2)
156 * sigc::hide<-1>(&foo)(1,2,3); // same as sigc::hide(&foo)(1,2,3) (calls foo(1,2))
157 * sigc::hide<0>(&foo)(1,2,3); // adds a dummy parameter at the beginning and calls foo(2,3)
158 * sigc::hide<1>(&foo)(1,2,3); // adds a dummy parameter in the middle and calls foo(1,3)
159 * sigc::hide<2>(&foo)(1,2,3); // adds a dummy parameter at the back and calls foo(1,2)
162 * The functor sigc::hide() returns can be directly passed into
163 * sigc::signal::connect().
167 * sigc::signal<void,int> some_signal;
169 * some_signal.connect(sigc::hide(&foo));
172 * sigc::hide() can be nested in order to discard multiple arguments.
175 * // multiple argument hiding ...
176 * sigc::hide(sigc::hide(&foo))(1,2,3,4); // adds two dummy parameters at the back and calls foo(1,2)
179 * sigc::hide_return() alters an arbitrary functor by
180 * dropping its return value, thus converting it to a void functor.
185 /** Adaptor that adds a dummy parameter to the wrapped functor.
186 * Use the convenience function sigc::hide() to create an instance of sigc::hide_functor.
188 * The following template arguments are used:
189 * - @e I_location Zero-based position of the dummy parameter (@p -1 for the last parameter).
190 * - @e T_type Type of the dummy parameter.
191 * - @e T_functor Type of the functor to wrap.
195 template <int I_location, class T_functor>
196 #ifndef DOXYGEN_SHOULD_SKIP_THIS
199 struct hide_functor {};
202 FOR(-1,eval(CALL_SIZE-1),[[HIDE_FUNCTOR(%1)]])dnl
204 #ifndef DOXYGEN_SHOULD_SKIP_THIS
205 //template specialization of visitor<>::do_visit_each<>(action, functor):
206 /** Performs a functor on each of the targets of a functor.
207 * The function overload for sigc::hide_functor performs a functor on the
208 * functor stored in the sigc::hide_functor object.
212 template <int I_location, class T_functor>
213 struct visitor<hide_functor<I_location, T_functor> >
215 template <typename T_action>
216 static void do_visit_each(const T_action& _A_action,
217 const hide_functor<I_location, T_functor>& _A_target)
219 sigc::visit_each(_A_action, _A_target.functor_);
222 #endif // DOXYGEN_SHOULD_SKIP_THIS
224 /** Creates an adaptor of type sigc::hide_functor which adds a dummy parameter to the passed functor.
225 * The optional template argument @e I_location specifies the zero-based
226 * position of the dummy parameter in the returned functor (@p -1 stands for the last parameter).
228 * @param _A_func Functor that should be wrapped.
229 * @return Adaptor that executes @e _A_func, ignoring the value of the dummy parameter.
233 template <int I_location, class T_functor>
234 inline hide_functor<I_location, T_functor>
235 hide(const T_functor& _A_func)
236 { return hide_functor<I_location, T_functor>(_A_func); }
238 /** Creates an adaptor of type sigc::hide_functor which adds a dummy parameter to the passed functor.
239 * This overload adds a dummy parameter at the back of the functor's parameter list.
241 * @param _A_func Functor that should be wrapped.
242 * @return Adaptor that executes @e _A_func, ignoring the value of the last parameter.
246 template <class T_functor>
247 inline hide_functor<-1, T_functor>
248 hide(const T_functor& _A_func)
249 { return hide_functor<-1, T_functor> (_A_func); }
251 } /* namespace sigc */