| 1 |
dnl Copyright 2002, 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([ORDINAL],[dnl |
| 22 |
ifelse($1,0,,$1)ifelse($1,0,[last],$1,1,[st],$1,2,[nd],$1,3,[rd],[th])[]dnl |
| 23 |
]) |
| 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 |
| 29 |
ifelse($1,0,[dnl |
| 30 |
{ typedef typename adaptor_type::template deduce_result_type<LOOP(_P_(T_arg%1),eval($2-1))>::type type; }; |
| 31 |
],[dnl |
| 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; }; |
| 33 |
])dnl |
| 34 |
ifelse(eval($1 < 2),1,[#endif // DOXYGEN_SHOULD_SKIP_THIS |
| 35 |
],)dnl |
| 36 |
]) |
| 37 |
define([HIDE_OPERATOR],[dnl |
| 38 |
ifelse($2,0,,[dnl |
| 39 |
ifelse($2,1,[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. |
| 43 |
*/ |
| 44 |
template <class T_arg1> |
| 45 |
typename deduce_result_type<T_arg1>::type |
| 46 |
operator()(T_arg1) |
| 47 |
{ return this->functor_(); } |
| 48 |
|
| 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_(); } |
| 54 |
#endif |
| 55 |
|
| 56 |
],$1,0,[dnl |
| 57 |
/** Invokes the wrapped functor, ignoring the last argument.dnl |
| 58 |
FOR(1, eval($2-1),[ |
| 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. |
| 62 |
*/ |
| 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,]))); } |
| 68 |
|
| 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,]))); } |
| 75 |
#endif |
| 76 |
|
| 77 |
],[dnl |
| 78 |
/** Invokes the wrapped functor, ignoring the ORDINAL($1) argument.dnl |
| 79 |
FOR(1, eval($1-1),[ |
| 80 |
* @param _A_a%1 Argument to be passed on to the functor.]) |
| 81 |
* @param _A_a$1 Argument to be ignored.dnl |
| 82 |
FOR(eval($1+1), $2,[ |
| 83 |
* @param _A_a%1 Argument to be passed on to the functor.]) |
| 84 |
* @return The return value of the functor invocation. |
| 85 |
*/ |
| 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,]))); } |
| 91 |
|
| 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,]))); } |
| 98 |
#endif |
| 99 |
|
| 100 |
])])dnl |
| 101 |
])dnl end HIDE_OPERATOR |
| 102 |
|
| 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()(). |
| 108 |
* |
| 109 |
* @ingroup hide |
| 110 |
*/ |
| 111 |
template <class T_functor> |
| 112 |
struct hide_functor <$1, T_functor> : public adapts<T_functor> |
| 113 |
{ |
| 114 |
typedef typename adapts<T_functor>::adaptor_type adaptor_type; |
| 115 |
|
| 116 |
DEDUCE_RESULT_TYPE(eval($1+1),CALL_SIZE)dnl |
| 117 |
typedef typename adaptor_type::result_type result_type; |
| 118 |
|
| 119 |
FOR(eval($1+1),CALL_SIZE,[[HIDE_OPERATOR(eval($1+1),%1)]])dnl |
| 120 |
|
| 121 |
/** Constructs a hide_functor object that adds a dummy parameter to the passed functor. |
| 122 |
* @param _A_func Functor to invoke from operator()(). |
| 123 |
*/ |
| 124 |
explicit hide_functor(const T_functor& _A_func) |
| 125 |
: adapts<T_functor>(_A_func) |
| 126 |
{} |
| 127 |
}; |
| 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) |
| 130 |
|
| 131 |
])dnl end HIDE_FUNCTOR |
| 132 |
|
| 133 |
divert(0)dnl |
| 134 |
_FIREWALL([ADAPTORS_HIDE]) |
| 135 |
#include <sigc++/adaptors/adaptor_trait.h> |
| 136 |
|
| 137 |
namespace sigc { |
| 138 |
|
| 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. |
| 143 |
* |
| 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 |
| 146 |
* parameter. |
| 147 |
* (A value of @p -1 adds a parameter at the end so sigc::hide<-1>() gives the same result as sigc::hide().) |
| 148 |
* |
| 149 |
* The type of the parameter can optionally be specified if not deduced. |
| 150 |
* |
| 151 |
* @par Examples: |
| 152 |
* @code |
| 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) |
| 160 |
* @endcode |
| 161 |
* |
| 162 |
* The functor sigc::hide() returns can be directly passed into |
| 163 |
* sigc::signal::connect(). |
| 164 |
* |
| 165 |
* @par Example: |
| 166 |
* @code |
| 167 |
* sigc::signal<void,int> some_signal; |
| 168 |
* void foo(); |
| 169 |
* some_signal.connect(sigc::hide(&foo)); |
| 170 |
* @endcode |
| 171 |
* |
| 172 |
* sigc::hide() can be nested in order to discard multiple arguments. |
| 173 |
* @par Example: |
| 174 |
* @code |
| 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) |
| 177 |
* @endcode |
| 178 |
|
| 179 |
* sigc::hide_return() alters an arbitrary functor by |
| 180 |
* dropping its return value, thus converting it to a void functor. |
| 181 |
* |
| 182 |
* @ingroup adaptors |
| 183 |
*/ |
| 184 |
|
| 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. |
| 187 |
* |
| 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. |
| 192 |
* |
| 193 |
* @ingroup hide |
| 194 |
*/ |
| 195 |
template <int I_location, class T_functor> |
| 196 |
#ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 197 |
struct hide_functor; |
| 198 |
#else |
| 199 |
struct hide_functor {}; |
| 200 |
#endif |
| 201 |
|
| 202 |
FOR(-1,eval(CALL_SIZE-1),[[HIDE_FUNCTOR(%1)]])dnl |
| 203 |
|
| 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. |
| 209 |
* |
| 210 |
* @ingroup hide |
| 211 |
*/ |
| 212 |
template <int I_location, class T_functor> |
| 213 |
struct visitor<hide_functor<I_location, T_functor> > |
| 214 |
{ |
| 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) |
| 218 |
{ |
| 219 |
sigc::visit_each(_A_action, _A_target.functor_); |
| 220 |
} |
| 221 |
}; |
| 222 |
#endif // DOXYGEN_SHOULD_SKIP_THIS |
| 223 |
|
| 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). |
| 227 |
* |
| 228 |
* @param _A_func Functor that should be wrapped. |
| 229 |
* @return Adaptor that executes @e _A_func, ignoring the value of the dummy parameter. |
| 230 |
* |
| 231 |
* @ingroup hide |
| 232 |
*/ |
| 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); } |
| 237 |
|
| 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. |
| 240 |
* |
| 241 |
* @param _A_func Functor that should be wrapped. |
| 242 |
* @return Adaptor that executes @e _A_func, ignoring the value of the last parameter. |
| 243 |
* |
| 244 |
* @ingroup hide |
| 245 |
*/ |
| 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); } |
| 250 |
|
| 251 |
} /* namespace sigc */ |