]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - sigc++/adaptors/macros/retype_return.h.m4
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / sigc++ / adaptors / macros / retype_return.h.m4
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([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)>
25         (LOOP(_A_a%1, $1)));
26     }
27
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)>
32         (LOOP(_A_a%1, $1)));
33     }
34   #endif
35
36 ])
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)>
41         (LOOP(_A_a%1, $1));
42     }
43
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)>
48         (LOOP(_A_a%1, $1));
49     }
50   #endif
51
52 ])
53
54 divert(0)dnl
55 _FIREWALL([ADAPTORS_RETYPE_RETURN])
56 #include <sigc++/adaptors/adaptor_trait.h>
57
58 namespace sigc {
59
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.
62  *
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.
66  *
67  * @ingroup retype
68  */
69 template <class T_return, class T_functor>
70 struct retype_return_functor : public adapts<T_functor>
71 {
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; };
76 #endif
77   typedef T_return result_type;
78
79   T_return operator()();
80
81 FOR(1,CALL_SIZE,[[RETYPE_RETURN_OPERATOR(%1)]])dnl
82   retype_return_functor() {}
83
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()().
86    */
87   explicit retype_return_functor(_R_(T_functor) _A_functor)
88     : adapts<T_functor>(_A_functor)
89     {}
90 };
91
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_()); }
95
96
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>.
100  *
101  * @ingroup retype
102  */
103 /* The void specialization is needed because of explicit cast to T_return.
104  */
105 template <class T_functor>
106 struct retype_return_functor<void, T_functor> : public adapts<T_functor>
107 {
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; };
112 #endif
113   typedef void result_type;
114
115   void operator()();
116
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)
121     {}
122 };
123
124 template <class T_functor>
125 void retype_return_functor<void, T_functor>::operator()()
126   { this->functor_(); }
127
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.
133  *
134  * @ingroup retype
135  */
136 template <class T_return, class T_functor>
137 struct visitor<retype_return_functor<T_return, T_functor> >
138 {
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)
142   {
143     sigc::visit_each(_A_action, _A_target.functor_);
144   }
145 };
146 #endif // DOXYGEN_SHOULD_SKIP_THIS
147
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.
150  *
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.
153  *
154  * @ingroup retype
155  */
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); }
160
161 /** Creates an adaptor of type sigc::retype_return_functor which drops the return value of the passed functor.
162  *
163  * @param _A_functor Functor that should be wrapped.
164  * @return Adaptor that executes @e _A_functor dropping its return value.
165  *
166  * @ingroup hide
167  */
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); }
172
173 } /* namespace sigc */