c++-gtk-utils
callback.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 to 2016 Chris Vine
2 
3 The library comprised in this file or of which this file is part is
4 distributed by Chris Vine under the GNU Lesser General Public
5 License as follows:
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public License
9  as published by the Free Software Foundation; either version 2.1 of
10  the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License, version 2.1, for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License, version 2.1, along with this library (see the file LGPL.TXT
19  which came with this source code package in the c++-gtk-utils
20  sub-directory); if not, write to the Free Software Foundation, Inc.,
21  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23 However, it is not intended that the object code of a program whose
24 source code instantiates a template from this file or uses macros or
25 inline functions (of any length) should by reason only of that
26 instantiation or use be subject to the restrictions of use in the GNU
27 Lesser General Public License. With that in mind, the words "and
28 macros, inline functions and instantiations of templates (of any
29 length)" shall be treated as substituted for the words "and small
30 macros and small inline functions (ten lines or less in length)" in
31 the fourth paragraph of section 5 of that licence. This does not
32 affect any other reason why object code may be subject to the
33 restrictions in that licence (nor for the avoidance of doubt does it
34 affect the application of section 2 of that licence to modifications
35 of the source code in this file).
36 
37 */
38 
39 #ifndef CGU_CALLBACK_H
40 #define CGU_CALLBACK_H
41 
42 /**
43  * @file callback.h
44  * @brief This file provides classes for type erasure.
45  *
46  * \#include <c++-gtk-utils/callback.h>
47  *
48  * These classes provide type erasure on callable objects. They
49  * comprise a generic callback creation and execution interface for
50  * closures. There is a basic Callback::Callback type, which is an
51  * entire closure or 'thunk', where all values are bound into the
52  * object, and is completely opaque. Callback::CallbackArg<T...> is a
53  * class which takes unbound arguments of the template types when the
54  * object is dispatched. (The opaque Callback::Callback type is a
55  * typedef for Callback::CallbackArg<>: the two types are
56  * interchangeable.)
57  *
58  * Objects of these classes are normally constructed using the
59  * Callback::lambda() factory function, which takes any callable
60  * object such as a lambda expression or the return value of
61  * std::bind, and returns a pointer to a Callback/CallbackArg object
62  * allocated on free store. When using Callback::lambda(), the
63  * unbound argument types (if any) must be passed as explicit template
64  * parameters.
65  *
66  * Callback/CallbackArg objects can also be constructed using the
67  * Callback::make() and Callback::make_ref() factory functions, which
68  * can be useful where invoking standalone functions or object
69  * methods.
70  *
71  * From version 2.0.23, a convenience Callback::to_unique() function
72  * is available which will construct a std::unique_ptr object from a
73  * Callback/CallbackArg object returned by Callback::lambda(),
74  * Callback::make() or Callback::make_ref(), for the purpose of taking
75  * ownership of the Callback/CallbackArg object. This function is
76  * mainly intended for use with the auto keyword, to avoid having to
77  * write out the type of the unique_ptr object in longhand.
78  * Corresponding Callback::to_functor() and
79  * Callback::to_safe_functor() functions are also provided.
80  *
81  * The Callback/CallbackArg classes do not provide for a return
82  * value. If a result is wanted, users should pass an unbound argument
83  * by reference or pointer (or pointer to pointer).
84  *
85  * The Callback::make() and Callback::make_ref() functions
86  * -------------------------------------------------------
87  *
88  * The Callback::make() and Callback::make_ref() functions construct a
89  * Callback/CallbackArg object from a function pointer (or an object
90  * reference and member function pointer) together with bound
91  * arguments. They provide for a maximum of five bound arguments, and
92  * the unbound arguments (if any) must be the last (trailing)
93  * arguments of the relevant function or method to be called.
94  *
95  * Callback::make() does a direct type mapping from the bound
96  * arguments of the function or method represented by the callback
97  * object to the arguments stored by it and is for use when all bound
98  * arguments are simple fundamental types such as pointers (including
99  * C strings), integers or floating points.
100  *
101  * Callback::make_ref() is for use where bound arguments include class
102  * types or one or more of the types of the bound arguments include a
103  * const reference. It will accomplish perfect forwarding (by lvalue
104  * reference or rvalue reference) when constructing the callback and
105  * will also ensure that a copy of any object to be passed by const
106  * reference (as well as any taken by value) is kept in order to avoid
107  * dangling references. Note however that where a member function is
108  * called, the object of which the target function is a member must
109  * still be in existence when the Callback/CallbackArg object is
110  * dispatched and, unlike Callback::make(), Callback::make_ref()
111  * cannot be used with overloaded functions except with explicit
112  * disambiguation.
113  *
114  * Callback::make() can also construct a Callback/CallbackArg object
115  * from a std::function object.
116  *
117  * Callback::FunctorArg and Callback::SafeFunctorArg classes
118  * ---------------------------------------------------------
119  *
120  * Functor/FunctorArg objects hold a Callback/CallbackArg object by
121  * SharedPtr to enable them to be shared by reference counting, and
122  * SafeFunctor/SafeFunctorArg objects hold them by SharedLockPtr,
123  * which have a thread safe reference count so that they may be shared
124  * between different threads. These classes also have an operator()()
125  * method so as to be callable with function syntax.
126  *
127  * Memory allocation
128  * -----------------
129  *
130  * If the library is installed using the
131  * \--with-glib-memory-slices-no-compat configuration option, any
132  * Callback/CallbackArg object will be constructed in glib memory
133  * slices rather than in the generic C++ free store.
134  *
135  * Usage
136  * -----
137  *
138  * Using Callback::lambda():
139  *
140  * @code
141  * using namespace Cgu;
142  *
143  * // here cb1 is of type Callback::Callback*
144  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
145  * cb1->dispatch();
146  * delete cb1;
147  *
148  * // here Callback::to_unique() is used to make a std::unique_ptr object to
149  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
150  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
151  * cb2->dispatch();
152  *
153  * // the same using Callback::Functor
154  * Callback::Functor f1{Callback::lambda<>([]() {std::cout << "Hello world\n";})};
155  * f1();
156  *
157  * int k = 5;
158  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
159  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;}));
160  * int res;
161  * cb3->dispatch(2, res);
162  * std::cout << k << " times 10 times 2 is " << res << '\n';
163  *
164  * // the same using Callback::FunctorArg
165  * Callback::FunctorArg<int, int&> f2{Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;})};
166  * f2(2, res);
167  * std::cout << k << " times 10 times 2 is " << res << '\n';
168  * @endcode
169  *
170  * Using Callback::make(), with a class object my_obj of type MyClass,
171  * with a method void MyClass::my_method(int, int, const char*):
172  *
173  * @code
174  * using namespace Cgu;
175  *
176  * int arg1 = 1, arg2 = 5;
177  *
178  * // here cb1 is of type Callback::Callback*
179  * auto cb1 = Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n");
180  * cb1->dispatch();
181  * delete cb1;
182  *
183  * // here cb2 is of type std::unique_ptr<const Callback::Callback>
184  * auto cb2 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n"));
185  * cb2->dispatch();
186  *
187  * // the same using Callback::Functor
188  * Callback::Functor f1{Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n")};
189  * f1();
190  *
191  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, const char*>>
192  * auto cb3 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1));
193  * cb3->dispatch(arg2, "Hello\n");
194  *
195  * // the same using Callback::FunctorArg
196  * Callback::FunctorArg<int, const char*> f2{Callback::make(my_obj, &MyClass::my_method, arg1)};
197  * f2(arg2, "Hello\n");
198  * @endcode
199  *
200  * Using Callback::make_ref(), with a class object my_obj of type
201  * MyClass, with a method void MyClass::my_method(int, const
202  * Something&):
203  *
204  * @code
205  * int arg1 = 1;
206  * Something arg2;
207  * // here cb is of type std::unique_ptr<const Callback::Callback>
208  * auto cb = Callback::to_unique(Callback::make_ref(my_obj, &MyClass::my_method, arg1, arg2));
209  * @endcode
210  *
211  * Posting of callbacks
212  * --------------------
213  *
214  * This file also provides a Callback::post() function which will
215  * execute a callback in a glib main loop and can be used (amongst
216  * other things) to pass an event from a worker thread to the main
217  * program thread. In that respect, it provides an alternative to the
218  * Notifier class. It is passed a pointer to a Callback::Callback
219  * object created with a call to Callback::lambda(), Callback::make(),
220  * Callback::make_ref().
221  *
222  * To provide for thread-safe automatic disconnection of the callback
223  * if the callback represents or calls into a non-static method of an
224  * object which may be destroyed before the callback executes in the
225  * main loop, include a Releaser as a public member of that object and
226  * pass the Releaser object as the second argument of
227  * Callback::post(). Note that for this to be race free, the lifetime
228  * of the remote object whose method is to be invoked must be
229  * determined by the thread to whose main loop the callback has been
230  * attached. When the main loop begins invoking the execution of the
231  * callback, the remote object must either wholly exist (in which case
232  * the callback will be invoked) or have been destroyed (in which case
233  * the callback will be ignored), and not be in some transient
234  * half-state governed by another thread.
235  *
236  * Advantages as against Notifier:
237  *
238  * 1. If there are a lot of different events requiring callbacks to be
239  * dispatched in the program from worker threads to the main
240  * thread, this avoids having separate Notifier objects for each
241  * event.
242  * 2. It is easier to pass arguments with varying values - they can be
243  * passed as bound arguments of the callback and no special
244  * synchronisation is normally required (the call to
245  * g_source_attach() invokes locking of the main loop which will
246  * have the effect of ensuring memory visibility). With a Notifier
247  * object it may be necessary to use an asynchronous queue to pass
248  * variable values (or to bind a reference to the data, thus
249  * normally requiring separate synchronisation).
250  * 3. Although the callback would normally be sent for execution by
251  * the main program loop, and that is the default, it can be sent
252  * for execution by any thread which has its own
253  * GMainContext/GMainLoop objects. Thus callbacks can be passed
254  * for execution between worker threads, or from the main program
255  * thread to worker threads, as well as from worker threads to the
256  * main program thread.
257  *
258  * Disadvantages as against Notifier:
259  *
260  * 1. Less efficient, as a new callback object has to be created on
261  * freestore every time the callback is invoked, together with a
262  * new SafeEmitter object if a Releaser is used to track the
263  * callback.
264  * 2. Multiple callbacks relevant to a single event cannot be invoked
265  * from a single call for the event - each callback has to be
266  * separately dispatched.
267  */
268 
269 /**
270  * @namespace Cgu::Callback
271  * @brief This namespace provides classes for type erasure.
272  *
273  * \#include <c++-gtk-utils/callback.h>
274  *
275  * These classes provide type erasure on callable objects. They
276  * comprise a generic callback creation and execution interface for
277  * closures. There is a basic Callback::Callback type, which is an
278  * entire closure or 'thunk', where all values are bound into the
279  * object, and is completely opaque. Callback::CallbackArg<T...> is a
280  * class which takes unbound arguments of the template types when the
281  * object is dispatched. (The opaque Callback::Callback type is a
282  * typedef for Callback::CallbackArg<>: the two types are
283  * interchangeable.)
284  *
285  * Objects of these classes are normally constructed using the
286  * Callback::lambda() factory function, which takes any callable
287  * object such as a lambda expression or the return value of
288  * std::bind, and returns a pointer to a Callback/CallbackArg object
289  * allocated on free store. When using Callback::lambda(), the
290  * unbound argument types (if any) must be passed as explicit template
291  * parameters.
292  *
293  * Callback/CallbackArg objects can also be constructed using the
294  * Callback::make() and Callback::make_ref() factory functions, which
295  * can be useful where invoking standalone functions or object
296  * methods.
297  *
298  * From version 2.0.23, a convenience Callback::to_unique() function
299  * is available which will construct a std::unique_ptr object from a
300  * Callback/CallbackArg object returned by Callback::lambda(),
301  * Callback::make() or Callback::make_ref(), for the purpose of taking
302  * ownership of the Callback/CallbackArg object. This function is
303  * mainly intended for use with the auto keyword, to avoid having to
304  * write out the type of the unique_ptr object in longhand.
305  * Corresponding Callback::to_functor() and
306  * Callback::to_safe_functor() functions are also provided.
307  *
308  * The Callback/CallbackArg classes do not provide for a return
309  * value. If a result is wanted, users should pass an unbound argument
310  * by reference or pointer (or pointer to pointer).
311  *
312  * The Callback::make() and Callback::make_ref() functions
313  * -------------------------------------------------------
314  *
315  * The Callback::make() and Callback::make_ref() functions construct a
316  * Callback/CallbackArg object from a function pointer (or an object
317  * reference and member function pointer) together with bound
318  * arguments. They provide for a maximum of five bound arguments, and
319  * the unbound arguments (if any) must be the last (trailing)
320  * arguments of the relevant function or method to be called.
321  *
322  * Callback::make() does a direct type mapping from the bound
323  * arguments of the function or method represented by the callback
324  * object to the arguments stored by it and is for use when all bound
325  * arguments are simple fundamental types such as pointers (including
326  * C strings), integers or floating points.
327  *
328  * Callback::make_ref() is for use where bound arguments include class
329  * types or one or more of the types of the bound arguments include a
330  * const reference. It will accomplish perfect forwarding (by lvalue
331  * reference or rvalue reference) when constructing the callback and
332  * will also ensure that a copy of any object to be passed by const
333  * reference (as well as any taken by value) is kept in order to avoid
334  * dangling references. Note however that where a member function is
335  * called, the object of which the target function is a member must
336  * still be in existence when the Callback/CallbackArg object is
337  * dispatched and, unlike Callback::make(), Callback::make_ref()
338  * cannot be used with overloaded functions except with explicit
339  * disambiguation.
340  *
341  * Callback::make() can also construct a Callback/CallbackArg object
342  * from a std::function object.
343  *
344  * Callback::FunctorArg and Callback::SafeFunctorArg classes
345  * ---------------------------------------------------------
346  *
347  * Functor/FunctorArg objects hold a Callback/CallbackArg object by
348  * SharedPtr to enable them to be shared by reference counting, and
349  * SafeFunctor/SafeFunctorArg objects hold them by SharedLockPtr,
350  * which have a thread safe reference count so that they may be shared
351  * between different threads. These classes also have an operator()()
352  * method so as to be callable with function syntax.
353  *
354  * Memory allocation
355  * -----------------
356  *
357  * If the library is installed using the
358  * \--with-glib-memory-slices-no-compat configuration option, any
359  * Callback/CallbackArg object will be constructed in glib memory
360  * slices rather than in the generic C++ free store.
361  *
362  * Usage
363  * -----
364  *
365  * Using Callback::lambda():
366  *
367  * @code
368  * using namespace Cgu;
369  *
370  * // here cb1 is of type Callback::Callback*
371  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
372  * cb1->dispatch();
373  * delete cb1;
374  *
375  * // here Callback::to_unique() is used to make a std::unique_ptr object to
376  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
377  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
378  * cb2->dispatch();
379  *
380  * // the same using Callback::Functor
381  * Callback::Functor f1{Callback::lambda<>([]() {std::cout << "Hello world\n";})};
382  * f1();
383  *
384  * int k = 5;
385  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
386  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;}));
387  * int res;
388  * cb3->dispatch(2, res);
389  * std::cout << k << " times 10 times 2 is " << res << '\n';
390  *
391  * // the same using Callback::FunctorArg
392  * Callback::FunctorArg<int, int&> f2{Callback::lambda<int, int&>([=] (int i, int& j) {j = k * 10 * i;})};
393  * f2(2, res);
394  * std::cout << k << " times 10 times 2 is " << res << '\n';
395  * @endcode
396  *
397  * Using Callback::make(), with a class object my_obj of type MyClass,
398  * with a method void MyClass::my_method(int, int, const char*):
399  *
400  * @code
401  * using namespace Cgu;
402  *
403  * int arg1 = 1, arg2 = 5;
404  *
405  * // here cb1 is of type Callback::Callback*
406  * auto cb1 = Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n");
407  * cb1->dispatch();
408  * delete cb1;
409  *
410  * // here cb2 is of type std::unique_ptr<const Callback::Callback>
411  * auto cb2 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n"));
412  * cb2->dispatch();
413  *
414  * // the same using Callback::Functor
415  * Callback::Functor f1{Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n")};
416  * f1();
417  *
418  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, const char*>>
419  * auto cb3 = Callback::to_unique(Callback::make(my_obj, &MyClass::my_method, arg1));
420  * cb3->dispatch(arg2, "Hello\n");
421  *
422  * // the same using Callback::FunctorArg
423  * Callback::FunctorArg<int, const char*> f2{Callback::make(my_obj, &MyClass::my_method, arg1)};
424  * f2(arg2, "Hello\n");
425  * @endcode
426  *
427  * Using Callback::make_ref(), with a class object my_obj of type
428  * MyClass, with a method void MyClass::my_method(int, const
429  * Something&):
430  *
431  * @code
432  * int arg1 = 1;
433  * Something arg2;
434  * // here cb is of type std::unique_ptr<const Callback::Callback>
435  * auto cb = Callback::to_unique(Callback::make_ref(my_obj, &MyClass::my_method, arg1, arg2));
436  * @endcode
437  *
438  * Posting of callbacks
439  * --------------------
440  *
441  * This namespace also provides a Callback::post() function which will
442  * execute a callback in a glib main loop and can be used (amongst
443  * other things) to pass an event from a worker thread to the main
444  * program thread. In that respect, it provides an alternative to the
445  * Notifier class. It is passed a pointer to a Callback::Callback
446  * object created with a call to Callback::lambda(), Callback::make(),
447  * Callback::make_ref().
448  *
449  * To provide for thread-safe automatic disconnection of the callback
450  * if the callback represents or calls into a non-static method of an
451  * object which may be destroyed before the callback executes in the
452  * main loop, include a Releaser as a public member of that object and
453  * pass the Releaser object as the second argument of
454  * Callback::post(). Note that for this to be race free, the lifetime
455  * of the remote object whose method is to be invoked must be
456  * determined by the thread to whose main loop the callback has been
457  * attached. When the main loop begins invoking the execution of the
458  * callback, the remote object must either wholly exist (in which case
459  * the callback will be invoked) or have been destroyed (in which case
460  * the callback will be ignored), and not be in some transient
461  * half-state governed by another thread.
462  *
463  * Advantages as against Notifier:
464  *
465  * 1. If there are a lot of different events requiring callbacks to be
466  * dispatched in the program from worker threads to the main
467  * thread, this avoids having separate Notifier objects for each
468  * event.
469  * 2. It is easier to pass arguments with varying values - they can be
470  * passed as bound arguments of the callback and no special
471  * synchronisation is normally required (the call to
472  * g_source_attach() invokes locking of the main loop which will
473  * have the effect of ensuring memory visibility). With a Notifier
474  * object it may be necessary to use an asynchronous queue to pass
475  * variable values (or to bind a reference to the data, thus
476  * normally requiring separate synchronisation).
477  * 3. Although the callback would normally be sent for execution by
478  * the main program loop, and that is the default, it can be sent
479  * for execution by any thread which has its own
480  * GMainContext/GMainLoop objects. Thus callbacks can be passed
481  * for execution between worker threads, or from the main program
482  * thread to worker threads, as well as from worker threads to the
483  * main program thread.
484  *
485  * Disadvantages as against Notifier:
486  *
487  * 1. Less efficient, as a new callback object has to be created on
488  * freestore every time the callback is invoked, together with a
489  * new SafeEmitter object if a Releaser is used to track the
490  * callback.
491  * 2. Multiple callbacks relevant to a single event cannot be invoked
492  * from a single call for the event - each callback has to be
493  * separately dispatched.
494  */
495 
496 #include <functional> // for std::less, std::function and std::hash<T*>
497 #include <utility> // for std::move and std::forward
498 #include <memory> // for std::unique_ptr
499 #include <cstddef> // for std::size_t
500 #include <type_traits> // for std::remove_reference and std::remove_const
501 
502 #include <glib.h>
503 
505 #include <c++-gtk-utils/param.h>
507 
508 namespace Cgu {
509 
510 namespace Callback {
511 
512 /*
513  The CallbackArg class could be additionally templated to provide a
514  return value, but that would affect the simplicity of the
515  interface, and if a case were to arise where a result is needed, an
516  alternative is for users to pass an argument by reference or
517  pointer (or pointer to pointer) rather than have a return value.
518 */
519 
520 /* Declare the two interface types */
521 
522 template <class... FreeArgs> class CallbackArg;
523 typedef CallbackArg<> Callback;
524 
525 /* now the class definitions */
526 
527 /**
528  * @class CallbackArg callback.h c++-gtk-utils/callback.h
529  * @brief The callback interface class
530  * @sa Callback namespace
531  * @sa FunctorArg SafeFunctorArg
532  *
533  * This class provides type erasure for callable objects. The
534  * CallbackArg type is constructed on free store and can wrap any
535  * callable object, such as a lambda expression or the return value of
536  * std::bind.
537  *
538  * The class is particularly relevant where a callable object with
539  * bound values needs to be handed safely between threads, or in other
540  * cases where a callback object has to be passed by pointer (which
541  * will happen at some stage with glib or pthreads). They are
542  * therefore useful for general event passing when used together with
543  * the Callback::post() functions or as the continuation for GIO async
544  * operations, and are more efficient than constructing std::function
545  * objects on free store and passing them by pointer (they avoid one
546  * level of indirection and only require one rather than two
547  * allocations).
548  *
549  * The classes are also used in the Emitter/EmitterArg and
550  * SafeEmitter/SafeEmitterArg classes in emitter.h, which enable
551  * callable objects to be connected to an emitter and provide for
552  * automatic disconnection where a class object whose member a
553  * callback represents or calls into ceases to exist. They are also
554  * used internally to implement the Thread::Future and
555  * Thread::TaskManager classes.
556  *
557  * The template types are the types of the unbound arguments, if any.
558  * Callback::CallbackArg<> is typedef'ed to Callback::Callback. The
559  * main method of constructing a Callback/CallbackArg object is with
560  * the Callback::lambda() factory function. When using
561  * Callback::lambda(), the unbound argument types (if any) must be
562  * passed as explicit template parameters.
563  *
564  * Callback/CallbackArg classes do not provide for a return value. If
565  * a result is wanted, users should pass an unbound argument by
566  * reference or pointer (or pointer to pointer).
567  *
568  * @b Usage
569  *
570  * These are examples:
571  *
572  * @code
573  * using namespace Cgu;
574  *
575  * // here cb1 is of type Callback::Callback*
576  * auto cb1 = Callback::lambda<>([]() {std::cout << "Hello world\n";});
577  * cb1->dispatch();
578  * delete cb1;
579  *
580  * // here Callback::to_unique() is used to make a std::unique_ptr object to
581  * // manage the callback. cb2 is of type std::unique_ptr<const Callback::Callback>
582  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {std::cout << "Hello world\n";}));
583  * cb2->dispatch();
584  *
585  * // here cb3 is of type std::unique_ptr<const Callback::CallbackArg<int, int&>>
586  * auto cb3 = Callback::to_unique(Callback::lambda<int, int&>([] (int i, int& j) {j = 10 * i;}));
587  * int res;
588  * cb3->dispatch(2, res);
589  * std::cout << "10 times 2 is " << res << '\n';
590  * @endcode
591  *
592  * For further background, including about the Callback::make(),
593  * Callback::make_ref() and Callback::to_unique() functions, read
594  * this: Callback
595  */
596 
597 template <class... FreeArgs>
598 class CallbackArg {
599 public:
600 /* Because dispatch() is a virtual function, we cannot templatise it
601  * with a view to preserving r-value forwarding of temporary objects
602  * passed as a free argument. But this would rarely be relevant
603  * anyway - it would only be relevant if the target function were to
604  * take an argument by r-value reference and a temporary were to be
605  * passed to it. In such a case virtual dispatch is at the cost of a
606  * copy of the temporary.
607  */
608 /**
609  * This will execute the referenced function, callable object or class
610  * method encapsulated by this class. It will only throw if the
611  * dispatched function, callable object or class method throws, or if
612  * the copy constructor of a free or bound argument throws and it is
613  * not a reference argument. It is thread safe if the referenced
614  * function or class method is thread safe.
615  * @param args The unbound arguments to be passed to the referenced
616  * function, callable object or class method, if any.
617  * @note We use dispatch() to execute the callback, because the
618  * callback would normally be invoked through a base class pointer.
619  * To invoke it through operator()(), use the FunctorArg or
620  * SafeFunctorArg wrapper class.
621  */
622  virtual void dispatch(typename Cgu::Param<FreeArgs>::ParamType... args) const = 0;
623 
624 /**
625  * The constructor will not throw unless the copy constructor of an
626  * argument bound to the derived implementation class throws.
627  */
629 
630 /**
631  * The destructor will not throw unless the destructor of an argument
632  * bound to the derived implementation class throws.
633  */
634  virtual ~CallbackArg() {}
635 
636 /* these functions will be inherited by the derived callback classes */
637 #ifdef CGU_USE_GLIB_MEMORY_SLICES_NO_COMPAT
639 #endif
640 };
641 
642 /**
643  * A function for making a std::unique_ptr object from a
644  * Cgu::Callback::CallbackArg object (say, as constructed by
645  * Cgu::Callback::lambda(), Cgu::Callback::make() or
646  * Cgu::Callback::make_ref()), for the purpose of taking ownership of
647  * the CallbackArg object. It is thread safe and will not throw.
648  *
649  * This function is mainly intended for use with the auto keyword, to
650  * avoid having to write out the type of the unique_ptr object in
651  * longhand. For example:
652  *
653  * @code
654  * using namespace Cgu;
655  * // here a std::unique_ptr<const Cgu::Callback::CallbackArg<const std::string&>> object is constructed
656  * auto cb = Callback::to_unique(Callback::lambda<const std::string&>([] (const std::string& s) {
657  * std::cout << s;
658  * }));
659  * cb->dispatch("Hello\n");
660  * @endcode
661  *
662  * This function cannot be used to overcome the problems of C++'s
663  * unconstrained partial evaluation rules for functions taking more
664  * than one argument (the lack of such constraints is a poor design
665  * choice for a language with exceptions such as C++). For example, a
666  * function:
667  *
668  * @code
669  * void do_it(std::unique_ptr<const Cgu::Callback::Callback> cb1,
670  * std::unique_ptr<const Cgu::Callback::Callback> cb2);
671  * @endcode
672  * should not be called like this:
673  * @code
674  * do_it(Callback::to_unique(Callback::lambda<>([]() {...;})),
675  * Callback::to_unique(Callback::lambda<>([]() {...;})));
676  * @endcode
677  *
678  * This is because one possible sequencing that C++ permits is as
679  * follows:
680  *
681  * 1. Construct the callback object for the first argument by calling
682  * Callback::lambda().
683  * 2. Construct the callback object for the second argument by calling
684  * Callback::lambda().
685  * 3. Initialize a std::unique_ptr object for the second argument by
686  * calling Callback::to_unique().
687  * 4. Initialize a std::unique_ptr object for the first argument by
688  * calling Callback::to_unique().
689  * 5. Enter do_it().
690  *
691  * Because step 2 is permitted to precede step 4, if step 2 throws
692  * then the object constructed at step 1 will be leaked. To avoid
693  * this, explicit sequencing must be provided for in the code, as
694  * follows:
695  *
696  * @code
697  * auto cb1 = Callback::to_unique(Callback::lambda<>([]() {...;}));
698  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {...;}));
699  * do_it(std::move(cb1),
700  * std::move(cb2));
701  * @endcode
702  *
703  * The Cgu::Callback::CallbackArg object held by the unique_ptr
704  * returned by this function is const. This is because all the
705  * interfaces in this library also take const
706  * Cgu::Callback::CallbackArg objects (and their only method, the
707  * dispatch() method, is const). However, if constructed using
708  * Cgu::Callback::lambda(), Cgu::Callback::make() or
709  * Cgu::Callback::make_ref(), the Cgu::Callback::CallbackArg object
710  * can safely be cast to non-const.
711  *
712  * @param cb The CallbackArg object which is to be managed by a
713  * std::unique_ptr.
714  * @return The std::unique_ptr object.
715  *
716  * Since 2.0.23
717  */
718 template<class... T>
719 std::unique_ptr<const CallbackArg<T...>> to_unique(const CallbackArg<T...>* cb) {
720  return std::unique_ptr<const CallbackArg<T...>>(cb);
721 }
722 
723 /* The four basic functor types */
724 
725 template <class... FreeArgs> class FunctorArg;
726 template <class... FreeArgs> class SafeFunctorArg;
727 typedef FunctorArg<> Functor;
729 
730 /* Functor friend functions */
731 
732 // we can use built-in operator == when comparing pointers referencing
733 // different objects of the same type
734 /**
735  * Two FunctorArg objects compare equal if the addresses of the
736  * CallbackArg objects they contain are the same. This comparison
737  * operator does not throw.
738  */
739 template <class... T>
740 bool operator==(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
741  return (f1.cb_s.get() == f2.cb_s.get());
742 }
743 
744 /**
745  * Two FunctorArg objects compare unequal if the addresses of the
746  * CallbackArg objects they contain are not the same. This comparison
747  * operator does not throw.
748  */
749 template <class... T>
750 bool operator!=(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
751  return !(f1 == f2);
752 }
753 
754 // we must use std::less rather than the < built-in operator for
755 // pointers to objects not within the same array or object: "For
756 // templates greater, less, greater_equal, and less_equal, the
757 // specializations for any pointer type yield a total order, even if
758 // the built-in operators <, >, <=, >= do not." (para 20.3.3/8).
759 /**
760  * One FunctorArg object is less than another if the address of the
761  * CallbackArg object contained by the first is regarded by std::less
762  * as less than the address of the CallbackArg object contained by the
763  * other. This comparison operator does not throw unless std::less
764  * applied to pointer types throws (which it would not do with any
765  * sane implementation).
766  */
767 template <class... T>
768 bool operator<(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
769  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
770 }
771 
772 /**
773  * Two SafeFunctorArg objects compare equal if the addresses of the
774  * CallbackArg objects they contain are the same. This comparison
775  * operator does not throw.
776  */
777 template <class... T>
779  return (f1.cb_s.get() == f2.cb_s.get());
780 }
781 
782 /**
783  * Two SafeFunctorArg objects compare unequal if the addresses of the
784  * CallbackArg objects they contain are not the same. This comparison
785  * operator does not throw.
786  */
787 template <class... T>
789  return !(f1 == f2);
790 }
791 
792 /**
793  * One SafeFunctorArg object is less than another if the address of
794  * the CallbackArg object contained by the first is regarded by
795  * std::less as less than the address of the CallbackArg object
796  * contained by the other. This comparison operator does not throw
797  * unless std::less applied to pointer types throws (which it would
798  * not do with any sane implementation).
799  */
800 template <class... T>
802  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
803 }
804 
805 } // namespace Callback
806 } // namespace Cgu
807 
808 // doxygen produces long filenames that tar can't handle:
809 // we have generic documentation for std::hash specialisations
810 // in doxygen.main.in
811 #ifndef DOXYGEN_PARSING
812 
813 /* These structs allow FunctorArg and SafeFunctorArg objects to be
814  keys in unordered associative containers */
815 namespace std {
816 template <class... T>
817 struct hash<Cgu::Callback::FunctorArg<T...>> {
818  typedef std::size_t result_type;
819  typedef Cgu::Callback::FunctorArg<T...> argument_type;
820  result_type operator()(const argument_type& f) const {
821  // this is fine: std::hash structs do not normally contain data and
822  // std::hash<T*> certainly won't, so we don't have overhead constructing
823  // std::hash<T*> on the fly
824  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
825  }
826 };
827 template <class... T>
828 struct hash<Cgu::Callback::SafeFunctorArg<T...>> {
829  typedef std::size_t result_type;
830  typedef Cgu::Callback::SafeFunctorArg<T...> argument_type;
831  result_type operator()(const argument_type& f) const {
832  // this is fine: std::hash structs do not normally contain data and
833  // std::hash<T*> certainly won't, so we don't have overhead constructing
834  // std::hash<T*> on the fly
835  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
836  }
837 };
838 } // namespace std
839 
840 #endif // DOXYGEN_PARSING
841 
842 namespace Cgu {
843 namespace Callback {
844 
845 /* the functor classes */
846 
847 /**
848  * @class FunctorArg callback.h c++-gtk-utils/callback.h
849  * @brief Functor class holding a Callback::CallbackArg object.
850  * @sa SafeFunctorArg
851  * @sa Callback namespace
852  *
853  * This class wraps a CallbackArg object. The callback object is kept
854  * by SharedPtr so the functor can be copied and offers automatic
855  * lifetime management of the wrapped callback object, as well as
856  * providing an operator()() function. Ownership is taken of the
857  * CallbackArg object passed to the constructor taking a CallbackArg
858  * pointer, so that constructor should be treated like a shared
859  * pointer constructor - only pass a newly allocated object to it (or
860  * copy construct it or assign to it from another existing FunctorArg
861  * object). The template types are the types of the unbound
862  * arguments, if any. Callback::FunctorArg<> is typedef'ed to
863  * Callback::Functor.
864  *
865  * The constructor taking a Callback::CallbackArg pointer is not
866  * marked explicit, so the results of Callback::lambda(),
867  * Callback::make() or Callback::make_ref() can be passed directly to
868  * a function taking a Callback::FunctorArg argument, and implicit
869  * conversion will take place.
870  *
871  * Functor/FunctorArg classes do not provide for a return value. If
872  * a result is wanted, users should pass an unbound argument by
873  * reference or pointer (or pointer to pointer).
874  *
875  * @b Usage
876  *
877  * These are examples:
878  *
879  * @code
880  * using namespace Cgu;
881  *
882  * // here f1 is directly initialized using the type conversion constructor
883  * Callback::Functor f1{Callback::lambda<>([] () {std::cout << "Hello world\n";})};
884  * f1();
885  *
886  * // here Callback::to_functor() is used to enable use of the auto keyword.
887  * // f2 is of type Callback::Functor
888  * auto f2 = Callback::to_functor(Callback::lambda<>([] () {std::cout << "Hello world\n";}));
889  * f2();
890  *
891  * // here f3 is of type Callback::FunctorArg<int, int&>
892  * auto f3 = Callback::to_functor(Callback::lambda<int, int&>([] (int i, int& j) {j = 10 * i;}));
893  * int res;
894  * f3(2, res);
895  * std::cout << "10 times 2 is " << res << '\n';
896  * @endcode
897  *
898  * For further background, including about the Callback::make(),
899  * Callback::make_ref() and Callback::to_functor() functions, read
900  * this: Callback
901  */
902 
903 template <class... FreeArgs>
904 class FunctorArg {
905  SharedPtr<const CallbackArg<FreeArgs...>> cb_s;
906 public:
907 /* Because CallbackArg::dispatch() is a virtual function, it is
908  * pointless templatising this function with a view to preserving
909  * r-value forwarding of temporary objects passed as a free argument,
910  * because the r-value typeness will be discarded in dispatch(). But
911  * this would rarely be relevant anyway - it would only be relevant if
912  * the target function were to take an argument by r-value reference
913  * and a temporary were to be passed to it. In such a case virtual
914  * dispatch is at the cost of a copy of the temporary.
915  */
916 /**
917  * This will execute the function, callable object or class method
918  * represented by the callback encapsulated by this object, or do
919  * nothing if this object has not been initialized with a callback.
920  * It will only throw if the executed function, callable object or
921  * class method throws, or if the copy constructor of a free or bound
922  * argument throws and it is not a reference argument. It is thread
923  * safe if the referenced function or class method is thread safe.
924  * @param args The unbound arguments to be passed to the referenced
925  * function, callable object or class method, if any.
926  */
927  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
928  if (cb_s.get()) cb_s->dispatch(args...);
929  }
930 
931 /**
932  * This function does not throw.
933  * @param f The assignor.
934  * @return The functor object after assignment.
935  */
936  FunctorArg& operator=(const FunctorArg& f) {cb_s = f.cb_s; return *this;}
937 
938 /**
939  * This function does not throw.
940  * @param f The functor to be moved.
941  * @return The functor object after the move operation.
942  */
943  FunctorArg& operator=(FunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
944 
945 /**
946  * Two FunctorArg objects compare equal if the addresses of the
947  * CallbackArg objects they contain are the same. This comparison
948  * operator does not throw.
949  */
950  friend bool operator== <>(const FunctorArg&, const FunctorArg&);
951 
952 /**
953  * One FunctorArg object is less than another if the address of the
954  * CallbackArg object contained by the first is regarded by std::less
955  * as less than the address of the CallbackArg object contained by the
956  * other. This comparison operator does not throw.
957  */
958  friend bool operator< <>(const FunctorArg&, const FunctorArg&);
959 
960  friend struct std::hash<FunctorArg>;
961 
962 /**
963  * Constructor of first FunctorArg holding the referenced callback.
964  * As it is not marked explicit, it is also a type conversion
965  * constructor.
966  * @param cb The CallbackArg object which the functor is to manage.
967  * @exception std::bad_alloc This might throw std::bad_alloc if
968  * memory is exhausted and the system throws in that case. Note that
969  * if such an exception is thrown, then this constructor will clean
970  * itself up and also delete the callback object passed to it.
971  * @note std::bad_alloc will not be thrown if the library has been
972  * installed using the \--with-glib-memory-slices-no-compat
973  * configuration option: instead glib will terminate the program if it
974  * is unable to obtain memory from the operating system.
975  */
976  FunctorArg(const CallbackArg<FreeArgs...>* cb): cb_s(cb) {}
977 
978 /**
979  * The copy constructor does not throw.
980  * @param f The assignor
981  */
982  FunctorArg(const FunctorArg& f): cb_s(f.cb_s) {}
983 
984 /**
985  * The move constructor does not throw.
986  * @param f The functor to be moved.
987  */
988  FunctorArg(FunctorArg&& f): cb_s(std::move(f.cb_s)) {}
989 
990  /**
991  * Default constructor, where a Callback::CallbackArg object is to be
992  * assigned later (via the type conversion constructor and/or the
993  * assignment operator). This constructor does not throw.
994  */
996 
997 /* Only has effect if --with-glib-memory-slices-compat or
998  --with-glib-memory-slices-no-compat option picked */
1000 };
1001 
1002 /**
1003  * @class SafeFunctorArg callback.h c++-gtk-utils/callback.h
1004  * @brief Functor class holding a Callback::CallbackArg object, with
1005  * thread-safe reference count.
1006  * @sa FunctorArg
1007  * @sa Callback namespace
1008  *
1009  * This class wraps a CallbackArg object. It is the same as
1010  * Callback::FunctorArg except that it will provide synchronisation of
1011  * the reference count between threads. Use it where a functor
1012  * wrapper object is to be passed between threads. The FunctorArg
1013  * documentation gives further details. The
1014  * Callback::to_safe_functor() function can be used in place of the
1015  * Callback::to_functor() function when constructing a
1016  * Callback::SafeFunctorArg object using the auto keyword.
1017  *
1018  * Callback::SafeFunctorArg<> is typedef'ed to Callback::SafeFunctor.
1019  *
1020  * For further background, including about the Callback::make(),
1021  * Callback::make_ref() and Callback::to_safe_functor() functions,
1022  * read this: Callback
1023  */
1024 
1025 template <class... FreeArgs>
1026 class SafeFunctorArg {
1027  SharedLockPtr<const CallbackArg<FreeArgs...>> cb_s;
1028 public:
1029 /**
1030  * This will execute the function, callable object or class method
1031  * represented by the callback encapsulated by this object, or do
1032  * nothing if this object has not been initialized with a callback.
1033  * It will only throw if the executed function, callable object or
1034  * class method throws, or if the copy constructor of a free or bound
1035  * argument throws and it is not a reference argument. It is thread
1036  * safe if the referenced function or class method is thread safe.
1037  * @param args The unbound arguments to be passed to the referenced
1038  * function, callable object or class method, if any.
1039  */
1040  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
1041  if (cb_s.get()) cb_s->dispatch(args...);
1042  }
1043 
1044 /**
1045  * This function does not throw.
1046  * @param f The assignor.
1047  * @return The functor object after assignment.
1048  */
1049  SafeFunctorArg& operator=(const SafeFunctorArg& f) {cb_s = f.cb_s; return *this;}
1050 
1051 /**
1052  * This function does not throw.
1053  * @param f The functor to be moved.
1054  * @return The functor object after the move operation.
1055  */
1056  SafeFunctorArg& operator=(SafeFunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
1057 
1058 /**
1059  * Two SafeFunctorArg objects compare equal if the addresses of the
1060  * CallbackArg objects they contain are the same. This comparison
1061  * operator does not throw.
1062  */
1063  friend bool operator== <>(const SafeFunctorArg&, const SafeFunctorArg&);
1064 
1065 /**
1066  * One SafeFunctorArg object is less than another if the address of
1067  * the CallbackArg object contained by the first is regarded by
1068  * std::less as less than the address of the CallbackArg object
1069  * contained by the other. This comparison operator does not throw.
1070  */
1071  friend bool operator< <>(const SafeFunctorArg&, const SafeFunctorArg&);
1072 
1073  friend struct std::hash<SafeFunctorArg>;
1074 
1075  /**
1076  * Constructor of first SafeFunctorArg holding the referenced
1077  * callback. As it is not marked explicit, it is also a type
1078  * conversion constructor.
1079  * @param cb The CallbackArg object which the functor is to manage.
1080  * @exception std::bad_alloc This might throw std::bad_alloc if
1081  * memory is exhausted and the system throws in that case. Note that
1082  * if such an exception is thrown, then this constructor will clean
1083  * itself up and also delete the callback object passed to it.
1084  * @note std::bad_alloc will not be thrown if the library has been
1085  * installed using the \--with-glib-memory-slices-no-compat
1086  * configuration option: instead glib will terminate the program if it
1087  * is unable to obtain memory from the operating system.
1088  */
1090 
1091 /**
1092  * The copy constructor does not throw.
1093  * @param f The assignor.
1094  */
1095  SafeFunctorArg(const SafeFunctorArg& f): cb_s(f.cb_s) {}
1096 
1097 /**
1098  * The move constructor does not throw.
1099  * @param f The functor to be moved.
1100  */
1101  SafeFunctorArg(SafeFunctorArg&& f): cb_s(std::move(f.cb_s)) {}
1102 
1103  /**
1104  * Default constructor, where a Callback::CallbackArg object is to be
1105  * assigned later (via the type conversion constructor and/or the
1106  * assignment operator). This constructor does not throw.
1107  * @note The reference count maintained with respect to the contained
1108  * callback object is thread-safe, so SafeFunctorArg objects may be
1109  * copied between threads by the implicit assignment operator and put
1110  * in different containers in different threads. They use a
1111  * SharedLockPtr object to hold the referenced callback object.
1112  */
1114 
1115 /* Only has effect if --with-glib-memory-slices-compat or
1116  --with-glib-memory-slices-no-compat option picked */
1118 };
1119 
1120 /**
1121  * A function for making a Cgu::Callback::FunctorArg object from a
1122  * Cgu::Callback::CallbackArg object, for the purpose of taking
1123  * ownership of the CallbackArg object. It is thread safe.
1124  *
1125  * Because the constructor of FunctorArg taking a pointer is not
1126  * explicit and can therefore be used for implicit type conversion,
1127  * this function will not often be needed. It is mainly intended for
1128  * use when constructing a named object in local scope with the auto
1129  * keyword, to avoid having to write out the type of the FunctorArg
1130  * object in longhand. For example:
1131  *
1132  * @code
1133  * using namespace Cgu;
1134  * // here a Cgu::Callback::FunctorArg<const std::string&> object is constructed
1135  * auto f = Callback::to_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1136  * std::cout << s;
1137  * }));
1138  * f("Hello\n");
1139  * @endcode
1140  *
1141  * @param cb The CallbackArg object which is to be managed by a
1142  * functor.
1143  * @return The FunctorArg object.
1144  * @exception std::bad_alloc This function might throw std::bad_alloc
1145  * if memory is exhausted and the system throws in that case. Note
1146  * that if such an exception is thrown, then this function will delete
1147  * the callback object passed to it.
1148  * @note std::bad_alloc will not be thrown if the library has been
1149  * installed using the \--with-glib-memory-slices-no-compat
1150  * configuration option: instead glib will terminate the program if it
1151  * is unable to obtain memory from the operating system.
1152  *
1153  * Since 2.0.23
1154  */
1155 template<class... T>
1157  return cb;
1158 }
1159 
1160 /**
1161  * A function for making a Cgu::Callback::SafeFunctorArg object from a
1162  * Cgu::Callback::CallbackArg object, for the purpose of taking
1163  * ownership of the CallbackArg object. It is thread safe.
1164  *
1165  * Because the constructor of SafeFunctorArg taking a pointer is not
1166  * explicit and can therefore be used for implicit type conversion,
1167  * this function will not often be needed. It is mainly intended for
1168  * use when constructing a named object in local scope with the auto
1169  * keyword, to avoid having to write out the type of the
1170  * SafeFunctorArg object in longhand. For example:
1171  *
1172  * @code
1173  * using namespace Cgu;
1174  * // here a Cgu::Callback::SafeFunctorArg<const std::string&> object is constructed
1175  * auto f = Callback::to_safe_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1176  * std::cout << s;
1177  * }));
1178  * f("Hello\n");
1179  * @endcode
1180  *
1181  * @param cb The CallbackArg object which is to be managed by a
1182  * functor.
1183  * @return The SafeFunctorArg object.
1184  * @exception std::bad_alloc This function might throw std::bad_alloc
1185  * if memory is exhausted and the system throws in that case. Note
1186  * that if such an exception is thrown, then this function will delete
1187  * the callback object passed to it.
1188  * @note std::bad_alloc will not be thrown if the library has been
1189  * installed using the \--with-glib-memory-slices-no-compat
1190  * configuration option: instead glib will terminate the program if it
1191  * is unable to obtain memory from the operating system.
1192  *
1193  * Since 2.0.23
1194  */
1195 template<class... T>
1197  return cb;
1198 }
1199 
1200 /* the callback implementation classes */
1201 
1202 template <class T, class... FreeArgs>
1203 class Callback0: public CallbackArg<FreeArgs...> {
1204 public:
1205  typedef void (T::* MemFunc)(FreeArgs...);
1206 private:
1207  T* obj;
1208  MemFunc func;
1209 public:
1210  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1211  (obj->*func)(free_args...);
1212  }
1213  Callback0(T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
1214 };
1215 
1216 template <bool unref, class T, class BoundArg, class... FreeArgs>
1217 class Callback1: public CallbackArg<FreeArgs...> {
1218 public:
1219  typedef void (T::* MemFunc)(BoundArg, FreeArgs...);
1220 private:
1221  T* obj;
1222  MemFunc func;
1224 public:
1225  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1226  (obj->*func)(arg, free_args...);
1227  }
1228  template <class Arg>
1229  Callback1(T& obj_, MemFunc func_,
1230  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
1231 };
1232 
1233 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1234 class Callback2: public CallbackArg<FreeArgs...> {
1235 public:
1236  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...);
1237 private:
1238  T* obj;
1239  MemFunc func;
1242 public:
1243  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1244  (obj->*func)(arg1, arg2, free_args...);
1245  }
1246  template <class Arg1, class Arg2>
1247  Callback2(T& obj_, MemFunc func_,
1248  Arg1&& arg1_,
1249  Arg2&& arg2_): obj(&obj_), func(func_),
1250  arg1(std::forward<Arg1>(arg1_)),
1251  arg2(std::forward<Arg2>(arg2_)) {}
1252 };
1253 
1254 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1255 class Callback3: public CallbackArg<FreeArgs...> {
1256 public:
1257  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
1258 private:
1259  T* obj;
1260  MemFunc func;
1264 public:
1265  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1266  (obj->*func)(arg1, arg2, arg3, free_args...);
1267  }
1268  template <class Arg1, class Arg2, class Arg3>
1269  Callback3(T& obj_, MemFunc func_,
1270  Arg1&& arg1_,
1271  Arg2&& arg2_,
1272  Arg3&& arg3_):
1273  obj(&obj_), func(func_),
1274  arg1(std::forward<Arg1>(arg1_)),
1275  arg2(std::forward<Arg2>(arg2_)),
1276  arg3(std::forward<Arg3>(arg3_)) {}
1277 };
1278 
1279 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1280  class BoundArg4, class... FreeArgs>
1281 class Callback4: public CallbackArg<FreeArgs...> {
1282 public:
1283  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
1284 private:
1285  T* obj;
1286  MemFunc func;
1291 public:
1292  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1293  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
1294  }
1295  template <class Arg1, class Arg2, class Arg3, class Arg4>
1296  Callback4(T& obj_, MemFunc func_,
1297  Arg1&& arg1_,
1298  Arg2&& arg2_,
1299  Arg3&& arg3_,
1300  Arg4&& arg4_):
1301  obj(&obj_), func(func_),
1302  arg1(std::forward<Arg1>(arg1_)),
1303  arg2(std::forward<Arg2>(arg2_)),
1304  arg3(std::forward<Arg3>(arg3_)),
1305  arg4(std::forward<Arg4>(arg4_)) {}
1306 };
1307 
1308 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1309  class BoundArg4, class BoundArg5, class... FreeArgs>
1310 class Callback5: public CallbackArg<FreeArgs...> {
1311 public:
1312  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
1313  BoundArg4, BoundArg5, FreeArgs...);
1314 private:
1315  T* obj;
1316  MemFunc func;
1322 public:
1323  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1324  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
1325  }
1326  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1327  Callback5(T& obj_, MemFunc func_,
1328  Arg1&& arg1_,
1329  Arg2&& arg2_,
1330  Arg3&& arg3_,
1331  Arg4&& arg4_,
1332  Arg5&& arg5_):
1333  obj(&obj_), func(func_),
1334  arg1(std::forward<Arg1>(arg1_)),
1335  arg2(std::forward<Arg2>(arg2_)),
1336  arg3(std::forward<Arg3>(arg3_)),
1337  arg4(std::forward<Arg4>(arg4_)),
1338  arg5(std::forward<Arg5>(arg5_)) {}
1339 };
1340 
1341 /* const versions, for binding to const methods */
1342 
1343 template <class T, class... FreeArgs>
1344 class Callback0_const: public CallbackArg<FreeArgs...> {
1345 public:
1346  typedef void (T::* MemFunc)(FreeArgs...) const;
1347 private:
1348  const T* obj;
1349  MemFunc func;
1350 public:
1351  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1352  (obj->*func)(free_args...);
1353  }
1354  Callback0_const(const T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
1355 };
1356 
1357 template <bool unref, class T, class BoundArg, class... FreeArgs>
1358 class Callback1_const: public CallbackArg<FreeArgs...> {
1359 public:
1360  typedef void (T::* MemFunc)(BoundArg, FreeArgs...) const;
1361 private:
1362  const T* obj;
1363  MemFunc func;
1365 public:
1366  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1367  (obj->*func)(arg, free_args...);
1368  }
1369  template <class Arg>
1370  Callback1_const(const T& obj_, MemFunc func_,
1371  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
1372 };
1373 
1374 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1375 class Callback2_const: public CallbackArg<FreeArgs...> {
1376 public:
1377  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...) const;
1378 private:
1379  const T* obj;
1380  MemFunc func;
1383 public:
1384  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1385  (obj->*func)(arg1, arg2, free_args...);
1386  }
1387  template <class Arg1, class Arg2>
1388  Callback2_const(const T& obj_, MemFunc func_,
1389  Arg1&& arg1_,
1390  Arg2&& arg2_): obj(&obj_), func(func_),
1391  arg1(std::forward<Arg1>(arg1_)),
1392  arg2(std::forward<Arg2>(arg2_)) {}
1393 };
1394 
1395 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1396 class Callback3_const: public CallbackArg<FreeArgs...> {
1397 public:
1398  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const;
1399 private:
1400  const T* obj;
1401  MemFunc func;
1405 public:
1406  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1407  (obj->*func)(arg1, arg2, arg3, free_args...);
1408  }
1409  template <class Arg1, class Arg2, class Arg3>
1410  Callback3_const(const T& obj_, MemFunc func_,
1411  Arg1&& arg1_,
1412  Arg2&& arg2_,
1413  Arg3&& arg3_):
1414  obj(&obj_), func(func_),
1415  arg1(std::forward<Arg1>(arg1_)),
1416  arg2(std::forward<Arg2>(arg2_)),
1417  arg3(std::forward<Arg3>(arg3_)) {}
1418 };
1419 
1420 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1421  class BoundArg4, class... FreeArgs>
1422 class Callback4_const: public CallbackArg<FreeArgs...> {
1423 public:
1424  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...) const;
1425 private:
1426  const T* obj;
1427  MemFunc func;
1432 public:
1433  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1434  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
1435  }
1436  template <class Arg1, class Arg2, class Arg3, class Arg4>
1437  Callback4_const(const T& obj_, MemFunc func_,
1438  Arg1&& arg1_,
1439  Arg2&& arg2_,
1440  Arg3&& arg3_,
1441  Arg4&& arg4_):
1442  obj(&obj_), func(func_),
1443  arg1(std::forward<Arg1>(arg1_)),
1444  arg2(std::forward<Arg2>(arg2_)),
1445  arg3(std::forward<Arg3>(arg3_)),
1446  arg4(std::forward<Arg4>(arg4_)) {}
1447 };
1448 
1449 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1450  class BoundArg4, class BoundArg5, class... FreeArgs>
1451 class Callback5_const: public CallbackArg<FreeArgs...> {
1452 public:
1453  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
1454  BoundArg4, BoundArg5, FreeArgs...) const;
1455 private:
1456  const T* obj;
1457  MemFunc func;
1463 public:
1464  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1465  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
1466  }
1467  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1468  Callback5_const(const T& obj_, MemFunc func_,
1469  Arg1&& arg1_,
1470  Arg2&& arg2_,
1471  Arg3&& arg3_,
1472  Arg4&& arg4_,
1473  Arg5&& arg5_):
1474  obj(&obj_), func(func_),
1475  arg1(std::forward<Arg1>(arg1_)),
1476  arg2(std::forward<Arg2>(arg2_)),
1477  arg3(std::forward<Arg3>(arg3_)),
1478  arg4(std::forward<Arg4>(arg4_)),
1479  arg5(std::forward<Arg5>(arg5_)) {}
1480 };
1481 
1482 /* for static class methods and non-class functions */
1483 
1484 template <class... FreeArgs>
1485 class Callback0_static: public CallbackArg<FreeArgs...> {
1486 public:
1487  typedef void (*Func)(FreeArgs...);
1488 private:
1489  Func func;
1490 public:
1491  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1492  func(free_args...);
1493  }
1494  Callback0_static(Func func_): func(func_) {}
1495 };
1496 
1497 template <bool unref, class BoundArg, class... FreeArgs>
1498 class Callback1_static: public CallbackArg<FreeArgs...> {
1499 public:
1500  typedef void (*Func)(BoundArg, FreeArgs...);
1501 private:
1502  Func func;
1504 public:
1505  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1506  func(arg, free_args...);
1507  }
1508  template <class Arg>
1509  Callback1_static(Func func_, Arg&& arg_): func(func_), arg(std::forward<Arg>(arg_)) {}
1510 };
1511 
1512 template <bool unref, class BoundArg1, class BoundArg2, class... FreeArgs>
1513 class Callback2_static: public CallbackArg<FreeArgs...> {
1514 public:
1515  typedef void (*Func)(BoundArg1, BoundArg2, FreeArgs...);
1516 private:
1517  Func func;
1520 public:
1521  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1522  func(arg1, arg2, free_args...);
1523  }
1524  template <class Arg1, class Arg2>
1525  Callback2_static(Func func_, Arg1&& arg1_,
1526  Arg2&& arg2_): func(func_),
1527  arg1(std::forward<Arg1>(arg1_)),
1528  arg2(std::forward<Arg2>(arg2_)) {}
1529 };
1530 
1531 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1532 class Callback3_static: public CallbackArg<FreeArgs...> {
1533 public:
1534  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
1535 private:
1536  Func func;
1540 public:
1541  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1542  func(arg1, arg2, arg3, free_args...);
1543  }
1544  template <class Arg1, class Arg2, class Arg3>
1546  Arg1&& arg1_,
1547  Arg2&& arg2_,
1548  Arg3&& arg3_):
1549  func(func_),
1550  arg1(std::forward<Arg1>(arg1_)),
1551  arg2(std::forward<Arg2>(arg2_)),
1552  arg3(std::forward<Arg3>(arg3_)) {}
1553 };
1554 
1555 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
1556  class BoundArg4, class... FreeArgs>
1557 class Callback4_static: public CallbackArg<FreeArgs...> {
1558 public:
1559  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
1560 private:
1561  Func func;
1566 public:
1567  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1568  func(arg1, arg2, arg3, arg4, free_args...);
1569  }
1570  template <class Arg1, class Arg2, class Arg3, class Arg4>
1572  Arg1&& arg1_,
1573  Arg2&& arg2_,
1574  Arg3&& arg3_,
1575  Arg4&& arg4_):
1576  func(func_),
1577  arg1(std::forward<Arg1>(arg1_)),
1578  arg2(std::forward<Arg2>(arg2_)),
1579  arg3(std::forward<Arg3>(arg3_)),
1580  arg4(std::forward<Arg4>(arg4_)) {}
1581 };
1582 
1583 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
1584  class BoundArg4, class BoundArg5, class... FreeArgs>
1585 class Callback5_static: public CallbackArg<FreeArgs...> {
1586 public:
1587  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3,
1588  BoundArg4, BoundArg5, FreeArgs...);
1589 private:
1590  Func func;
1596 public:
1597  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1598  func(arg1, arg2, arg3, arg4, arg5, free_args...);
1599  }
1600  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1602  Arg1&& arg1_,
1603  Arg2&& arg2_,
1604  Arg3&& arg3_,
1605  Arg4&& arg4_,
1606  Arg5&& arg5_):
1607  func(func_),
1608  arg1(std::forward<Arg1>(arg1_)),
1609  arg2(std::forward<Arg2>(arg2_)),
1610  arg3(std::forward<Arg3>(arg3_)),
1611  arg4(std::forward<Arg4>(arg4_)),
1612  arg5(std::forward<Arg5>(arg5_)) {}
1613 };
1614 
1615 // TODO: Version 2.0.9 provides a Callback_lambda class for callable
1616 // objects which makes the specialized Callback_function class
1617 // redundant. At an API break we can remove the Callback_function
1618 // class and modify the Callback::make() helper function overload for
1619 // std::function objects to construct a Callback_lambda object
1620 // instead. Doing it now would not affect ABI compatibility as the
1621 // library produces these only by base pointer, but a user may have
1622 // instantiated them by hand in user code.
1623 template <class... FreeArgs>
1624 class Callback_function: public CallbackArg<FreeArgs...> {
1625  std::function<void(FreeArgs...)> f;
1626 public:
1627  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {f(free_args...);}
1628  Callback_function(const std::function<void(FreeArgs...)>& f_): f(f_) {}
1629  Callback_function(std::function<void(FreeArgs...)>&& f_): f(std::move(f_)) {}
1630 };
1631 
1632 // generic class for callable objects such as lambdas
1633 template <class Lambda, class... FreeArgs>
1634 class Callback_lambda: public CallbackArg<FreeArgs...> {
1635  // making 'l' mutable means that Callback_lamdba objects can contain
1636  // mutable lambda expressions
1637  mutable Lambda l;
1638 public:
1639  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {l(free_args...);}
1640  template <class L> Callback_lambda(L&& l_): l(std::forward<L>(l_)) {}
1641 };
1642 
1643 /* Convenience functions making callback objects on freestore. These
1644  * can for example be passed as the first argument of the
1645  * Thread::start() method in thread.h. They are also used by the
1646  * Callback::post() function.
1647 */
1648 
1649 /**
1650  * A convenience function to make Callback::CallbackArg objects
1651  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1652  * is exhausted and the system throws in that case. This exception
1653  * will not be thrown if the library has been installed using the
1654  * \--with-glib-memory-slices-no-compat configuration option (instead
1655  * glib will terminate the program if it is unable to obtain memory
1656  * from the operating system).
1657  */
1658 template <class T, class... FreeArgs>
1659 CallbackArg<FreeArgs...>* make(T& t,
1660  void (T::*func)(FreeArgs...)) {
1661  return new Callback0<T, FreeArgs...>{t, func};
1662 }
1663 
1664 /**
1665  * DEPRECATED.
1666  *
1667  * Since this function constructs a callback which does not take a
1668  * bound argument, it is a synonym for make() (the two are identical).
1669  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1670  * is exhausted and the system throws in that case. This exception
1671  * will not be thrown if the library has been installed using the
1672  * \--with-glib-memory-slices-no-compat configuration option (instead
1673  * glib will terminate the program if it is unable to obtain memory
1674  * from the operating system).
1675  */
1676 template <class T, class... FreeArgs>
1677 CallbackArg<FreeArgs...>* make_val(T& t,
1678  void (T::*func)(FreeArgs...)) {
1679  return new Callback0<T, FreeArgs...>{t, func};
1680 }
1681 
1682 /**
1683  * Since this function constructs a callback which does not take a
1684  * bound argument, it is a synonym for make() (the two are identical).
1685  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1686  * is exhausted and the system throws in that case. This exception
1687  * will not be thrown if the library has been installed using the
1688  * \--with-glib-memory-slices-no-compat configuration option (instead
1689  * glib will terminate the program if it is unable to obtain memory
1690  * from the operating system).
1691  *
1692  * Since 2.0.0-rc3
1693  */
1694 template <class T, class... FreeArgs>
1695 CallbackArg<FreeArgs...>* make_ref(T& t,
1696  void (T::*func)(FreeArgs...)) {
1697  return new Callback0<T, FreeArgs...>{t, func};
1698 }
1699 
1700 /**
1701  * A convenience function to make Callback::CallbackArg objects
1702  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1703  * is exhausted and the system throws in that case (this exception
1704  * will not be thrown if the library has been installed using the
1705  * \--with-glib-memory-slices-no-compat configuration option: instead
1706  * glib will terminate the program if it is unable to obtain memory
1707  * from the operating system). It will also throw if the copy
1708  * constructor of a bound argument throws and it is not a reference
1709  * argument.
1710  */
1711 template <class T, class BoundArg, class... FreeArgs>
1712 CallbackArg<FreeArgs...>* make(T& t,
1713  void (T::*func)(BoundArg, FreeArgs...),
1714  BoundArg arg) {
1715  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
1716 }
1717 
1718 /**
1719  * DEPRECATED: use Callback::make_ref() instead.
1720  *
1721  * An alternative function to make Callback::CallbackArg objects,
1722  * which is for use where a target function receives an argument of
1723  * class type by value which is to be a bound argument, so the
1724  * compiler is not able to carry out copy elision when constructing
1725  * the callback object.
1726  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1727  * is exhausted and the system throws in that case (this exception
1728  * will not be thrown if the library has been installed using the
1729  * \--with-glib-memory-slices-no-compat configuration option: instead
1730  * glib will terminate the program if it is unable to obtain memory
1731  * from the operating system). It will also throw if the copy
1732  * constructor of a bound argument throws and it is not a reference
1733  * argument.
1734  */
1735 template <class T, class BoundArg, class... FreeArgs>
1736 CallbackArg<FreeArgs...>* make_val(T& t,
1737  void (T::*func)(BoundArg, FreeArgs...),
1738  const BoundArg& arg) {
1739  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
1740 }
1741 
1742 /**
1743  * An alternative function to make Callback::CallbackArg objects,
1744  * which is for use where a target function either receives a class
1745  * type bound argument by value, or receives a bound argument by
1746  * reference to const in a case where the generated CallbackArg object
1747  * is to store a copy of that argument instead of just keeping a
1748  * reference.
1749  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1750  * is exhausted and the system throws in that case (this exception
1751  * will not be thrown if the library has been installed using the
1752  * \--with-glib-memory-slices-no-compat configuration option: instead
1753  * glib will terminate the program if it is unable to obtain memory
1754  * from the operating system). It will also throw if the copy or move
1755  * constructor of a bound argument throws.
1756  *
1757  * Since 2.0.0-rc3
1758  */
1759 template <class T, class BoundArg, class Arg, class... FreeArgs>
1760 CallbackArg<FreeArgs...>* make_ref(T& t,
1761  void (T::*func)(BoundArg, FreeArgs...),
1762  Arg&& arg) {
1763  return new Callback1<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
1764 }
1765 
1766 /**
1767  * A convenience function to make Callback::CallbackArg objects
1768  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1769  * is exhausted and the system throws in that case (this exception
1770  * will not be thrown if the library has been installed using the
1771  * \--with-glib-memory-slices-no-compat configuration option: instead
1772  * glib will terminate the program if it is unable to obtain memory
1773  * from the operating system). It will also throw if the copy
1774  * constructor of a bound argument throws and it is not a reference
1775  * argument.
1776  */
1777 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1778 CallbackArg<FreeArgs...>* make(T& t,
1779  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1780  BoundArg1 arg1,
1781  BoundArg2 arg2) {
1782  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
1783 }
1784 
1785 /**
1786  * DEPRECATED: use Callback::make_ref() instead.
1787  *
1788  * An alternative function to make Callback::CallbackArg objects,
1789  * which is for use where a target function receives an argument of
1790  * class type by value which is to be a bound argument, so the
1791  * compiler is not able to carry out copy elision when constructing
1792  * the callback object.
1793  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1794  * is exhausted and the system throws in that case (this exception
1795  * will not be thrown if the library has been installed using the
1796  * \--with-glib-memory-slices-no-compat configuration option: instead
1797  * glib will terminate the program if it is unable to obtain memory
1798  * from the operating system). It will also throw if the copy
1799  * constructor of a bound argument throws and it is not a reference
1800  * argument.
1801  */
1802 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1803 CallbackArg<FreeArgs...>* make_val(T& t,
1804  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1805  const BoundArg1& arg1,
1806  const BoundArg2& arg2) {
1807  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
1808 }
1809 
1810 /**
1811  * An alternative function to make Callback::CallbackArg objects,
1812  * which is for use where a target function either receives a class
1813  * type bound argument by value, or receives a bound argument by
1814  * reference to const in a case where the generated CallbackArg object
1815  * is to store a copy of that argument instead of just keeping a
1816  * reference.
1817  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1818  * is exhausted and the system throws in that case (this exception
1819  * will not be thrown if the library has been installed using the
1820  * \--with-glib-memory-slices-no-compat configuration option: instead
1821  * glib will terminate the program if it is unable to obtain memory
1822  * from the operating system). It will also throw if the copy or move
1823  * constructor of a bound argument throws.
1824  *
1825  * Since 2.0.0-rc3
1826  */
1827 template <class T, class BoundArg1, class BoundArg2,
1828  class Arg1, class Arg2, class... FreeArgs>
1829 CallbackArg<FreeArgs...>* make_ref(T& t,
1830  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1831  Arg1&& arg1,
1832  Arg2&& arg2) {
1833  return new Callback2<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
1834  std::forward<Arg1>(arg1),
1835  std::forward<Arg2>(arg2)};
1836 }
1837 
1838 /**
1839  * A convenience function to make Callback::CallbackArg objects
1840  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1841  * is exhausted and the system throws in that case (this exception
1842  * will not be thrown if the library has been installed using the
1843  * \--with-glib-memory-slices-no-compat configuration option: instead
1844  * glib will terminate the program if it is unable to obtain memory
1845  * from the operating system). It will also throw if the copy
1846  * constructor of a bound argument throws and it is not a reference
1847  * argument.
1848  */
1849 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1850 CallbackArg<FreeArgs...>* make(T& t,
1851  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1852  BoundArg1 arg1,
1853  BoundArg2 arg2,
1854  BoundArg3 arg3) {
1855  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
1856 }
1857 
1858 /**
1859  * DEPRECATED: use Callback::make_ref() instead.
1860  *
1861  * An alternative function to make Callback::CallbackArg objects,
1862  * which is for use where a target function receives an argument of
1863  * class type by value which is to be a bound argument, so the
1864  * compiler is not able to carry out copy elision when constructing
1865  * the callback object.
1866  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1867  * is exhausted and the system throws in that case (this exception
1868  * will not be thrown if the library has been installed using the
1869  * \--with-glib-memory-slices-no-compat configuration option: instead
1870  * glib will terminate the program if it is unable to obtain memory
1871  * from the operating system). It will also throw if the copy
1872  * constructor of a bound argument throws and it is not a reference
1873  * argument.
1874  */
1875 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1876 CallbackArg<FreeArgs...>* make_val(T& t,
1877  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1878  const BoundArg1& arg1,
1879  const BoundArg2& arg2,
1880  const BoundArg3& arg3) {
1881  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
1882 }
1883 
1884 /**
1885  * An alternative function to make Callback::CallbackArg objects,
1886  * which is for use where a target function either receives a class
1887  * type bound argument by value, or receives a bound argument by
1888  * reference to const in a case where the generated CallbackArg object
1889  * is to store a copy of that argument instead of just keeping a
1890  * reference.
1891  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1892  * is exhausted and the system throws in that case (this exception
1893  * will not be thrown if the library has been installed using the
1894  * \--with-glib-memory-slices-no-compat configuration option: instead
1895  * glib will terminate the program if it is unable to obtain memory
1896  * from the operating system). It will also throw if the copy or move
1897  * constructor of a bound argument throws.
1898  *
1899  * Since 2.0.0-rc3
1900  */
1901 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1902  class Arg1, class Arg2, class Arg3, class... FreeArgs>
1903 CallbackArg<FreeArgs...>* make_ref(T& t,
1904  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1905  Arg1&& arg1,
1906  Arg2&& arg2,
1907  Arg3&& arg3) {
1908  return new Callback3<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
1909  std::forward<Arg1>(arg1),
1910  std::forward<Arg2>(arg2),
1911  std::forward<Arg3>(arg3)};
1912 }
1913 
1914 /**
1915  * A convenience function to make Callback::CallbackArg objects
1916  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1917  * is exhausted and the system throws in that case (this exception
1918  * will not be thrown if the library has been installed using the
1919  * \--with-glib-memory-slices-no-compat configuration option: instead
1920  * glib will terminate the program if it is unable to obtain memory
1921  * from the operating system). It will also throw if the copy
1922  * constructor of a bound argument throws and it is not a reference
1923  * argument.
1924  */
1925 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1926  class BoundArg4, class... FreeArgs>
1927 CallbackArg<FreeArgs...>* make(T& t,
1928  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1929  BoundArg4, FreeArgs...),
1930  BoundArg1 arg1,
1931  BoundArg2 arg2,
1932  BoundArg3 arg3,
1933  BoundArg4 arg4) {
1934  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
1935  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
1936 }
1937 
1938 /**
1939  * DEPRECATED: use Callback::make_ref() instead.
1940  *
1941  * An alternative function to make Callback::CallbackArg objects,
1942  * which is for use where a target function receives an argument of
1943  * class type by value which is to be a bound argument, so the
1944  * compiler is not able to carry out copy elision when constructing
1945  * the callback object.
1946  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1947  * is exhausted and the system throws in that case (this exception
1948  * will not be thrown if the library has been installed using the
1949  * \--with-glib-memory-slices-no-compat configuration option: instead
1950  * glib will terminate the program if it is unable to obtain memory
1951  * from the operating system). It will also throw if the copy
1952  * constructor of a bound argument throws and it is not a reference
1953  * argument.
1954  */
1955 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1956  class BoundArg4, class... FreeArgs>
1957 CallbackArg<FreeArgs...>* make_val(T& t,
1958  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1959  BoundArg4, FreeArgs...),
1960  const BoundArg1& arg1,
1961  const BoundArg2& arg2,
1962  const BoundArg3& arg3,
1963  const BoundArg4& arg4) {
1964  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
1965  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
1966 }
1967 
1968 /**
1969  * An alternative function to make Callback::CallbackArg objects,
1970  * which is for use where a target function either receives a class
1971  * type bound argument by value, or receives a bound argument by
1972  * reference to const in a case where the generated CallbackArg object
1973  * is to store a copy of that argument instead of just keeping a
1974  * reference.
1975  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1976  * is exhausted and the system throws in that case (this exception
1977  * will not be thrown if the library has been installed using the
1978  * \--with-glib-memory-slices-no-compat configuration option: instead
1979  * glib will terminate the program if it is unable to obtain memory
1980  * from the operating system). It will also throw if the copy or move
1981  * constructor of a bound argument throws.
1982  *
1983  * Since 2.0.0-rc3
1984  */
1985 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1986  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
1987 CallbackArg<FreeArgs...>* make_ref(T& t,
1988  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1989  BoundArg4, FreeArgs...),
1990  Arg1&& arg1,
1991  Arg2&& arg2,
1992  Arg3&& arg3,
1993  Arg4&& arg4) {
1994  return new Callback4<true, T, BoundArg1, BoundArg2, BoundArg3,
1995  BoundArg4, FreeArgs...>{t, func,
1996  std::forward<Arg1>(arg1),
1997  std::forward<Arg2>(arg2),
1998  std::forward<Arg3>(arg3),
1999  std::forward<Arg4>(arg4)};
2000 }
2001 
2002 /**
2003  * A convenience function to make Callback::CallbackArg objects
2004  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2005  * is exhausted and the system throws in that case (this exception
2006  * will not be thrown if the library has been installed using the
2007  * \--with-glib-memory-slices-no-compat configuration option: instead
2008  * glib will terminate the program if it is unable to obtain memory
2009  * from the operating system). It will also throw if the copy
2010  * constructor of a bound argument throws and it is not a reference
2011  * argument.
2012  */
2013 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2014  class BoundArg4, class BoundArg5, class... FreeArgs>
2015 CallbackArg<FreeArgs...>* make(T& t,
2016  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2017  BoundArg4, BoundArg5, FreeArgs...),
2018  BoundArg1 arg1,
2019  BoundArg2 arg2,
2020  BoundArg3 arg3,
2021  BoundArg4 arg4,
2022  BoundArg5 arg5) {
2023  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
2024  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2025 }
2026 
2027 /**
2028  * DEPRECATED: use Callback::make_ref() instead.
2029  *
2030  * An alternative function to make Callback::CallbackArg objects,
2031  * which is for use where a target function receives an argument of
2032  * class type by value which is to be a bound argument, so the
2033  * compiler is not able to carry out copy elision when constructing
2034  * the callback object.
2035  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2036  * is exhausted and the system throws in that case (this exception
2037  * will not be thrown if the library has been installed using the
2038  * \--with-glib-memory-slices-no-compat configuration option: instead
2039  * glib will terminate the program if it is unable to obtain memory
2040  * from the operating system). It will also throw if the copy
2041  * constructor of a bound argument throws and it is not a reference
2042  * argument.
2043  */
2044 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2045  class BoundArg4, class BoundArg5, class... FreeArgs>
2046 CallbackArg<FreeArgs...>* make_val(T& t,
2047  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2048  BoundArg4, BoundArg5, FreeArgs...),
2049  const BoundArg1& arg1,
2050  const BoundArg2& arg2,
2051  const BoundArg3& arg3,
2052  const BoundArg4& arg4,
2053  const BoundArg5& arg5) {
2054  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
2055  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2056 }
2057 
2058 /**
2059  * An alternative function to make Callback::CallbackArg objects,
2060  * which is for use where a target function either receives a class
2061  * type bound argument by value, or receives a bound argument by
2062  * reference to const in a case where the generated CallbackArg object
2063  * is to store a copy of that argument instead of just keeping a
2064  * reference.
2065  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2066  * is exhausted and the system throws in that case (this exception
2067  * will not be thrown if the library has been installed using the
2068  * \--with-glib-memory-slices-no-compat configuration option: instead
2069  * glib will terminate the program if it is unable to obtain memory
2070  * from the operating system). It will also throw if the copy or move
2071  * constructor of a bound argument throws.
2072  *
2073  * Since 2.0.0-rc3
2074  */
2075 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2076  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2077 CallbackArg<FreeArgs...>* make_ref(T& t,
2078  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2079  BoundArg4, BoundArg5, FreeArgs...),
2080  Arg1&& arg1,
2081  Arg2&& arg2,
2082  Arg3&& arg3,
2083  Arg4&& arg4,
2084  Arg5&& arg5) {
2085  return new Callback5<true, T, BoundArg1, BoundArg2, BoundArg3,
2086  BoundArg4, BoundArg5, FreeArgs...>{t, func,
2087  std::forward<Arg1>(arg1),
2088  std::forward<Arg2>(arg2),
2089  std::forward<Arg3>(arg3),
2090  std::forward<Arg4>(arg4),
2091  std::forward<Arg5>(arg5)};
2092 }
2093 
2094 /* const versions, for binding to const methods */
2095 
2096 /**
2097  * A convenience function to make Callback::CallbackArg objects
2098  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2099  * is exhausted and the system throws in that case. This exception
2100  * will not be thrown if the library has been installed using the
2101  * \--with-glib-memory-slices-no-compat configuration option (instead
2102  * glib will terminate the program if it is unable to obtain memory
2103  * from the operating system).
2104  */
2105 template <class T, class... FreeArgs>
2106 CallbackArg<FreeArgs...>* make(const T& t,
2107  void (T::*func)(FreeArgs...) const) {
2108  return new Callback0_const<T, FreeArgs...>{t, func};
2109 }
2110 
2111 /**
2112  * DEPRECATED.
2113  *
2114  * Since this function constructs a callback which does not take a
2115  * bound argument, it is a synonym for make() (the two are identical).
2116  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2117  * is exhausted and the system throws in that case. This exception
2118  * will not be thrown if the library has been installed using the
2119  * \--with-glib-memory-slices-no-compat configuration option (instead
2120  * glib will terminate the program if it is unable to obtain memory
2121  * from the operating system).
2122  */
2123 template <class T, class... FreeArgs>
2124 CallbackArg<FreeArgs...>* make_val(const T& t,
2125  void (T::*func)(FreeArgs...) const) {
2126  return new Callback0_const<T, FreeArgs...>{t, func};
2127 }
2128 
2129 /**
2130  * Since this function constructs a callback which does not take a
2131  * bound argument, it is a synonym for make() (the two are identical).
2132  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2133  * is exhausted and the system throws in that case. This exception
2134  * will not be thrown if the library has been installed using the
2135  * \--with-glib-memory-slices-no-compat configuration option (instead
2136  * glib will terminate the program if it is unable to obtain memory
2137  * from the operating system).
2138  *
2139  * Since 2.0.0-rc3
2140  */
2141 template <class T, class... FreeArgs>
2142 CallbackArg<FreeArgs...>* make_ref(const T& t,
2143  void (T::*func)(FreeArgs...) const) {
2144  return new Callback0_const<T, FreeArgs...>{t, func};
2145 }
2146 
2147 /**
2148  * A convenience function to make Callback::CallbackArg objects
2149  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2150  * is exhausted and the system throws in that case (this exception
2151  * will not be thrown if the library has been installed using the
2152  * \--with-glib-memory-slices-no-compat configuration option: instead
2153  * glib will terminate the program if it is unable to obtain memory
2154  * from the operating system). It will also throw if the copy
2155  * constructor of a bound argument throws and it is not a reference
2156  * argument.
2157  */
2158 template <class T, class BoundArg, class... FreeArgs>
2159 CallbackArg<FreeArgs...>* make(const T& t,
2160  void (T::*func)(BoundArg, FreeArgs...) const,
2161  BoundArg arg) {
2162  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
2163 }
2164 
2165 /**
2166  * DEPRECATED: use Callback::make_ref() instead.
2167  *
2168  * An alternative function to make Callback::CallbackArg objects,
2169  * which is for use where a target function receives an argument of
2170  * class type by value which is to be a bound argument, so the
2171  * compiler is not able to carry out copy elision when constructing
2172  * the callback object.
2173  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2174  * is exhausted and the system throws in that case (this exception
2175  * will not be thrown if the library has been installed using the
2176  * \--with-glib-memory-slices-no-compat configuration option: instead
2177  * glib will terminate the program if it is unable to obtain memory
2178  * from the operating system). It will also throw if the copy
2179  * constructor of a bound argument throws and it is not a reference
2180  * argument.
2181  */
2182 template <class T, class BoundArg, class... FreeArgs>
2183 CallbackArg<FreeArgs...>* make_val(const T& t,
2184  void (T::*func)(BoundArg, FreeArgs...) const,
2185  const BoundArg& arg) {
2186  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
2187 }
2188 
2189 /**
2190  * An alternative function to make Callback::CallbackArg objects,
2191  * which is for use where a target function either receives a class
2192  * type bound argument by value, or receives a bound argument by
2193  * reference to const in a case where the generated CallbackArg object
2194  * is to store a copy of that argument instead of just keeping a
2195  * reference.
2196  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2197  * is exhausted and the system throws in that case (this exception
2198  * will not be thrown if the library has been installed using the
2199  * \--with-glib-memory-slices-no-compat configuration option: instead
2200  * glib will terminate the program if it is unable to obtain memory
2201  * from the operating system). It will also throw if the copy or move
2202  * constructor of a bound argument throws.
2203  *
2204  * Since 2.0.0-rc3
2205  */
2206 template <class T, class BoundArg, class Arg, class... FreeArgs>
2207 CallbackArg<FreeArgs...>* make_ref(const T& t,
2208  void (T::*func)(BoundArg, FreeArgs...) const,
2209  Arg&& arg) {
2210  return new Callback1_const<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
2211 }
2212 
2213 /**
2214  * A convenience function to make Callback::CallbackArg objects
2215  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2216  * is exhausted and the system throws in that case (this exception
2217  * will not be thrown if the library has been installed using the
2218  * \--with-glib-memory-slices-no-compat configuration option: instead
2219  * glib will terminate the program if it is unable to obtain memory
2220  * from the operating system). It will also throw if the copy
2221  * constructor of a bound argument throws and it is not a reference
2222  * argument.
2223  */
2224 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
2225 CallbackArg<FreeArgs...>* make(const T& t,
2226  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2227  BoundArg1 arg1,
2228  BoundArg2 arg2) {
2229  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
2230 }
2231 
2232 /**
2233  * DEPRECATED: use Callback::make_ref() instead.
2234  *
2235  * An alternative function to make Callback::CallbackArg objects,
2236  * which is for use where a target function receives an argument of
2237  * class type by value which is to be a bound argument, so the
2238  * compiler is not able to carry out copy elision when constructing
2239  * the callback object.
2240  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2241  * is exhausted and the system throws in that case (this exception
2242  * will not be thrown if the library has been installed using the
2243  * \--with-glib-memory-slices-no-compat configuration option: instead
2244  * glib will terminate the program if it is unable to obtain memory
2245  * from the operating system). It will also throw if the copy
2246  * constructor of a bound argument throws and it is not a reference
2247  * argument.
2248  */
2249 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
2250 CallbackArg<FreeArgs...>* make_val(const T& t,
2251  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2252  const BoundArg1& arg1,
2253  const BoundArg2& arg2) {
2254  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
2255 }
2256 
2257 /**
2258  * An alternative function to make Callback::CallbackArg objects,
2259  * which is for use where a target function either receives a class
2260  * type bound argument by value, or receives a bound argument by
2261  * reference to const in a case where the generated CallbackArg object
2262  * is to store a copy of that argument instead of just keeping a
2263  * reference.
2264  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2265  * is exhausted and the system throws in that case (this exception
2266  * will not be thrown if the library has been installed using the
2267  * \--with-glib-memory-slices-no-compat configuration option: instead
2268  * glib will terminate the program if it is unable to obtain memory
2269  * from the operating system). It will also throw if the copy or move
2270  * constructor of a bound argument throws.
2271  *
2272  * Since 2.0.0-rc3
2273  */
2274 template <class T, class BoundArg1, class BoundArg2,
2275  class Arg1, class Arg2, class... FreeArgs>
2276 CallbackArg<FreeArgs...>* make_ref(const T& t,
2277  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2278  Arg1&& arg1,
2279  Arg2&& arg2) {
2280  return new Callback2_const<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
2281  std::forward<Arg1>(arg1),
2282  std::forward<Arg2>(arg2)};
2283 }
2284 
2285 /**
2286  * A convenience function to make Callback::CallbackArg objects
2287  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2288  * is exhausted and the system throws in that case (this exception
2289  * will not be thrown if the library has been installed using the
2290  * \--with-glib-memory-slices-no-compat configuration option: instead
2291  * glib will terminate the program if it is unable to obtain memory
2292  * from the operating system). It will also throw if the copy
2293  * constructor of a bound argument throws and it is not a reference
2294  * argument.
2295  */
2296 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2297 CallbackArg<FreeArgs...>* make(const T& t,
2298  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2299  BoundArg1 arg1,
2300  BoundArg2 arg2,
2301  BoundArg3 arg3) {
2302  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
2303 }
2304 
2305 /**
2306  * DEPRECATED: use Callback::make_ref() instead.
2307  *
2308  * An alternative function to make Callback::CallbackArg objects,
2309  * which is for use where a target function receives an argument of
2310  * class type by value which is to be a bound argument, so the
2311  * compiler is not able to carry out copy elision when constructing
2312  * the callback object.
2313  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2314  * is exhausted and the system throws in that case (this exception
2315  * will not be thrown if the library has been installed using the
2316  * \--with-glib-memory-slices-no-compat configuration option: instead
2317  * glib will terminate the program if it is unable to obtain memory
2318  * from the operating system). It will also throw if the copy
2319  * constructor of a bound argument throws and it is not a reference
2320  * argument.
2321  */
2322 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2323 CallbackArg<FreeArgs...>* make_val(const T& t,
2324  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2325  const BoundArg1& arg1,
2326  const BoundArg2& arg2,
2327  const BoundArg3& arg3) {
2328  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
2329 }
2330 
2331 /**
2332  * An alternative function to make Callback::CallbackArg objects,
2333  * which is for use where a target function either receives a class
2334  * type bound argument by value, or receives a bound argument by
2335  * reference to const in a case where the generated CallbackArg object
2336  * is to store a copy of that argument instead of just keeping a
2337  * reference.
2338  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2339  * is exhausted and the system throws in that case (this exception
2340  * will not be thrown if the library has been installed using the
2341  * \--with-glib-memory-slices-no-compat configuration option: instead
2342  * glib will terminate the program if it is unable to obtain memory
2343  * from the operating system). It will also throw if the copy or move
2344  * constructor of a bound argument throws.
2345  *
2346  * Since 2.0.0-rc3
2347  */
2348 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2349  class Arg1, class Arg2, class Arg3, class... FreeArgs>
2350 CallbackArg<FreeArgs...>* make_ref(const T& t,
2351  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2352  Arg1&& arg1,
2353  Arg2&& arg2,
2354  Arg3&& arg3) {
2355  return new Callback3_const<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
2356  std::forward<Arg1>(arg1),
2357  std::forward<Arg2>(arg2),
2358  std::forward<Arg3>(arg3)};
2359 }
2360 
2361 /**
2362  * A convenience function to make Callback::CallbackArg objects
2363  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2364  * is exhausted and the system throws in that case (this exception
2365  * will not be thrown if the library has been installed using the
2366  * \--with-glib-memory-slices-no-compat configuration option: instead
2367  * glib will terminate the program if it is unable to obtain memory
2368  * from the operating system). It will also throw if the copy
2369  * constructor of a bound argument throws and it is not a reference
2370  * argument.
2371  */
2372 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2373  class BoundArg4, class... FreeArgs>
2374 CallbackArg<FreeArgs...>* make(const T& t,
2375  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2376  BoundArg4, FreeArgs...) const,
2377  BoundArg1 arg1,
2378  BoundArg2 arg2,
2379  BoundArg3 arg3,
2380  BoundArg4 arg4) {
2381  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2382  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
2383 }
2384 
2385 /**
2386  * DEPRECATED: use Callback::make_ref() instead.
2387  *
2388  * An alternative function to make Callback::CallbackArg objects,
2389  * which is for use where a target function receives an argument of
2390  * class type by value which is to be a bound argument, so the
2391  * compiler is not able to carry out copy elision when constructing
2392  * the callback object.
2393  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2394  * is exhausted and the system throws in that case (this exception
2395  * will not be thrown if the library has been installed using the
2396  * \--with-glib-memory-slices-no-compat configuration option: instead
2397  * glib will terminate the program if it is unable to obtain memory
2398  * from the operating system). It will also throw if the copy
2399  * constructor of a bound argument throws and it is not a reference
2400  * argument.
2401  */
2402 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2403  class BoundArg4, class... FreeArgs>
2404 CallbackArg<FreeArgs...>* make_val(const T& t,
2405  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2406  BoundArg4, FreeArgs...) const,
2407  const BoundArg1& arg1,
2408  const BoundArg2& arg2,
2409  const BoundArg3& arg3,
2410  const BoundArg4& arg4) {
2411  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2412  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
2413 }
2414 
2415 /**
2416  * An alternative function to make Callback::CallbackArg objects,
2417  * which is for use where a target function either receives a class
2418  * type bound argument by value, or receives a bound argument by
2419  * reference to const in a case where the generated CallbackArg object
2420  * is to store a copy of that argument instead of just keeping a
2421  * reference.
2422  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2423  * is exhausted and the system throws in that case (this exception
2424  * will not be thrown if the library has been installed using the
2425  * \--with-glib-memory-slices-no-compat configuration option: instead
2426  * glib will terminate the program if it is unable to obtain memory
2427  * from the operating system). It will also throw if the copy or move
2428  * constructor of a bound argument throws.
2429  *
2430  * Since 2.0.0-rc3
2431  */
2432 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2433  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
2434 CallbackArg<FreeArgs...>* make_ref(const T& t,
2435  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2436  BoundArg4, FreeArgs...) const,
2437  Arg1&& arg1,
2438  Arg2&& arg2,
2439  Arg3&& arg3,
2440  Arg4&& arg4) {
2441  return new Callback4_const<true, T, BoundArg1, BoundArg2, BoundArg3,
2442  BoundArg4, FreeArgs...>{t, func,
2443  std::forward<Arg1>(arg1),
2444  std::forward<Arg2>(arg2),
2445  std::forward<Arg3>(arg3),
2446  std::forward<Arg4>(arg4)};
2447 }
2448 
2449 /**
2450  * A convenience function to make Callback::CallbackArg objects
2451  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2452  * is exhausted and the system throws in that case (this exception
2453  * will not be thrown if the library has been installed using the
2454  * \--with-glib-memory-slices-no-compat configuration option: instead
2455  * glib will terminate the program if it is unable to obtain memory
2456  * from the operating system). It will also throw if the copy
2457  * constructor of a bound argument throws and it is not a reference
2458  * argument.
2459  */
2460 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2461  class BoundArg4, class BoundArg5, class... FreeArgs>
2462 CallbackArg<FreeArgs...>* make(const T& t,
2463  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2464  BoundArg4, BoundArg5, FreeArgs...) const,
2465  BoundArg1 arg1,
2466  BoundArg2 arg2,
2467  BoundArg3 arg3,
2468  BoundArg4 arg4,
2469  BoundArg5 arg5) {
2470  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2471  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2472 }
2473 
2474 /**
2475  * DEPRECATED: use Callback::make_ref() instead.
2476  *
2477  * An alternative function to make Callback::CallbackArg objects,
2478  * which is for use where a target function receives an argument of
2479  * class type by value which is to be a bound argument, so the
2480  * compiler is not able to carry out copy elision when constructing
2481  * the callback object.
2482  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2483  * is exhausted and the system throws in that case (this exception
2484  * will not be thrown if the library has been installed using the
2485  * \--with-glib-memory-slices-no-compat configuration option: instead
2486  * glib will terminate the program if it is unable to obtain memory
2487  * from the operating system). It will also throw if the copy
2488  * constructor of a bound argument throws and it is not a reference
2489  * argument.
2490  */
2491 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2492  class BoundArg4, class BoundArg5, class... FreeArgs>
2493 CallbackArg<FreeArgs...>* make_val(const T& t,
2494  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2495  BoundArg4, BoundArg5, FreeArgs...) const,
2496  const BoundArg1& arg1,
2497  const BoundArg2& arg2,
2498  const BoundArg3& arg3,
2499  const BoundArg4& arg4,
2500  const BoundArg5& arg5) {
2501  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2502  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2503 }
2504 
2505 /**
2506  * An alternative function to make Callback::CallbackArg objects,
2507  * which is for use where a target function either receives a class
2508  * type bound argument by value, or receives a bound argument by
2509  * reference to const in a case where the generated CallbackArg object
2510  * is to store a copy of that argument instead of just keeping a
2511  * reference.
2512  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2513  * is exhausted and the system throws in that case (this exception
2514  * will not be thrown if the library has been installed using the
2515  * \--with-glib-memory-slices-no-compat configuration option: instead
2516  * glib will terminate the program if it is unable to obtain memory
2517  * from the operating system). It will also throw if the copy or move
2518  * constructor of a bound argument throws.
2519  *
2520  * Since 2.0.0-rc3
2521  */
2522 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2523  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2524 CallbackArg<FreeArgs...>* make_ref(const T& t,
2525  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2526  BoundArg4, BoundArg5, FreeArgs...) const,
2527  Arg1&& arg1,
2528  Arg2&& arg2,
2529  Arg3&& arg3,
2530  Arg4&& arg4,
2531  Arg5&& arg5) {
2532  return new Callback5_const<true, T, BoundArg1, BoundArg2, BoundArg3,
2533  BoundArg4, BoundArg5, FreeArgs...>{t, func,
2534  std::forward<Arg1>(arg1),
2535  std::forward<Arg2>(arg2),
2536  std::forward<Arg3>(arg3),
2537  std::forward<Arg4>(arg4),
2538  std::forward<Arg5>(arg5)};
2539 }
2540 
2541 /* for static class methods and non-class functions */
2542 
2543 /**
2544  * A convenience function to make Callback::CallbackArg objects
2545  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2546  * is exhausted and the system throws in that case. This exception
2547  * will not be thrown if the library has been installed using the
2548  * \--with-glib-memory-slices-no-compat configuration option (instead
2549  * glib will terminate the program if it is unable to obtain memory
2550  * from the operating system).
2551  */
2552 template <class... FreeArgs>
2553 CallbackArg<FreeArgs...>* make(void (*func)(FreeArgs...)) {
2554  return new Callback0_static<FreeArgs...>{func};
2555 }
2556 
2557 /**
2558  * DEPRECATED.
2559  *
2560  * Since this function constructs a callback which does not take a
2561  * bound argument, it is a synonym for make() (the two are identical).
2562  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2563  * is exhausted and the system throws in that case. This exception
2564  * will not be thrown if the library has been installed using the
2565  * \--with-glib-memory-slices-no-compat configuration option (instead
2566  * glib will terminate the program if it is unable to obtain memory
2567  * from the operating system).
2568  */
2569 template <class... FreeArgs>
2570 CallbackArg<FreeArgs...>* make_val(void (*func)(FreeArgs...)) {
2571  return new Callback0_static<FreeArgs...>{func};
2572 }
2573 
2574 /**
2575  * Since this function constructs a callback which does not take a
2576  * bound argument, it is a synonym for make() (the two are identical).
2577  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2578  * is exhausted and the system throws in that case. This exception
2579  * will not be thrown if the library has been installed using the
2580  * \--with-glib-memory-slices-no-compat configuration option (instead
2581  * glib will terminate the program if it is unable to obtain memory
2582  * from the operating system).
2583  *
2584  * Since 2.0.0-rc3
2585  */
2586 template <class... FreeArgs>
2587 CallbackArg<FreeArgs...>* make_ref(void (*func)(FreeArgs...)) {
2588  return new Callback0_static<FreeArgs...>{func};
2589 }
2590 
2591 /**
2592  * A convenience function to make Callback::CallbackArg objects
2593  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2594  * is exhausted and the system throws in that case (this exception
2595  * will not be thrown if the library has been installed using the
2596  * \--with-glib-memory-slices-no-compat configuration option: instead
2597  * glib will terminate the program if it is unable to obtain memory
2598  * from the operating system). It will also throw if the copy
2599  * constructor of a bound argument throws and it is not a reference
2600  * argument.
2601  */
2602 template <class BoundArg, class... FreeArgs>
2603 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg, FreeArgs...),
2604  BoundArg arg) {
2605  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
2606 }
2607 
2608 /**
2609  * DEPRECATED: use Callback::make_ref() instead.
2610  *
2611  * An alternative function to make Callback::CallbackArg objects,
2612  * which is for use where a target function receives an argument of
2613  * class type by value which is to be a bound argument, so the
2614  * compiler is not able to carry out copy elision when constructing
2615  * the callback object.
2616  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2617  * is exhausted and the system throws in that case (this exception
2618  * will not be thrown if the library has been installed using the
2619  * \--with-glib-memory-slices-no-compat configuration option: instead
2620  * glib will terminate the program if it is unable to obtain memory
2621  * from the operating system). It will also throw if the copy
2622  * constructor of a bound argument throws and it is not a reference
2623  * argument.
2624  */
2625 template <class BoundArg, class... FreeArgs>
2626 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg, FreeArgs...),
2627  const BoundArg& arg) {
2628  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
2629 }
2630 
2631 /**
2632  * An alternative function to make Callback::CallbackArg objects,
2633  * which is for use where a target function either receives a class
2634  * type bound argument by value, or receives a bound argument by
2635  * reference to const in a case where the generated CallbackArg object
2636  * is to store a copy of that argument instead of just keeping a
2637  * reference.
2638  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2639  * is exhausted and the system throws in that case (this exception
2640  * will not be thrown if the library has been installed using the
2641  * \--with-glib-memory-slices-no-compat configuration option: instead
2642  * glib will terminate the program if it is unable to obtain memory
2643  * from the operating system). It will also throw if the copy or move
2644  * constructor of a bound argument throws.
2645  *
2646  * Since 2.0.0-rc3
2647  */
2648 template <class BoundArg, class Arg, class... FreeArgs>
2649 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg, FreeArgs...),
2650  Arg&& arg) {
2651  return new Callback1_static<true, BoundArg, FreeArgs...>{func, std::forward<Arg>(arg)};
2652 }
2653 
2654 /**
2655  * A convenience function to make Callback::CallbackArg objects
2656  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2657  * is exhausted and the system throws in that case (this exception
2658  * will not be thrown if the library has been installed using the
2659  * \--with-glib-memory-slices-no-compat configuration option: instead
2660  * glib will terminate the program if it is unable to obtain memory
2661  * from the operating system). It will also throw if the copy
2662  * constructor of a bound argument throws and it is not a reference
2663  * argument.
2664  */
2665 template <class BoundArg1, class BoundArg2, class... FreeArgs>
2666 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2667  BoundArg1 arg1,
2668  BoundArg2 arg2) {
2669  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
2670 }
2671 
2672 /**
2673  * DEPRECATED: use Callback::make_ref() instead.
2674  *
2675  * An alternative function to make Callback::CallbackArg objects,
2676  * which is for use where a target function receives an argument of
2677  * class type by value which is to be a bound argument, so the
2678  * compiler is not able to carry out copy elision when constructing
2679  * the callback object.
2680  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2681  * is exhausted and the system throws in that case (this exception
2682  * will not be thrown if the library has been installed using the
2683  * \--with-glib-memory-slices-no-compat configuration option: instead
2684  * glib will terminate the program if it is unable to obtain memory
2685  * from the operating system). It will also throw if the copy
2686  * constructor of a bound argument throws and it is not a reference
2687  * argument.
2688  */
2689 template <class BoundArg1, class BoundArg2, class... FreeArgs>
2690 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2691  const BoundArg1& arg1,
2692  const BoundArg2& arg2) {
2693  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
2694 }
2695 
2696 /**
2697  * An alternative function to make Callback::CallbackArg objects,
2698  * which is for use where a target function either receives a class
2699  * type bound argument by value, or receives a bound argument by
2700  * reference to const in a case where the generated CallbackArg object
2701  * is to store a copy of that argument instead of just keeping a
2702  * reference.
2703  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2704  * is exhausted and the system throws in that case (this exception
2705  * will not be thrown if the library has been installed using the
2706  * \--with-glib-memory-slices-no-compat configuration option: instead
2707  * glib will terminate the program if it is unable to obtain memory
2708  * from the operating system). It will also throw if the copy or move
2709  * constructor of a bound argument throws.
2710  *
2711  * Since 2.0.0-rc3
2712  */
2713 template <class BoundArg1, class BoundArg2, class Arg1, class Arg2, class... FreeArgs>
2714 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2715  Arg1&& arg1,
2716  Arg2&& arg2) {
2717  return new Callback2_static<true, BoundArg1, BoundArg2, FreeArgs...>{func,
2718  std::forward<Arg1>(arg1),
2719  std::forward<Arg2>(arg2)};
2720 }
2721 
2722 /**
2723  * A convenience function to make Callback::CallbackArg objects
2724  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2725  * is exhausted and the system throws in that case (this exception
2726  * will not be thrown if the library has been installed using the
2727  * \--with-glib-memory-slices-no-compat configuration option: instead
2728  * glib will terminate the program if it is unable to obtain memory
2729  * from the operating system). It will also throw if the copy
2730  * constructor of a bound argument throws and it is not a reference
2731  * argument.
2732  */
2733 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2734 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2735  BoundArg1 arg1,
2736  BoundArg2 arg2,
2737  BoundArg3 arg3) {
2738  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
2739 }
2740 
2741 /**
2742  * DEPRECATED: use Callback::make_ref() instead.
2743  *
2744  * An alternative function to make Callback::CallbackArg objects,
2745  * which is for use where a target function receives an argument of
2746  * class type by value which is to be a bound argument, so the
2747  * compiler is not able to carry out copy elision when constructing
2748  * the callback object.
2749  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2750  * is exhausted and the system throws in that case (this exception
2751  * will not be thrown if the library has been installed using the
2752  * \--with-glib-memory-slices-no-compat configuration option: instead
2753  * glib will terminate the program if it is unable to obtain memory
2754  * from the operating system). It will also throw if the copy
2755  * constructor of a bound argument throws and it is not a reference
2756  * argument.
2757  */
2758 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2759 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2760  const BoundArg1& arg1,
2761  const BoundArg2& arg2,
2762  const BoundArg3& arg3) {
2763  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
2764 }
2765 
2766 /**
2767  * An alternative function to make Callback::CallbackArg objects,
2768  * which is for use where a target function either receives a class
2769  * type bound argument by value, or receives a bound argument by
2770  * reference to const in a case where the generated CallbackArg object
2771  * is to store a copy of that argument instead of just keeping a
2772  * reference.
2773  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2774  * is exhausted and the system throws in that case (this exception
2775  * will not be thrown if the library has been installed using the
2776  * \--with-glib-memory-slices-no-compat configuration option: instead
2777  * glib will terminate the program if it is unable to obtain memory
2778  * from the operating system). It will also throw if the copy or move
2779  * constructor of a bound argument throws.
2780  *
2781  * Since 2.0.0-rc3
2782  */
2783 template <class BoundArg1, class BoundArg2, class BoundArg3,
2784  class Arg1, class Arg2, class Arg3, class... FreeArgs>
2785 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2786  Arg1&& arg1,
2787  Arg2&& arg2,
2788  Arg3&& arg3) {
2789  return new Callback3_static<true, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func,
2790  std::forward<Arg1>(arg1),
2791  std::forward<Arg2>(arg2),
2792  std::forward<Arg3>(arg3)};
2793 }
2794 
2795 /**
2796  * A convenience function to make Callback::CallbackArg objects
2797  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2798  * is exhausted and the system throws in that case (this exception
2799  * will not be thrown if the library has been installed using the
2800  * \--with-glib-memory-slices-no-compat configuration option: instead
2801  * glib will terminate the program if it is unable to obtain memory
2802  * from the operating system). It will also throw if the copy
2803  * constructor of a bound argument throws and it is not a reference
2804  * argument.
2805  */
2806 template <class BoundArg1, class BoundArg2, class BoundArg3,
2807  class BoundArg4, class... FreeArgs>
2808 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2809  BoundArg4, FreeArgs...),
2810  BoundArg1 arg1,
2811  BoundArg2 arg2,
2812  BoundArg3 arg3,
2813  BoundArg4 arg4) {
2814  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
2815  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
2816 }
2817 
2818 /**
2819  * DEPRECATED: use Callback::make_ref() instead.
2820  *
2821  * An alternative function to make Callback::CallbackArg objects,
2822  * which is for use where a target function receives an argument of
2823  * class type by value which is to be a bound argument, so the
2824  * compiler is not able to carry out copy elision when constructing
2825  * the callback object.
2826  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2827  * is exhausted and the system throws in that case (this exception
2828  * will not be thrown if the library has been installed using the
2829  * \--with-glib-memory-slices-no-compat configuration option: instead
2830  * glib will terminate the program if it is unable to obtain memory
2831  * from the operating system). It will also throw if the copy
2832  * constructor of a bound argument throws and it is not a reference
2833  * argument.
2834  */
2835 template <class BoundArg1, class BoundArg2, class BoundArg3,
2836  class BoundArg4, class... FreeArgs>
2837 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2838  BoundArg4, FreeArgs...),
2839  const BoundArg1& arg1,
2840  const BoundArg2& arg2,
2841  const BoundArg3& arg3,
2842  const BoundArg4& arg4) {
2843  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
2844  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
2845 }
2846 
2847 /**
2848  * An alternative function to make Callback::CallbackArg objects,
2849  * which is for use where a target function either receives a class
2850  * type bound argument by value, or receives a bound argument by
2851  * reference to const in a case where the generated CallbackArg object
2852  * is to store a copy of that argument instead of just keeping a
2853  * reference.
2854  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2855  * is exhausted and the system throws in that case (this exception
2856  * will not be thrown if the library has been installed using the
2857  * \--with-glib-memory-slices-no-compat configuration option: instead
2858  * glib will terminate the program if it is unable to obtain memory
2859  * from the operating system). It will also throw if the copy or move
2860  * constructor of a bound argument throws.
2861  *
2862  * Since 2.0.0-rc3
2863  */
2864 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2865  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
2866 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2867  BoundArg4, FreeArgs...),
2868  Arg1&& arg1,
2869  Arg2&& arg2,
2870  Arg3&& arg3,
2871  Arg4&& arg4) {
2872  return new Callback4_static<true, BoundArg1, BoundArg2, BoundArg3,
2873  BoundArg4, FreeArgs...>{func,
2874  std::forward<Arg1>(arg1),
2875  std::forward<Arg2>(arg2),
2876  std::forward<Arg3>(arg3),
2877  std::forward<Arg4>(arg4)};
2878 }
2879 
2880 /**
2881  * A convenience function to make Callback::CallbackArg objects
2882  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2883  * is exhausted and the system throws in that case (this exception
2884  * will not be thrown if the library has been installed using the
2885  * \--with-glib-memory-slices-no-compat configuration option: instead
2886  * glib will terminate the program if it is unable to obtain memory
2887  * from the operating system). It will also throw if the copy
2888  * constructor of a bound argument throws and it is not a reference
2889  * argument.
2890  */
2891 template <class BoundArg1, class BoundArg2, class BoundArg3,
2892  class BoundArg4, class BoundArg5, class... FreeArgs>
2893 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2894  BoundArg4, BoundArg5, FreeArgs...),
2895  BoundArg1 arg1,
2896  BoundArg2 arg2,
2897  BoundArg3 arg3,
2898  BoundArg4 arg4,
2899  BoundArg5 arg5) {
2900  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
2901  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
2902 }
2903 
2904 /**
2905  * DEPRECATED: use Callback::make_ref() instead.
2906  *
2907  * An alternative function to make Callback::CallbackArg objects,
2908  * which is for use where a target function receives an argument of
2909  * class type by value which is to be a bound argument, so the
2910  * compiler is not able to carry out copy elision when constructing
2911  * the callback object.
2912  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2913  * is exhausted and the system throws in that case (this exception
2914  * will not be thrown if the library has been installed using the
2915  * \--with-glib-memory-slices-no-compat configuration option: instead
2916  * glib will terminate the program if it is unable to obtain memory
2917  * from the operating system). It will also throw if the copy
2918  * constructor of a bound argument throws and it is not a reference
2919  * argument.
2920  */
2921 template <class BoundArg1, class BoundArg2, class BoundArg3,
2922  class BoundArg4, class BoundArg5, class... FreeArgs>
2923 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2924  BoundArg4, BoundArg5, FreeArgs...),
2925  const BoundArg1& arg1,
2926  const BoundArg2& arg2,
2927  const BoundArg3& arg3,
2928  const BoundArg4& arg4,
2929  const BoundArg5& arg5) {
2930  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
2931  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
2932 }
2933 
2934 /**
2935  * An alternative function to make Callback::CallbackArg objects,
2936  * which is for use where a target function either receives a class
2937  * type bound argument by value, or receives a bound argument by
2938  * reference to const in a case where the generated CallbackArg object
2939  * is to store a copy of that argument instead of just keeping a
2940  * reference.
2941  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2942  * is exhausted and the system throws in that case (this exception
2943  * will not be thrown if the library has been installed using the
2944  * \--with-glib-memory-slices-no-compat configuration option: instead
2945  * glib will terminate the program if it is unable to obtain memory
2946  * from the operating system). It will also throw if the copy or move
2947  * constructor of a bound argument throws.
2948  *
2949  * Since 2.0.0-rc3
2950  */
2951 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2952  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2953 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2954  BoundArg4, BoundArg5, FreeArgs...),
2955  Arg1&& arg1,
2956  Arg2&& arg2,
2957  Arg3&& arg3,
2958  Arg4&& arg4,
2959  Arg5&& arg5) {
2960  return new Callback5_static<true, BoundArg1, BoundArg2, BoundArg3,
2961  BoundArg4, BoundArg5, FreeArgs...>{func,
2962  std::forward<Arg1>(arg1),
2963  std::forward<Arg2>(arg2),
2964  std::forward<Arg3>(arg3),
2965  std::forward<Arg4>(arg4),
2966  std::forward<Arg5>(arg5)};
2967 }
2968 
2969 /* for std::function objects */
2970 
2971 /**
2972  * A convenience function to make Callback::CallbackArg objects from
2973  * std::function objects.
2974  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2975  * is exhausted and the system throws in that case (this exception
2976  * will not be thrown if the library has been installed using the
2977  * \--with-glib-memory-slices-no-compat configuration option: instead
2978  * glib will terminate the program if it is unable to obtain memory
2979  * from the operating system). It will also throw if the copy
2980  * constructor of a bound argument throws and it is not a reference
2981  * argument.
2982  */
2983 template <class... FreeArgs>
2984 CallbackArg<FreeArgs...>* make(const std::function<void(FreeArgs...)>& f) {
2985  return new Callback_function<FreeArgs...>{f};
2986 }
2987 
2988 /**
2989  * DEPRECATED.
2990  *
2991  * A convenience function to make Callback::Callback objects from
2992  * std::function objects. Since this function takes no bound argument
2993  * (and bound arguments are bound into the std::function object), it
2994  * is a synonym for make() (the two are identical).
2995  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2996  * is exhausted and the system throws in that case (this exception
2997  * will not be thrown if the library has been installed using the
2998  * \--with-glib-memory-slices-no-compat configuration option: instead
2999  * glib will terminate the program if it is unable to obtain memory
3000  * from the operating system). It will also throw if the copy
3001  * constructor of a bound argument throws and it is not a reference
3002  * argument.
3003  */
3004 template <class... FreeArgs>
3005 CallbackArg<FreeArgs...>* make_val(const std::function<void(FreeArgs...)>& f) {
3006  return new Callback_function<FreeArgs...>{f};
3007 }
3008 
3009 /**
3010  * A convenience function to make Callback::Callback objects from
3011  * std::function objects. Since this function takes no bound argument
3012  * (and bound arguments are bound into the std::function object), it
3013  * is a synonym for make() (the two are identical).
3014  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3015  * is exhausted and the system throws in that case (this exception
3016  * will not be thrown if the library has been installed using the
3017  * \--with-glib-memory-slices-no-compat configuration option: instead
3018  * glib will terminate the program if it is unable to obtain memory
3019  * from the operating system). It will also throw if the copy
3020  * constructor of a bound argument throws and it is not a reference
3021  * argument.
3022  */
3023 template <class... FreeArgs>
3024 CallbackArg<FreeArgs...>* make_ref(const std::function<void(FreeArgs...)>& f) {
3025  return new Callback_function<FreeArgs...>{f};
3026 }
3027 
3028 /**
3029  * A convenience function to make Callback::CallbackArg objects from
3030  * std::function objects.
3031  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3032  * is exhausted and the system throws in that case (this exception
3033  * will not be thrown if the library has been installed using the
3034  * \--with-glib-memory-slices-no-compat configuration option: instead
3035  * glib will terminate the program if it is unable to obtain memory
3036  * from the operating system). It will also throw if the copy
3037  * constructor of a bound argument throws and it is not a reference
3038  * argument.
3039  */
3040 template <class... FreeArgs>
3041 CallbackArg<FreeArgs...>* make(std::function<void(FreeArgs...)>&& f) {
3042  return new Callback_function<FreeArgs...>{std::move(f)};
3043 }
3044 
3045 /**
3046  * DEPRECATED.
3047  *
3048  * A convenience function to make Callback::Callback objects from
3049  * std::function objects. Since this function takes no bound argument
3050  * (and bound arguments are bound into the std::function object), it
3051  * is a synonym for make() (the two are identical).
3052  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3053  * is exhausted and the system throws in that case (this exception
3054  * will not be thrown if the library has been installed using the
3055  * \--with-glib-memory-slices-no-compat configuration option: instead
3056  * glib will terminate the program if it is unable to obtain memory
3057  * from the operating system). It will also throw if the copy or move
3058  * constructor of a bound argument throws and it is not a reference
3059  * argument.
3060  */
3061 template <class... FreeArgs>
3062 CallbackArg<FreeArgs...>* make_val(std::function<void(FreeArgs...)>&& f) {
3063  return new Callback_function<FreeArgs...>{std::move(f)};
3064 }
3065 
3066 /**
3067  * A convenience function to make Callback::Callback objects from
3068  * std::function objects. Since this function takes no bound argument
3069  * (and bound arguments are bound into the std::function object), it
3070  * is a synonym for make() (the two are identical).
3071  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3072  * is exhausted and the system throws in that case (this exception
3073  * will not be thrown if the library has been installed using the
3074  * \--with-glib-memory-slices-no-compat configuration option: instead
3075  * glib will terminate the program if it is unable to obtain memory
3076  * from the operating system). It will also throw if the copy or move
3077  * constructor of a bound argument throws and it is not a reference
3078  * argument.
3079  */
3080 template <class... FreeArgs>
3081 CallbackArg<FreeArgs...>* make_ref(std::function<void(FreeArgs...)>&& f) {
3082  return new Callback_function<FreeArgs...>{std::move(f)};
3083 }
3084 
3085 // This helper function to construct Callback_lambda objects could be
3086 // implemented as a further overload of Callback::make(). No best
3087 // match ambiguities would arise, because even when Callback::make()
3088 // is passed a function pointer without bound arguments, the overload
3089 // of Callback::make taking a function pointer (as opposed to a
3090 // generic callable object) would still comprise the best match.
3091 // However, to construct Callback_lambda objects, the unbound
3092 // arguments need to be specified by hand, which doesn't happen with
3093 // Callback::make() (it would only be necessary to specify an explicit
3094 // type where a mutable reference argument is to be bound to the
3095 // callback object). It seems to me to be less confusing to the user
3096 // therefore to have a separate Callback::lambda() helper function.
3097 // However, if you disagree please let me know.
3098 
3099 // template parameter packs do not need to be placed last in the case
3100 // of function templates, as type deduction is available for the last
3101 // parameter: there is in fact no function parameter pack in
3102 // Callback::lambda() (function parameter packs must come last).
3103 /**
3104  * A convenience function to make Callback::CallbackArg objects from
3105  * C++11/14 lambda expressions, or from any other arbitrary callable
3106  * object. The types of the unbound arguments (if any) must be
3107  * explicitly specified as template parameters, as they cannot be
3108  * deduced. From version 2.0.10, this function can be called for
3109  * lambda expressions which are declared mutable (in version 2.0.9,
3110  * this function could only be called for non-mutable lambda
3111  * expressions). From version 2.0.16, this function can be passed
3112  * callable objects which are lvalues as well as rvalues (prior to
3113  * version 2.0.16, it could only be passed callable objects which are
3114  * rvalues).
3115  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3116  * is exhausted and the system throws in that case (this exception
3117  * will not be thrown if the library has been installed using the
3118  * \--with-glib-memory-slices-no-compat configuration option: instead
3119  * glib will terminate the program if it is unable to obtain memory
3120  * from the operating system). It will also throw if the copy or move
3121  * constructor of an object captured by the lambda expression throws.
3122  *
3123  * Since 2.0.9
3124  */
3125 template <class... FreeArgs, class Lambda>
3126 CallbackArg<FreeArgs...>* lambda(Lambda&& l) {
3127  typedef typename std::remove_const<typename std::remove_reference<Lambda>::type>::type LType;
3128  return new Callback_lambda<LType, FreeArgs...>{std::forward<Lambda>(l)};
3129 }
3130 
3131 } // namespace Callback
3132 
3133 class Releaser;
3134 
3135 namespace Callback {
3136 
3137 /**
3138  * Posts a callback for execution by a glib main loop. It is
3139  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
3140  * has been called. glib >= 2.32 does not require g_thread_init() to
3141  * be called. This function will not throw.
3142  * @param cb The callback object. Ownership is taken of this object,
3143  * and it will be deleted when it has been finished with.
3144  * @param priority The priority to be given to the callback in the
3145  * main loop. In ascending order of priorities, priorities are
3146  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
3147  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
3148  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
3149  * callback will appear in the event list in the main loop, not the
3150  * priority which the OS will adopt
3151  * @param context The glib main loop context in which the callback is
3152  * to be executed (the default of NULL will cause the callback to be
3153  * executed in the main program loop, and this is usually what is
3154  * wanted).
3155  * @note 1. Cancellation of the receiving thread is blocked when the
3156  * callback executes.
3157  * @note 2. If the callback throws an exception, the exception will be
3158  * consumed to protect the main loop and a g_critical() warning will
3159  * be issued.
3160  */
3161 void post(const Callback* cb, gint priority = G_PRIORITY_DEFAULT_IDLE,
3162  GMainContext* context = 0);
3163 
3164 /**
3165  * Posts a callback for execution by a glib main loop. It is
3166  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
3167  * has been called. glib >= 2.32 does not require g_thread_init() to
3168  * be called. This function will not throw.
3169  * @param cb The callback object. Ownership is taken of this object,
3170  * and it will be deleted when it has been finished with.
3171  * @param r A Releaser object for automatic disconnection of the
3172  * callback before it executes in the main loop (mainly relevant if
3173  * the callback represents a non-static member function of an object
3174  * which may be destroyed before the callback executes).
3175  * @param priority The priority to be given to the callback in the
3176  * main loop. In ascending order of priorities, priorities are
3177  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
3178  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
3179  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
3180  * callback will appear in the event list in the main loop, not the
3181  * priority which the OS will adopt.
3182  * @param context The glib main loop context in which the callback is
3183  * to be executed (the default of NULL will cause the callback to be
3184  * executed in the main program loop, and this is usually what is
3185  * wanted).
3186  * @exception std::bad_alloc This function might throw std::bad_alloc
3187  * if memory is exhausted and the system throws in that case. If it
3188  * does so, the Callback object will be disposed of.
3189  * @exception Cgu::Thread::MutexError This function might throw
3190  * Cgu:Thread::MutexError if initialisation of the mutex in a
3191  * SafeEmitterArg object constructed by this function fails. If it
3192  * does so, the Callback object will be disposed of. (It is often not
3193  * worth checking for this exception, as it means either memory is
3194  * exhausted or pthread has run out of other resources to create new
3195  * mutexes.)
3196  * @note 1. Cancellation of the receiving thread is blocked when the
3197  * callback executes.
3198  * @note 2. If the callback throws an exception, the exception will be
3199  * consumed to protect the main loop and a g_critical() warning will
3200  * be issued.
3201  * @note 3. By virtue of the Releaser object, it is in theory possible
3202  * (if memory is exhausted and the system throws in that case) that an
3203  * internal SafeEmitterArg object will throw std::bad_alloc when
3204  * emitting/executing the callback in the glib main loop, with the
3205  * result that the relevant callback will not execute (instead the
3206  * exception will be consumed and a g_critical() warning will be
3207  * issued). This is rarely of any relevance because glib will abort
3208  * the program if it is itself unable to obtain memory from the
3209  * operating system. However, where it is relevant, design the
3210  * program so that it is not necessary to provide a releaser object.
3211  */
3212 void post(const Callback* cb, Releaser& r,
3213  gint priority = G_PRIORITY_DEFAULT_IDLE, GMainContext* context = 0);
3214 
3215 } // namespace Callback
3216 
3217 } // namespace Cgu
3218 
3219 #endif
Cgu::Callback::lambda
CallbackArg< FreeArgs... > * lambda(Lambda &&l)
Definition: callback.h:3126
Cgu::Param
Struct for automatic typing of function parameter arguments.
Definition: param.h:76
Cgu::Callback::Callback_function::Callback_function
Callback_function(std::function< void(FreeArgs...)> &&f_)
Definition: callback.h:1629
Cgu::Callback::SafeFunctorArg::SafeFunctorArg
SafeFunctorArg(SafeFunctorArg &&f)
Definition: callback.h:1101
Cgu::Callback::SafeFunctorArg::SafeFunctorArg
SafeFunctorArg(const CallbackArg< FreeArgs... > *cb)
Definition: callback.h:1089
Cgu::Callback::Callback2_const::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...) const
Definition: callback.h:1377
Cgu::Callback::Callback0::MemFunc
void(T::* MemFunc)(FreeArgs...)
Definition: callback.h:1205
Cgu::Callback::Callback2_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1521
Cgu::Callback::Callback1_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1505
Cgu::Callback::to_unique
std::unique_ptr< const CallbackArg< T... > > to_unique(const CallbackArg< T... > *cb)
Definition: callback.h:719
Cgu::Callback::FunctorArg::operator=
FunctorArg & operator=(FunctorArg &&f)
Definition: callback.h:943
Cgu::Callback::Callback_function::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1627
Cgu::Callback::make_ref
CallbackArg< FreeArgs... > * make_ref(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1695
Cgu::Callback::CallbackArg
The callback interface class.
Definition: callback.h:522
Cgu::Callback::Callback4::Callback4
Callback4(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1296
Cgu::Callback::Callback5
Definition: callback.h:1310
Cgu::Callback::Callback_lambda::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1639
Cgu
Definition: application.h:44
Cgu::Callback::Callback2_const::Callback2_const
Callback2_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1388
Cgu::Callback::Callback1::Callback1
Callback1(T &obj_, MemFunc func_, Arg &&arg_)
Definition: callback.h:1229
Cgu::Callback::Callback4_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1433
Cgu::Callback::Callback5::Callback5
Callback5(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1327
Cgu::Callback::Callback1::MemFunc
void(T::* MemFunc)(BoundArg, FreeArgs...)
Definition: callback.h:1219
Cgu::Callback::Callback1_static::Callback1_static
Callback1_static(Func func_, Arg &&arg_)
Definition: callback.h:1509
Cgu::Callback::CallbackArg::~CallbackArg
virtual ~CallbackArg()
Definition: callback.h:634
Cgu::Callback::make
CallbackArg< FreeArgs... > * make(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1659
shared_ptr.h
Cgu::Callback::Callback5::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1323
Cgu::Callback::operator!=
bool operator!=(const FunctorArg< T... > &f1, const FunctorArg< T... > &f2)
Definition: callback.h:750
Cgu::Callback::Callback0_const
Definition: callback.h:1344
Cgu::Callback::SafeFunctorArg::operator()
void operator()(typename Cgu::Param< FreeArgs >::ParamType... args) const
Definition: callback.h:1040
Cgu::Callback::Functor
FunctorArg Functor
Definition: callback.h:726
Cgu::Callback::Callback4_static::Callback4_static
Callback4_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1571
Cgu::Callback::Callback5_static::Func
void(* Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...)
Definition: callback.h:1587
Cgu::Callback::Callback_lambda::Callback_lambda
Callback_lambda(L &&l_)
Definition: callback.h:1640
Cgu::Callback::Callback0_static::Func
void(* Func)(FreeArgs...)
Definition: callback.h:1487
Cgu::Callback::Callback2
Definition: callback.h:1234
Cgu::Callback::operator<
bool operator<(const FunctorArg< T... > &f1, const FunctorArg< T... > &f2)
Definition: callback.h:768
Cgu::Callback::Callback2_static::Func
void(* Func)(BoundArg1, BoundArg2, FreeArgs...)
Definition: callback.h:1515
Cgu::Callback::Callback2::Callback2
Callback2(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1247
Cgu::Callback::Callback2_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1384
Cgu::Callback::SafeFunctorArg::operator=
SafeFunctorArg & operator=(SafeFunctorArg &&f)
Definition: callback.h:1056
Cgu::Callback::Callback5_static::Callback5_static
Callback5_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1601
Cgu::Callback::Callback0_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1491
Cgu::Callback::make_val
CallbackArg< FreeArgs... > * make_val(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1677
Cgu::Callback::Callback3_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1541
Cgu::Callback::Callback0_const::Callback0_const
Callback0_const(const T &obj_, MemFunc func_)
Definition: callback.h:1354
Cgu::Callback::Callback2::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1243
Cgu::Callback::Callback0_static::Callback0_static
Callback0_static(Func func_)
Definition: callback.h:1494
Cgu::Callback::Callback4_const
Definition: callback.h:1422
Cgu::Callback::Callback0_const::MemFunc
void(T::* MemFunc)(FreeArgs...) const
Definition: callback.h:1346
Cgu::Callback::to_functor
FunctorArg< T... > to_functor(const CallbackArg< T... > *cb)
Definition: callback.h:1156
Cgu::Callback::Callback5_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1597
Cgu::Callback::Callback4_static::Func
void(* Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...)
Definition: callback.h:1559
Cgu::Callback::CallbackArg::dispatch
virtual void dispatch(typename Cgu::Param< FreeArgs >::ParamType... args) const =0
Cgu::RemoveRefCond
Struct which will conditionally convert a reference type to a value type.
Definition: param.h:103
Cgu::Callback::Callback4
Definition: callback.h:1281
Cgu::Callback::CallbackArg::CallbackArg
CallbackArg()
Definition: callback.h:628
Cgu::Callback::Callback3_static::Func
void(* Func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...)
Definition: callback.h:1534
Cgu::Callback::Callback4_const::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...) const
Definition: callback.h:1424
Cgu::Callback::Callback5_const::Callback5_const
Callback5_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1468
Cgu::Callback::FunctorArg::operator()
void operator()(typename Cgu::Param< FreeArgs >::ParamType... args) const
Definition: callback.h:927
Cgu::Callback::FunctorArg::FunctorArg
FunctorArg()
Definition: callback.h:995
Cgu::Callback::Callback3::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1265
Cgu::Callback::Callback1_const::Callback1_const
Callback1_const(const T &obj_, MemFunc func_, Arg &&arg_)
Definition: callback.h:1370
Cgu::Callback::Callback1
Definition: callback.h:1217
Cgu::Callback::Callback
CallbackArg Callback
Definition: callback.h:522
Cgu::Callback::Callback1_static::Func
void(* Func)(BoundArg, FreeArgs...)
Definition: callback.h:1500
param.h
Cgu::Callback::Callback_lambda
Definition: callback.h:1634
Cgu::Callback::Callback3_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1406
Cgu::Callback::Callback1_static
Definition: callback.h:1498
Cgu::Callback::Callback1_const
Definition: callback.h:1358
Cgu::Callback::Callback2_static
Definition: callback.h:1513
Cgu::Callback::Callback5_static
Definition: callback.h:1585
Cgu::Callback::Callback4_const::Callback4_const
Callback4_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1437
Cgu::Callback::Callback3_static
Definition: callback.h:1532
Cgu::Callback::Callback4_static
Definition: callback.h:1557
Cgu::Callback::FunctorArg::FunctorArg
FunctorArg(FunctorArg &&f)
Definition: callback.h:988
Cgu::Callback::to_safe_functor
SafeFunctorArg< T... > to_safe_functor(const CallbackArg< T... > *cb)
Definition: callback.h:1196
Cgu::Callback::SafeFunctorArg::operator=
SafeFunctorArg & operator=(const SafeFunctorArg &f)
Definition: callback.h:1049
Cgu::Callback::Callback3::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...)
Definition: callback.h:1257
Cgu::Callback::Callback0_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1351
Cgu::Callback::Callback2_static::Callback2_static
Callback2_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1525
Cgu::Callback::Callback0::Callback0
Callback0(T &obj_, MemFunc func_)
Definition: callback.h:1213
Cgu::Callback::Callback0_static
Definition: callback.h:1485
Cgu::Callback::SafeFunctorArg
Functor class holding a Callback::CallbackArg object, with thread-safe reference count.
Definition: callback.h:726
Cgu::Callback::Callback_function::Callback_function
Callback_function(const std::function< void(FreeArgs...)> &f_)
Definition: callback.h:1628
Cgu::Callback::Callback1_const::MemFunc
void(T::* MemFunc)(BoundArg, FreeArgs...) const
Definition: callback.h:1360
Cgu::Callback::SafeFunctor
SafeFunctorArg SafeFunctor
Definition: callback.h:728
Cgu::Callback::Callback1_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1366
Cgu::Callback::Callback4::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...)
Definition: callback.h:1283
Cgu::Callback::Callback4::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1292
Cgu::Callback::Callback2::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...)
Definition: callback.h:1236
CGU_GLIB_MEMORY_SLICES_FUNCS
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition: cgu_config.h:84
Cgu::Callback::Callback3
Definition: callback.h:1255
Cgu::Callback::Callback3_const
Definition: callback.h:1396
hash
A specialization of std::hash for Cgu::Callback::FunctorArg, Cgu::Callback::SafeFunctorArg,...
Cgu::Callback::Callback5::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...)
Definition: callback.h:1312
Cgu::Callback::Callback3_static::Callback3_static
Callback3_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1545
Cgu::SharedLockPtr
This is a smart pointer for managing the lifetime of objects allocated on freestore,...
Definition: shared_ptr.h:644
Cgu::Callback::Callback1::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1225
Cgu::Callback::Callback3_const::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const
Definition: callback.h:1398
Cgu::Callback::Callback5_const
Definition: callback.h:1451
Cgu::Callback::Callback3::Callback3
Callback3(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1269
Cgu::Callback::FunctorArg
Functor class holding a Callback::CallbackArg object.
Definition: callback.h:725
Cgu::Callback::Callback_function
Definition: callback.h:1624
Cgu::Callback::SafeFunctorArg::SafeFunctorArg
SafeFunctorArg(const SafeFunctorArg &f)
Definition: callback.h:1095
Cgu::Callback::FunctorArg::operator=
FunctorArg & operator=(const FunctorArg &f)
Definition: callback.h:936
Cgu::Callback::FunctorArg::FunctorArg
FunctorArg(const CallbackArg< FreeArgs... > *cb)
Definition: callback.h:976
Cgu::Callback::SafeFunctorArg::SafeFunctorArg
SafeFunctorArg()
Definition: callback.h:1113
Cgu::Callback::Callback0
Definition: callback.h:1203
Cgu::Callback::Callback5_const::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1464
Cgu::Callback::operator==
bool operator==(const FunctorArg< T... > &f1, const FunctorArg< T... > &f2)
Definition: callback.h:740
Cgu::Callback::Callback2_const
Definition: callback.h:1375
Cgu::Callback::Callback5_const::MemFunc
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...) const
Definition: callback.h:1453
Cgu::Callback::Callback4_static::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1567
Cgu::Callback::FunctorArg::FunctorArg
FunctorArg(const FunctorArg &f)
Definition: callback.h:982
Cgu::Callback::Callback0::dispatch
void dispatch(typename Cgu::Param< FreeArgs >::ParamType... free_args) const
Definition: callback.h:1210
Cgu::Callback::Callback3_const::Callback3_const
Callback3_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1410
cgu_config.h
Cgu::Callback::post
void post(const Callback *cb, gint priority=G_PRIORITY_DEFAULT_IDLE, GMainContext *context=0)