]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - untracked/sigc++/adaptors/adaptor_trait.h
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / untracked / sigc++ / adaptors / adaptor_trait.h
1 // -*- c++ -*-
2 /* Do not edit! -- generated file */
3 #ifndef _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_
4 #define _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_
5 #include <sigc++config.h> //To get SIGC_TEMPLATE_KEYWORD_OPERATOR_OVERLOAD
6 #include <sigc++/visit_each.h>
7 #include <sigc++/functors/functor_trait.h>
8 #include <sigc++/functors/ptr_fun.h>
9 #include <sigc++/functors/mem_fun.h>
10 #include <sigc++/adaptors/deduce_result_type.h>
11
12 namespace sigc {
13
14 // Call either operator()<>() or sun_forte_workaround<>(),
15 // depending on the compiler:
16 #ifdef SIGC_GCC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
17   #define SIGC_WORKAROUND_OPERATOR_PARENTHESES template operator()
18   #define SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
19 #else
20   #ifdef SIGC_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
21     #define SIGC_WORKAROUND_OPERATOR_PARENTHESES operator()
22     #define SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
23   #else
24     #define SIGC_WORKAROUND_OPERATOR_PARENTHESES sun_forte_workaround
25   #endif
26 #endif
27
28
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 template <class T_functor> struct adapts;
31 #endif
32
33 /** @defgroup adaptors Adaptors
34  * Adaptors are functors that alter the signature of a functor's
35  * operator()().
36  *
37  * The adaptor types libsigc++ provides
38  * are created with bind(), bind_return(), hide(), hide_return(),
39  * retype_return(), retype(), compose(), exception_catch(), track_obj()
40  * and group().
41  *
42  * You can easily derive your own adaptor type from sigc::adapts.
43  */
44
45 /** Converts an arbitrary functor into an adaptor type.
46  * All adaptor types in libsigc++ have
47  * a <tt>template operator()</tt> member of every argument count
48  * they support. These functions in turn invoke a stored adaptor's
49  * <tt>template operator()</tt>, processing the arguments and return
50  * value in a characteristic manner. Explicit function template
51  * instantiation is used to pass type hints thus saving copy costs.
52  *
53  * adaptor_functor is a glue between adaptors and arbitrary functors
54  * that just passes on the arguments. You won't use this type directly.
55  *
56  * The template argument @e T_functor determines the type of stored
57  * functor.
58  *
59  * @ingroup adaptors
60  */
61 template <class T_functor>
62 struct adaptor_functor : public adaptor_base
63 {
64 #ifndef DOXYGEN_SHOULD_SKIP_THIS
65   template <class T_arg1=void, class T_arg2=void, class T_arg3=void, class T_arg4=void, class T_arg5=void, class T_arg6=void, class T_arg7=void>
66   struct deduce_result_type
67     { typedef sigc::deduce_result_t<T_functor, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7> type; };
68 #endif
69   typedef typename functor_trait<T_functor>::result_type result_type;
70
71   /** Invokes the wrapped functor passing on the arguments.
72    * @return The return value of the functor invocation.
73    */
74   result_type
75   operator()() const;
76
77   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
78   result_type sun_forte_workaround() const
79     { return operator(); }
80   #endif
81
82   /** Invokes the wrapped functor passing on the arguments.
83    * @param _A_arg1 Argument to be passed on to the functor.
84    * @return The return value of the functor invocation.
85    */
86   template <class T_arg1>
87   typename deduce_result_type<T_arg1>::type
88   operator()(T_arg1 _A_arg1) const
89     { return functor_(_A_arg1); }
90
91   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
92   template <class T_arg1>
93   typename deduce_result_type<T_arg1>::type
94   sun_forte_workaround(T_arg1 _A_arg1) const
95     { //Just calling operator() tries to copy the argument:
96       return functor_(_A_arg1);
97     }
98   #endif
99
100   /** Invokes the wrapped functor passing on the arguments.
101    * @param _A_arg1 Argument to be passed on to the functor.
102    * @param _A_arg2 Argument to be passed on to the functor.
103    * @return The return value of the functor invocation.
104    */
105   template <class T_arg1, class T_arg2>
106   typename deduce_result_type<T_arg1, T_arg2>::type
107   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2) const
108     { return functor_(_A_arg1, _A_arg2); }
109
110   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
111   template <class T_arg1, class T_arg2>
112   typename deduce_result_type<T_arg1, T_arg2>::type
113   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2) const
114     { //Just calling operator() tries to copy the argument:
115       return functor_(_A_arg1, _A_arg2);
116     }
117   #endif
118
119   /** Invokes the wrapped functor passing on the arguments.
120    * @param _A_arg1 Argument to be passed on to the functor.
121    * @param _A_arg2 Argument to be passed on to the functor.
122    * @param _A_arg3 Argument to be passed on to the functor.
123    * @return The return value of the functor invocation.
124    */
125   template <class T_arg1, class T_arg2, class T_arg3>
126   typename deduce_result_type<T_arg1, T_arg2, T_arg3>::type
127   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3) const
128     { return functor_(_A_arg1, _A_arg2, _A_arg3); }
129
130   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
131   template <class T_arg1, class T_arg2, class T_arg3>
132   typename deduce_result_type<T_arg1, T_arg2, T_arg3>::type
133   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3) const
134     { //Just calling operator() tries to copy the argument:
135       return functor_(_A_arg1, _A_arg2, _A_arg3);
136     }
137   #endif
138
139   /** Invokes the wrapped functor passing on the arguments.
140    * @param _A_arg1 Argument to be passed on to the functor.
141    * @param _A_arg2 Argument to be passed on to the functor.
142    * @param _A_arg3 Argument to be passed on to the functor.
143    * @param _A_arg4 Argument to be passed on to the functor.
144    * @return The return value of the functor invocation.
145    */
146   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4>
147   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4>::type
148   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4) const
149     { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4); }
150
151   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
152   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4>
153   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4>::type
154   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4) const
155     { //Just calling operator() tries to copy the argument:
156       return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4);
157     }
158   #endif
159
160   /** Invokes the wrapped functor passing on the arguments.
161    * @param _A_arg1 Argument to be passed on to the functor.
162    * @param _A_arg2 Argument to be passed on to the functor.
163    * @param _A_arg3 Argument to be passed on to the functor.
164    * @param _A_arg4 Argument to be passed on to the functor.
165    * @param _A_arg5 Argument to be passed on to the functor.
166    * @return The return value of the functor invocation.
167    */
168   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5>
169   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5>::type
170   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5) const
171     { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5); }
172
173   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
174   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5>
175   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5>::type
176   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5) const
177     { //Just calling operator() tries to copy the argument:
178       return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5);
179     }
180   #endif
181
182   /** Invokes the wrapped functor passing on the arguments.
183    * @param _A_arg1 Argument to be passed on to the functor.
184    * @param _A_arg2 Argument to be passed on to the functor.
185    * @param _A_arg3 Argument to be passed on to the functor.
186    * @param _A_arg4 Argument to be passed on to the functor.
187    * @param _A_arg5 Argument to be passed on to the functor.
188    * @param _A_arg6 Argument to be passed on to the functor.
189    * @return The return value of the functor invocation.
190    */
191   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6>
192   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6>::type
193   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6) const
194     { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6); }
195
196   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
197   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6>
198   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6>::type
199   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6) const
200     { //Just calling operator() tries to copy the argument:
201       return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6);
202     }
203   #endif
204
205   /** Invokes the wrapped functor passing on the arguments.
206    * @param _A_arg1 Argument to be passed on to the functor.
207    * @param _A_arg2 Argument to be passed on to the functor.
208    * @param _A_arg3 Argument to be passed on to the functor.
209    * @param _A_arg4 Argument to be passed on to the functor.
210    * @param _A_arg5 Argument to be passed on to the functor.
211    * @param _A_arg6 Argument to be passed on to the functor.
212    * @param _A_arg7 Argument to be passed on to the functor.
213    * @return The return value of the functor invocation.
214    */
215   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7>
216   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7>::type
217   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6, T_arg7 _A_arg7) const
218     { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6, _A_arg7); }
219
220   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
221   template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7>
222   typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7>::type
223   sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6, T_arg7 _A_arg7) const
224     { //Just calling operator() tries to copy the argument:
225       return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6, _A_arg7);
226     }
227   #endif
228
229   /// Constructs an invalid functor.
230   adaptor_functor()
231     {}
232
233   /** Constructs an adaptor_functor object that wraps the passed functor.
234    * @param _A_functor Functor to invoke from operator()().
235    */
236   explicit adaptor_functor(const T_functor& _A_functor)
237     : functor_(_A_functor)
238     {}
239
240   /** Constructs an adaptor_functor object that wraps the passed (member)
241    * function pointer.
242    * @param _A_type Pointer to function or class method to invoke from operator()().
243    */
244   template <class T_type>
245   explicit adaptor_functor(const T_type& _A_type)
246     : functor_(_A_type)
247     {}
248
249   /// Functor that is invoked from operator()().
250   mutable T_functor functor_;
251 };
252
253 template <class T_functor>
254 typename adaptor_functor<T_functor>::result_type
255 adaptor_functor<T_functor>::operator()() const
256   { return functor_(); }
257
258 #ifndef DOXYGEN_SHOULD_SKIP_THIS
259 //template specialization of visitor<>::do_visit_each<>(action, functor):
260 /** Performs a functor on each of the targets of a functor.
261  * The function overload for sigc::adaptor_functor performs a functor
262  * on the functor stored in the sigc::adaptor_functor object.
263  *
264  * @ingroup adaptors
265  */
266 template <class T_functor>
267 struct visitor<adaptor_functor<T_functor> >
268 {
269   template <class T_action>
270   static void do_visit_each(const T_action& _A_action,
271                             const adaptor_functor<T_functor>& _A_target)
272   {
273     sigc::visit_each(_A_action, _A_target.functor_);
274   }
275 };
276 #endif // DOXYGEN_SHOULD_SKIP_THIS
277
278 /** Trait that specifies what is the adaptor version of a functor type.
279  * Template specializations for sigc::adaptor_base derived functors,
280  * for function pointers and for class methods are provided.
281  *
282  * The template argument @e T_functor is the functor type to convert.
283  * @e I_isadaptor indicates whether @e T_functor inherits from sigc::adaptor_base.
284  *
285  * @ingroup adaptors
286  */
287 #ifndef DOXYGEN_SHOULD_SKIP_THIS
288 template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct adaptor_trait;
289 #else
290 template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct adaptor_trait {};
291 #endif
292
293 /** Trait that specifies what is the adaptor version of a functor type.
294  * This template specialization is used for types that inherit from adaptor_base.
295  * adaptor_type is equal to @p T_functor in this case.
296  */
297 template <class T_functor>
298 struct adaptor_trait<T_functor, true>
299 {
300   typedef typename T_functor::result_type result_type;
301   typedef T_functor functor_type;
302   typedef T_functor adaptor_type;
303 };
304
305 /** Trait that specifies what is the adaptor version of a functor type.
306  * This template specialization is used for arbitrary functors,
307  * for function pointers and for class methods are provided.
308  * The latter are converted into @p pointer_functor or @p mem_functor types.
309  * adaptor_type is equal to @p adaptor_functor<functor_type>.
310  */
311 template <class T_functor>
312 struct adaptor_trait<T_functor, false>
313 {
314   typedef typename functor_trait<T_functor>::result_type result_type;
315   typedef typename functor_trait<T_functor>::functor_type functor_type;
316   typedef adaptor_functor<functor_type> adaptor_type;
317 };
318
319 // Doxygen (at least version 1.8.4) removes blank lines in a code block.
320 // That's why there are empty comment lines in the following code block.
321 /** Base type for adaptors.
322  * sigc::adapts wraps adaptors, functors, function pointers and class methods.
323  * It contains a single member functor which is always a sigc::adaptor_base.
324  * The typedef adaptor_type defines the exact type that is used
325  * to store the adaptor, functor, function pointer or class method passed
326  * into the constructor. It differs from @a T_functor unless @a T_functor
327  * inherits from sigc::adaptor_base.
328  *
329  * @par Example of a simple adaptor:
330  * @code
331  * namespace my_ns
332  * {
333  * template <class T_functor>
334  * struct my_adaptor : public sigc::adapts<T_functor>
335  * {
336  *   template <class T_arg1=void, class T_arg2=void>
337  *   struct deduce_result_type
338  *   { typedef sigc::deduce_result_t<T_functor, T_arg1, T_arg2> type; };
339  *   typedef typename sigc::functor_trait<T_functor>::result_type result_type;
340  *   //
341  *   result_type
342  *   operator()() const;
343  *   //
344  *   template <class T_arg1>
345  *   typename deduce_result_type<T_arg1>::type
346  *   operator()(T_arg1 _A_arg1) const;
347  *   //
348  *   template <class T_arg1, class T_arg2>
349  *   typename deduce_result_type<T_arg1, T_arg2>::type
350  *   operator()(T_arg1 _A_arg1, T_arg2 _A_arg2) const;
351  *   //
352  *   // Constructs a my_adaptor object that wraps the passed functor.
353  *   // Initializes adapts<T_functor>::functor_, which is invoked from operator()().
354  *   explicit my_adaptor(const T_functor& _A_functor)
355  *     : sigc::adapts<T_functor>(_A_functor) {}
356  * };
357  * } // end namespace my_ns
358  * //
359  * // Specialization of sigc::visitor for my_adaptor.
360  * namespace sigc
361  * {
362  * template <class T_functor>
363  * struct visitor<my_ns::my_adaptor<T_functor> >
364  * {
365  *   template <class T_action>
366  *   static void do_visit_each(const T_action& _A_action,
367  *                             const my_ns::my_adaptor<T_functor>& _A_target)
368  *   {
369  *     sigc::visit_each(_A_action, _A_target.functor_);
370  *   }
371  * };
372  * } // end namespace sigc
373  * @endcode
374  *
375  * If you implement your own adaptor, you must also provide your specialization
376  * of sigc::visitor<>::do_visit_each<>() that will forward the call to the functor(s)
377  * your adapter is wrapping. Otherwise, pointers stored within the functor won't be
378  * invalidated when a sigc::trackable object is destroyed and you can end up
379  * executing callbacks on destroyed objects.
380  *
381  * Your specialization of sigc::visitor<> must be in namespace sigc.
382  *
383  * @ingroup adaptors
384  */
385 template <class T_functor>
386 struct adapts : public adaptor_base
387 {
388   typedef typename adaptor_trait<T_functor>::result_type  result_type;
389   typedef typename adaptor_trait<T_functor>::adaptor_type adaptor_type;
390
391   /** Constructs an adaptor that wraps the passed functor.
392    * @param _A_functor Functor to invoke from operator()().
393    */
394   explicit adapts(const T_functor& _A_functor)
395     : functor_(_A_functor)
396     {}
397
398   /// Adaptor that is invoked from operator()().
399   mutable adaptor_type functor_;
400 };
401
402 } /* namespace sigc */
403 #endif /* _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_ */