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)
21 define([RETYPE_RETURN_OPERATOR],[dnl
22 template <LOOP(class T_arg%1, $1)>
23 inline T_return operator()(LOOP(T_arg%1 _A_a%1, $1))
24 { return T_return(this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
28 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
29 template <LOOP(class T_arg%1, $1)>
30 inline T_return sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
31 { return T_return(this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
37 define([RETYPE_RETURN_VOID_OPERATOR],[dnl
38 template <LOOP(class T_arg%1, $1)>
39 inline void operator()(LOOP(T_arg%1 _A_a%1, $1))
40 { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
44 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
45 template <LOOP(class T_arg%1, $1)>
46 inline void sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
47 { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
55 _FIREWALL([ADAPTORS_RETYPE_RETURN])
56 #include <sigc++/adaptors/adaptor_trait.h>
60 /** Adaptor that performs a C-style cast on the return value of a functor.
61 * Use the convenience function sigc::retype_return() to create an instance of retype_return_functor.
63 * The following template arguments are used:
64 * - @e T_return Target type of the C-style cast.
65 * - @e T_functor Type of the functor to wrap.
69 template <class T_return, class T_functor>
70 struct retype_return_functor : public adapts<T_functor>
72 #ifndef DOXYGEN_SHOULD_SKIP_THIS
73 template <LOOP(class T_arg%1=void, CALL_SIZE)>
74 struct deduce_result_type
75 { typedef T_return type; };
77 typedef T_return result_type;
79 T_return operator()();
81 FOR(1,CALL_SIZE,[[RETYPE_RETURN_OPERATOR(%1)]])dnl
82 retype_return_functor() {}
84 /** Constructs a retype_return_functor object that perform a C-style cast on the return value of the passed functor.
85 * @param _A_functor Functor to invoke from operator()().
87 explicit retype_return_functor(_R_(T_functor) _A_functor)
88 : adapts<T_functor>(_A_functor)
92 template <class T_return, class T_functor>
93 T_return retype_return_functor<T_return, T_functor>::operator()()
94 { return T_return(this->functor_()); }
97 /** Adaptor that performs a C-style cast on the return value of a functor.
98 * This template specialization is for a void return. It drops the return value of the functor it invokes.
99 * Use the convenience function sigc::hide_return() to create an instance of sigc::retype_return_functor<void>.
103 /* The void specialization is needed because of explicit cast to T_return.
105 template <class T_functor>
106 struct retype_return_functor<void, T_functor> : public adapts<T_functor>
108 #ifndef DOXYGEN_SHOULD_SKIP_THIS
109 template <LOOP(class T_arg%1=void, CALL_SIZE)>
110 struct deduce_result_type
111 { typedef void type; };
113 typedef void result_type;
117 FOR(1,CALL_SIZE,[[RETYPE_RETURN_VOID_OPERATOR(%1)]])dnl
118 retype_return_functor() {}
119 retype_return_functor(_R_(T_functor) _A_functor)
120 : adapts<T_functor>(_A_functor)
124 template <class T_functor>
125 void retype_return_functor<void, T_functor>::operator()()
126 { this->functor_(); }
128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
129 //template specialization of visitor<>::do_visit_each<>(action, functor):
130 /** Performs a functor on each of the targets of a functor.
131 * The function overload for sigc::retype_return_functor performs a functor on the
132 * functor stored in the sigc::retype_return_functor object.
136 template <class T_return, class T_functor>
137 struct visitor<retype_return_functor<T_return, T_functor> >
139 template <typename T_action>
140 static void do_visit_each(const T_action& _A_action,
141 const retype_return_functor<T_return, T_functor>& _A_target)
143 sigc::visit_each(_A_action, _A_target.functor_);
146 #endif // DOXYGEN_SHOULD_SKIP_THIS
148 /** Creates an adaptor of type sigc::retype_return_functor which performs a C-style cast on the return value of the passed functor.
149 * The template argument @e T_return specifies the target type of the cast.
151 * @param _A_functor Functor that should be wrapped.
152 * @return Adaptor that executes @e _A_functor performing a C-style cast on the return value.
156 template <class T_return, class T_functor>
157 inline retype_return_functor<T_return, T_functor>
158 retype_return(const T_functor& _A_functor)
159 { return retype_return_functor<T_return, T_functor>(_A_functor); }
161 /** Creates an adaptor of type sigc::retype_return_functor which drops the return value of the passed functor.
163 * @param _A_functor Functor that should be wrapped.
164 * @return Adaptor that executes @e _A_functor dropping its return value.
168 template <class T_functor>
169 inline retype_return_functor<void, T_functor>
170 hide_return(const T_functor& _A_functor)
171 { return retype_return_functor<void, T_functor>(_A_functor); }
173 } /* namespace sigc */