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++, and is due to
666  * change with C++17 - see further below). For example, at present a
667  * function:
668  *
669  * @code
670  * void do_it(std::unique_ptr<const Cgu::Callback::Callback> cb1,
671  * std::unique_ptr<const Cgu::Callback::Callback> cb2);
672  * @endcode
673  * should not be called like this:
674  * @code
675  * do_it(Callback::to_unique(Callback::lambda<>([]() {...;})),
676  * Callback::to_unique(Callback::lambda<>([]() {...;})));
677  * @endcode
678  *
679  * This is because one possible sequencing that C++14 and earlier
680  * permit is as follows:
681  *
682  * 1. Construct the callback object for the first argument by calling
683  * Callback::lambda().
684  * 2. Construct the callback object for the second argument by calling
685  * Callback::lambda().
686  * 3. Initialize a std::unique_ptr object for the second argument by
687  * calling Callback::to_unique().
688  * 4. Initialize a std::unique_ptr object for the first argument by
689  * calling Callback::to_unique().
690  * 5. Enter do_it().
691  *
692  * Because step 2 is permitted to precede step 4, if step 2 throws
693  * then the object constructed at step 1 will be leaked. To avoid
694  * this, explicit sequencing must be provided for in the code, as
695  * follows:
696  *
697  * @code
698  * auto cb1 = Callback::to_unique(Callback::lambda<>([]() {...;}));
699  * auto cb2 = Callback::to_unique(Callback::lambda<>([]() {...;}));
700  * do_it(std::move(cb1),
701  * std::move(cb2));
702  * @endcode
703  *
704  * The current proposals for C++17 preventing interleaving when
705  * evaluating function arguments (P0145R1) means that, if adopted in
706  * C++17 as seems likely, these issues should not affect code compiled
707  * with a C++17 compiler option.
708  *
709  * The Cgu::Callback::CallbackArg object held by the unique_ptr
710  * returned by this function is const. This is because all the
711  * interfaces in this library also take const
712  * Cgu::Callback::CallbackArg objects (and their only method, the
713  * dispatch() method, is const). However, if constructed using
714  * Cgu::Callback::lambda(), Cgu::Callback::make() or
715  * Cgu::Callback::make_ref(), the Cgu::Callback::CallbackArg object
716  * can safely be cast to non-const.
717  *
718  * @param cb The CallbackArg object which is to be managed by a
719  * std::unique_ptr.
720  * @return The std::unique_ptr object.
721  *
722  * Since 2.0.23
723  */
724 template<class... T>
725 std::unique_ptr<const CallbackArg<T...>> to_unique(const CallbackArg<T...>* cb) {
726  return std::unique_ptr<const CallbackArg<T...>>(cb);
727 }
728 
729 /* The four basic functor types */
730 
731 template <class... FreeArgs> class FunctorArg;
732 template <class... FreeArgs> class SafeFunctorArg;
733 typedef FunctorArg<> Functor;
735 
736 /* Functor friend functions */
737 
738 // we can use built-in operator == when comparing pointers referencing
739 // different objects of the same type
740 /**
741  * Two FunctorArg objects compare equal if the addresses of the
742  * CallbackArg objects they contain are the same. This comparison
743  * operator does not throw.
744  */
745 template <class... T>
746 bool operator==(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
747  return (f1.cb_s.get() == f2.cb_s.get());
748 }
749 
750 /**
751  * Two FunctorArg objects compare unequal if the addresses of the
752  * CallbackArg objects they contain are not the same. This comparison
753  * operator does not throw.
754  */
755 template <class... T>
756 bool operator!=(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
757  return !(f1 == f2);
758 }
759 
760 // we must use std::less rather than the < built-in operator for
761 // pointers to objects not within the same array or object: "For
762 // templates greater, less, greater_equal, and less_equal, the
763 // specializations for any pointer type yield a total order, even if
764 // the built-in operators <, >, <=, >= do not." (para 20.3.3/8).
765 /**
766  * One FunctorArg object is less than another if the address of the
767  * CallbackArg object contained by the first is regarded by std::less
768  * as less than the address of the CallbackArg object contained by the
769  * other. This comparison operator does not throw unless std::less
770  * applied to pointer types throws (which it would not do with any
771  * sane implementation).
772  */
773 template <class... T>
774 bool operator<(const FunctorArg<T...>& f1, const FunctorArg<T...>& f2) {
775  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
776 }
777 
778 /**
779  * Two SafeFunctorArg objects compare equal if the addresses of the
780  * CallbackArg objects they contain are the same. This comparison
781  * operator does not throw.
782  */
783 template <class... T>
785  return (f1.cb_s.get() == f2.cb_s.get());
786 }
787 
788 /**
789  * Two SafeFunctorArg objects compare unequal if the addresses of the
790  * CallbackArg objects they contain are not the same. This comparison
791  * operator does not throw.
792  */
793 template <class... T>
795  return !(f1 == f2);
796 }
797 
798 /**
799  * One SafeFunctorArg object is less than another if the address of
800  * the CallbackArg object contained by the first is regarded by
801  * std::less as less than the address of the CallbackArg object
802  * contained by the other. This comparison operator does not throw
803  * unless std::less applied to pointer types throws (which it would
804  * not do with any sane implementation).
805  */
806 template <class... T>
808  return std::less<const CallbackArg<T...>*>()(f1.cb_s.get(), f2.cb_s.get());
809 }
810 
811 } // namespace Callback
812 } // namespace Cgu
813 
814 // doxygen produces long filenames that tar can't handle:
815 // we have generic documentation for std::hash specialisations
816 // in doxygen.main.in
817 #ifndef DOXYGEN_PARSING
818 
819 /* These structs allow FunctorArg and SafeFunctorArg objects to be
820  keys in unordered associative containers */
821 namespace std {
822 template <class... T>
823 struct hash<Cgu::Callback::FunctorArg<T...>> {
824  typedef std::size_t result_type;
825  typedef Cgu::Callback::FunctorArg<T...> argument_type;
826  result_type operator()(const argument_type& f) const {
827  // this is fine: std::hash structs do not normally contain data and
828  // std::hash<T*> certainly won't, so we don't have overhead constructing
829  // std::hash<T*> on the fly
830  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
831  }
832 };
833 template <class... T>
834 struct hash<Cgu::Callback::SafeFunctorArg<T...>> {
835  typedef std::size_t result_type;
836  typedef Cgu::Callback::SafeFunctorArg<T...> argument_type;
837  result_type operator()(const argument_type& f) const {
838  // this is fine: std::hash structs do not normally contain data and
839  // std::hash<T*> certainly won't, so we don't have overhead constructing
840  // std::hash<T*> on the fly
841  return std::hash<const Cgu::Callback::CallbackArg<T...>*>()(f.cb_s.get());
842  }
843 };
844 } // namespace std
845 
846 #endif // DOXYGEN_PARSING
847 
848 namespace Cgu {
849 namespace Callback {
850 
851 /* the functor classes */
852 
853 /**
854  * @class FunctorArg callback.h c++-gtk-utils/callback.h
855  * @brief Functor class holding a Callback::CallbackArg object.
856  * @sa SafeFunctorArg
857  * @sa Callback namespace
858  *
859  * This class wraps a CallbackArg object. The callback object is kept
860  * by SharedPtr so the functor can be copied and offers automatic
861  * lifetime management of the wrapped callback object, as well as
862  * providing an operator()() function. Ownership is taken of the
863  * CallbackArg object passed to the constructor taking a CallbackArg
864  * pointer, so that constructor should be treated like a shared
865  * pointer constructor - only pass a newly allocated object to it (or
866  * copy construct it or assign to it from another existing FunctorArg
867  * object). The template types are the types of the unbound
868  * arguments, if any. Callback::FunctorArg<> is typedef'ed to
869  * Callback::Functor.
870  *
871  * The constructor taking a Callback::CallbackArg pointer is not
872  * marked explicit, so the results of Callback::lambda(),
873  * Callback::make() or Callback::make_ref() can be passed directly to
874  * a function taking a Callback::FunctorArg argument, and implicit
875  * conversion will take place.
876  *
877  * Functor/FunctorArg classes do not provide for a return value. If
878  * a result is wanted, users should pass an unbound argument by
879  * reference or pointer (or pointer to pointer).
880  *
881  * @b Usage
882  *
883  * These are examples:
884  *
885  * @code
886  * using namespace Cgu;
887  *
888  * // here f1 is directly initialized using the type conversion constructor
889  * Callback::Functor f1{Callback::lambda<>([] () {std::cout << "Hello world\n";})};
890  * f1();
891  *
892  * // here Callback::to_functor() is used to enable use of the auto keyword.
893  * // f2 is of type Callback::Functor
894  * auto f2 = Callback::to_functor(Callback::lambda<>([] () {std::cout << "Hello world\n";}));
895  * f2();
896  *
897  * // here f3 is of type Callback::FunctorArg<int, int&>
898  * auto f3 = Callback::to_functor(Callback::lambda<int, int&>([] (int i, int& j) {j = 10 * i;}));
899  * int res;
900  * f3(2, res);
901  * std::cout << "10 times 2 is " << res << '\n';
902  * @endcode
903  *
904  * For further background, including about the Callback::make(),
905  * Callback::make_ref() and Callback::to_functor() functions, read
906  * this: Callback
907  */
908 
909 template <class... FreeArgs>
910 class FunctorArg {
911  SharedPtr<const CallbackArg<FreeArgs...>> cb_s;
912 public:
913 /* Because CallbackArg::dispatch() is a virtual function, it is
914  * pointless templatising this function with a view to preserving
915  * r-value forwarding of temporary objects passed as a free argument,
916  * because the r-value typeness will be discarded in dispatch(). But
917  * this would rarely be relevant anyway - it would only be relevant if
918  * the target function were to take an argument by r-value reference
919  * and a temporary were to be passed to it. In such a case virtual
920  * dispatch is at the cost of a copy of the temporary.
921  */
922 /**
923  * This will execute the function, callable object or class method
924  * represented by the callback encapsulated by this object, or do
925  * nothing if this object has not been initialized with a callback.
926  * It will only throw if the executed function, callable object or
927  * class method throws, or if the copy constructor of a free or bound
928  * argument throws and it is not a reference argument. It is thread
929  * safe if the referenced function or class method is thread safe.
930  * @param args The unbound arguments to be passed to the referenced
931  * function, callable object or class method, if any.
932  */
933  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
934  if (cb_s.get()) cb_s->dispatch(args...);
935  }
936 
937 /**
938  * This function does not throw.
939  * @param f The assignor.
940  * @return The functor object after assignment.
941  */
942  FunctorArg& operator=(const FunctorArg& f) {cb_s = f.cb_s; return *this;}
943 
944 /**
945  * This function does not throw.
946  * @param f The functor to be moved.
947  * @return The functor object after the move operation.
948  */
949  FunctorArg& operator=(FunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
950 
951 /**
952  * Two FunctorArg objects compare equal if the addresses of the
953  * CallbackArg objects they contain are the same. This comparison
954  * operator does not throw.
955  */
956  friend bool operator== <>(const FunctorArg&, const FunctorArg&);
957 
958 /**
959  * One FunctorArg object is less than another if the address of the
960  * CallbackArg object contained by the first is regarded by std::less
961  * as less than the address of the CallbackArg object contained by the
962  * other. This comparison operator does not throw.
963  */
964  friend bool operator< <>(const FunctorArg&, const FunctorArg&);
965 
966  friend struct std::hash<FunctorArg>;
967 
968 /**
969  * Constructor of first FunctorArg holding the referenced callback.
970  * As it is not marked explicit, it is also a type conversion
971  * constructor.
972  * @param cb The CallbackArg object which the functor is to manage.
973  * @exception std::bad_alloc This might throw std::bad_alloc if
974  * memory is exhausted and the system throws in that case. Note that
975  * if such an exception is thrown, then this constructor will clean
976  * itself up and also delete the callback object passed to it.
977  * @note std::bad_alloc will not be thrown if the library has been
978  * installed using the \--with-glib-memory-slices-no-compat
979  * configuration option: instead glib will terminate the program if it
980  * is unable to obtain memory from the operating system.
981  */
982  FunctorArg(const CallbackArg<FreeArgs...>* cb): cb_s(cb) {}
983 
984 /**
985  * The copy constructor does not throw.
986  * @param f The assignor
987  */
988  FunctorArg(const FunctorArg& f): cb_s(f.cb_s) {}
989 
990 /**
991  * The move constructor does not throw.
992  * @param f The functor to be moved.
993  */
994  FunctorArg(FunctorArg&& f): cb_s(std::move(f.cb_s)) {}
995 
996  /**
997  * Default constructor, where a Callback::CallbackArg object is to be
998  * assigned later (via the type conversion constructor and/or the
999  * assignment operator). This constructor does not throw.
1000  */
1002 
1003 /* Only has effect if --with-glib-memory-slices-compat or
1004  --with-glib-memory-slices-no-compat option picked */
1006 };
1007 
1008 /**
1009  * @class SafeFunctorArg callback.h c++-gtk-utils/callback.h
1010  * @brief Functor class holding a Callback::CallbackArg object, with
1011  * thread-safe reference count.
1012  * @sa FunctorArg
1013  * @sa Callback namespace
1014  *
1015  * This class wraps a CallbackArg object. It is the same as
1016  * Callback::FunctorArg except that it will provide synchronisation of
1017  * the reference count between threads. Use it where a functor
1018  * wrapper object is to be passed between threads. The FunctorArg
1019  * documentation gives further details. The
1020  * Callback::to_safe_functor() function can be used in place of the
1021  * Callback::to_functor() function when constructing a
1022  * Callback::SafeFunctorArg object using the auto keyword.
1023  *
1024  * Callback::SafeFunctorArg<> is typedef'ed to Callback::SafeFunctor.
1025  *
1026  * For further background, including about the Callback::make(),
1027  * Callback::make_ref() and Callback::to_safe_functor() functions,
1028  * read this: Callback
1029  */
1030 
1031 template <class... FreeArgs>
1032 class SafeFunctorArg {
1033  SharedLockPtr<const CallbackArg<FreeArgs...>> cb_s;
1034 public:
1035 /**
1036  * This will execute the function, callable object or class method
1037  * represented by the callback encapsulated by this object, or do
1038  * nothing if this object has not been initialized with a callback.
1039  * It will only throw if the executed function, callable object or
1040  * class method throws, or if the copy constructor of a free or bound
1041  * argument throws and it is not a reference argument. It is thread
1042  * safe if the referenced function or class method is thread safe.
1043  * @param args The unbound arguments to be passed to the referenced
1044  * function, callable object or class method, if any.
1045  */
1046  void operator()(typename Cgu::Param<FreeArgs>::ParamType... args) const {
1047  if (cb_s.get()) cb_s->dispatch(args...);
1048  }
1049 
1050 /**
1051  * This function does not throw.
1052  * @param f The assignor.
1053  * @return The functor object after assignment.
1054  */
1055  SafeFunctorArg& operator=(const SafeFunctorArg& f) {cb_s = f.cb_s; return *this;}
1056 
1057 /**
1058  * This function does not throw.
1059  * @param f The functor to be moved.
1060  * @return The functor object after the move operation.
1061  */
1062  SafeFunctorArg& operator=(SafeFunctorArg&& f) {cb_s = std::move(f.cb_s); return *this;}
1063 
1064 /**
1065  * Two SafeFunctorArg objects compare equal if the addresses of the
1066  * CallbackArg objects they contain are the same. This comparison
1067  * operator does not throw.
1068  */
1069  friend bool operator== <>(const SafeFunctorArg&, const SafeFunctorArg&);
1070 
1071 /**
1072  * One SafeFunctorArg object is less than another if the address of
1073  * the CallbackArg object contained by the first is regarded by
1074  * std::less as less than the address of the CallbackArg object
1075  * contained by the other. This comparison operator does not throw.
1076  */
1077  friend bool operator< <>(const SafeFunctorArg&, const SafeFunctorArg&);
1078 
1079  friend struct std::hash<SafeFunctorArg>;
1080 
1081  /**
1082  * Constructor of first SafeFunctorArg holding the referenced
1083  * callback. As it is not marked explicit, it is also a type
1084  * conversion constructor.
1085  * @param cb The CallbackArg object which the functor is to manage.
1086  * @exception std::bad_alloc This might throw std::bad_alloc if
1087  * memory is exhausted and the system throws in that case. Note that
1088  * if such an exception is thrown, then this constructor will clean
1089  * itself up and also delete the callback object passed to it.
1090  * @note std::bad_alloc will not be thrown if the library has been
1091  * installed using the \--with-glib-memory-slices-no-compat
1092  * configuration option: instead glib will terminate the program if it
1093  * is unable to obtain memory from the operating system.
1094  */
1096 
1097 /**
1098  * The copy constructor does not throw.
1099  * @param f The assignor.
1100  */
1101  SafeFunctorArg(const SafeFunctorArg& f): cb_s(f.cb_s) {}
1102 
1103 /**
1104  * The move constructor does not throw.
1105  * @param f The functor to be moved.
1106  */
1107  SafeFunctorArg(SafeFunctorArg&& f): cb_s(std::move(f.cb_s)) {}
1108 
1109  /**
1110  * Default constructor, where a Callback::CallbackArg object is to be
1111  * assigned later (via the type conversion constructor and/or the
1112  * assignment operator). This constructor does not throw.
1113  * @note The reference count maintained with respect to the contained
1114  * callback object is thread-safe, so SafeFunctorArg objects may be
1115  * copied between threads by the implicit assignment operator and put
1116  * in different containers in different threads. They use a
1117  * SharedLockPtr object to hold the referenced callback object.
1118  */
1120 
1121 /* Only has effect if --with-glib-memory-slices-compat or
1122  --with-glib-memory-slices-no-compat option picked */
1124 };
1125 
1126 /**
1127  * A function for making a Cgu::Callback::FunctorArg object from a
1128  * Cgu::Callback::CallbackArg object, for the purpose of taking
1129  * ownership of the CallbackArg object. It is thread safe.
1130  *
1131  * Because the constructor of FunctorArg taking a pointer is not
1132  * explicit and can therefore be used for implicit type conversion,
1133  * this function will not often be needed. It is mainly intended for
1134  * use when constructing a named object in local scope with the auto
1135  * keyword, to avoid having to write out the type of the FunctorArg
1136  * object in longhand. For example:
1137  *
1138  * @code
1139  * using namespace Cgu;
1140  * // here a Cgu::Callback::FunctorArg<const std::string&> object is constructed
1141  * auto f = Callback::to_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1142  * std::cout << s;
1143  * }));
1144  * f("Hello\n");
1145  * @endcode
1146  *
1147  * @param cb The CallbackArg object which is to be managed by a
1148  * functor.
1149  * @return The FunctorArg object.
1150  * @exception std::bad_alloc This function might throw std::bad_alloc
1151  * if memory is exhausted and the system throws in that case. Note
1152  * that if such an exception is thrown, then this function will delete
1153  * the callback object passed to it.
1154  * @note std::bad_alloc will not be thrown if the library has been
1155  * installed using the \--with-glib-memory-slices-no-compat
1156  * configuration option: instead glib will terminate the program if it
1157  * is unable to obtain memory from the operating system.
1158  *
1159  * Since 2.0.23
1160  */
1161 template<class... T>
1163  return cb;
1164 }
1165 
1166 /**
1167  * A function for making a Cgu::Callback::SafeFunctorArg object from a
1168  * Cgu::Callback::CallbackArg object, for the purpose of taking
1169  * ownership of the CallbackArg object. It is thread safe.
1170  *
1171  * Because the constructor of SafeFunctorArg taking a pointer is not
1172  * explicit and can therefore be used for implicit type conversion,
1173  * this function will not often be needed. It is mainly intended for
1174  * use when constructing a named object in local scope with the auto
1175  * keyword, to avoid having to write out the type of the
1176  * SafeFunctorArg object in longhand. For example:
1177  *
1178  * @code
1179  * using namespace Cgu;
1180  * // here a Cgu::Callback::SafeFunctorArg<const std::string&> object is constructed
1181  * auto f = Callback::to_safe_functor(Callback::lambda<const std::string&>([] (const std::string& s) {
1182  * std::cout << s;
1183  * }));
1184  * f("Hello\n");
1185  * @endcode
1186  *
1187  * @param cb The CallbackArg object which is to be managed by a
1188  * functor.
1189  * @return The SafeFunctorArg object.
1190  * @exception std::bad_alloc This function might throw std::bad_alloc
1191  * if memory is exhausted and the system throws in that case. Note
1192  * that if such an exception is thrown, then this function will delete
1193  * the callback object passed to it.
1194  * @note std::bad_alloc will not be thrown if the library has been
1195  * installed using the \--with-glib-memory-slices-no-compat
1196  * configuration option: instead glib will terminate the program if it
1197  * is unable to obtain memory from the operating system.
1198  *
1199  * Since 2.0.23
1200  */
1201 template<class... T>
1203  return cb;
1204 }
1205 
1206 /* the callback implementation classes */
1207 
1208 template <class T, class... FreeArgs>
1209 class Callback0: public CallbackArg<FreeArgs...> {
1210 public:
1211  typedef void (T::* MemFunc)(FreeArgs...);
1212 private:
1213  T* obj;
1214  MemFunc func;
1215 public:
1216  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1217  (obj->*func)(free_args...);
1218  }
1219  Callback0(T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
1220 };
1221 
1222 template <bool unref, class T, class BoundArg, class... FreeArgs>
1223 class Callback1: public CallbackArg<FreeArgs...> {
1224 public:
1225  typedef void (T::* MemFunc)(BoundArg, FreeArgs...);
1226 private:
1227  T* obj;
1228  MemFunc func;
1230 public:
1231  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1232  (obj->*func)(arg, free_args...);
1233  }
1234  template <class Arg>
1235  Callback1(T& obj_, MemFunc func_,
1236  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
1237 };
1238 
1239 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1240 class Callback2: public CallbackArg<FreeArgs...> {
1241 public:
1242  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...);
1243 private:
1244  T* obj;
1245  MemFunc func;
1248 public:
1249  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1250  (obj->*func)(arg1, arg2, free_args...);
1251  }
1252  template <class Arg1, class Arg2>
1253  Callback2(T& obj_, MemFunc func_,
1254  Arg1&& arg1_,
1255  Arg2&& arg2_): obj(&obj_), func(func_),
1256  arg1(std::forward<Arg1>(arg1_)),
1257  arg2(std::forward<Arg2>(arg2_)) {}
1258 };
1259 
1260 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1261 class Callback3: public CallbackArg<FreeArgs...> {
1262 public:
1263  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
1264 private:
1265  T* obj;
1266  MemFunc func;
1270 public:
1271  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1272  (obj->*func)(arg1, arg2, arg3, free_args...);
1273  }
1274  template <class Arg1, class Arg2, class Arg3>
1275  Callback3(T& obj_, MemFunc func_,
1276  Arg1&& arg1_,
1277  Arg2&& arg2_,
1278  Arg3&& arg3_):
1279  obj(&obj_), func(func_),
1280  arg1(std::forward<Arg1>(arg1_)),
1281  arg2(std::forward<Arg2>(arg2_)),
1282  arg3(std::forward<Arg3>(arg3_)) {}
1283 };
1284 
1285 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1286  class BoundArg4, class... FreeArgs>
1287 class Callback4: public CallbackArg<FreeArgs...> {
1288 public:
1289  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
1290 private:
1291  T* obj;
1292  MemFunc func;
1297 public:
1298  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1299  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
1300  }
1301  template <class Arg1, class Arg2, class Arg3, class Arg4>
1302  Callback4(T& obj_, MemFunc func_,
1303  Arg1&& arg1_,
1304  Arg2&& arg2_,
1305  Arg3&& arg3_,
1306  Arg4&& arg4_):
1307  obj(&obj_), func(func_),
1308  arg1(std::forward<Arg1>(arg1_)),
1309  arg2(std::forward<Arg2>(arg2_)),
1310  arg3(std::forward<Arg3>(arg3_)),
1311  arg4(std::forward<Arg4>(arg4_)) {}
1312 };
1313 
1314 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1315  class BoundArg4, class BoundArg5, class... FreeArgs>
1316 class Callback5: public CallbackArg<FreeArgs...> {
1317 public:
1318  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
1319  BoundArg4, BoundArg5, FreeArgs...);
1320 private:
1321  T* obj;
1322  MemFunc func;
1328 public:
1329  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1330  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
1331  }
1332  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1333  Callback5(T& obj_, MemFunc func_,
1334  Arg1&& arg1_,
1335  Arg2&& arg2_,
1336  Arg3&& arg3_,
1337  Arg4&& arg4_,
1338  Arg5&& arg5_):
1339  obj(&obj_), func(func_),
1340  arg1(std::forward<Arg1>(arg1_)),
1341  arg2(std::forward<Arg2>(arg2_)),
1342  arg3(std::forward<Arg3>(arg3_)),
1343  arg4(std::forward<Arg4>(arg4_)),
1344  arg5(std::forward<Arg5>(arg5_)) {}
1345 };
1346 
1347 /* const versions, for binding to const methods */
1348 
1349 template <class T, class... FreeArgs>
1350 class Callback0_const: public CallbackArg<FreeArgs...> {
1351 public:
1352  typedef void (T::* MemFunc)(FreeArgs...) const;
1353 private:
1354  const T* obj;
1355  MemFunc func;
1356 public:
1357  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1358  (obj->*func)(free_args...);
1359  }
1360  Callback0_const(const T& obj_, MemFunc func_): obj(&obj_), func(func_) {}
1361 };
1362 
1363 template <bool unref, class T, class BoundArg, class... FreeArgs>
1364 class Callback1_const: public CallbackArg<FreeArgs...> {
1365 public:
1366  typedef void (T::* MemFunc)(BoundArg, FreeArgs...) const;
1367 private:
1368  const T* obj;
1369  MemFunc func;
1371 public:
1372  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1373  (obj->*func)(arg, free_args...);
1374  }
1375  template <class Arg>
1376  Callback1_const(const T& obj_, MemFunc func_,
1377  Arg&& arg_): obj(&obj_), func(func_), arg(std::forward<Arg>(arg_)) {}
1378 };
1379 
1380 template <bool unref, class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1381 class Callback2_const: public CallbackArg<FreeArgs...> {
1382 public:
1383  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...) const;
1384 private:
1385  const T* obj;
1386  MemFunc func;
1389 public:
1390  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1391  (obj->*func)(arg1, arg2, free_args...);
1392  }
1393  template <class Arg1, class Arg2>
1394  Callback2_const(const T& obj_, MemFunc func_,
1395  Arg1&& arg1_,
1396  Arg2&& arg2_): obj(&obj_), func(func_),
1397  arg1(std::forward<Arg1>(arg1_)),
1398  arg2(std::forward<Arg2>(arg2_)) {}
1399 };
1400 
1401 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1402 class Callback3_const: public CallbackArg<FreeArgs...> {
1403 public:
1404  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const;
1405 private:
1406  const T* obj;
1407  MemFunc func;
1411 public:
1412  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1413  (obj->*func)(arg1, arg2, arg3, free_args...);
1414  }
1415  template <class Arg1, class Arg2, class Arg3>
1416  Callback3_const(const T& obj_, MemFunc func_,
1417  Arg1&& arg1_,
1418  Arg2&& arg2_,
1419  Arg3&& arg3_):
1420  obj(&obj_), func(func_),
1421  arg1(std::forward<Arg1>(arg1_)),
1422  arg2(std::forward<Arg2>(arg2_)),
1423  arg3(std::forward<Arg3>(arg3_)) {}
1424 };
1425 
1426 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1427  class BoundArg4, class... FreeArgs>
1428 class Callback4_const: public CallbackArg<FreeArgs...> {
1429 public:
1430  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...) const;
1431 private:
1432  const T* obj;
1433  MemFunc func;
1438 public:
1439  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1440  (obj->*func)(arg1, arg2, arg3, arg4, free_args...);
1441  }
1442  template <class Arg1, class Arg2, class Arg3, class Arg4>
1443  Callback4_const(const T& obj_, MemFunc func_,
1444  Arg1&& arg1_,
1445  Arg2&& arg2_,
1446  Arg3&& arg3_,
1447  Arg4&& arg4_):
1448  obj(&obj_), func(func_),
1449  arg1(std::forward<Arg1>(arg1_)),
1450  arg2(std::forward<Arg2>(arg2_)),
1451  arg3(std::forward<Arg3>(arg3_)),
1452  arg4(std::forward<Arg4>(arg4_)) {}
1453 };
1454 
1455 template <bool unref, class T, class BoundArg1, class BoundArg2, class BoundArg3,
1456  class BoundArg4, class BoundArg5, class... FreeArgs>
1457 class Callback5_const: public CallbackArg<FreeArgs...> {
1458 public:
1459  typedef void (T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3,
1460  BoundArg4, BoundArg5, FreeArgs...) const;
1461 private:
1462  const T* obj;
1463  MemFunc func;
1469 public:
1470  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1471  (obj->*func)(arg1, arg2, arg3, arg4, arg5, free_args...);
1472  }
1473  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1474  Callback5_const(const T& obj_, MemFunc func_,
1475  Arg1&& arg1_,
1476  Arg2&& arg2_,
1477  Arg3&& arg3_,
1478  Arg4&& arg4_,
1479  Arg5&& arg5_):
1480  obj(&obj_), func(func_),
1481  arg1(std::forward<Arg1>(arg1_)),
1482  arg2(std::forward<Arg2>(arg2_)),
1483  arg3(std::forward<Arg3>(arg3_)),
1484  arg4(std::forward<Arg4>(arg4_)),
1485  arg5(std::forward<Arg5>(arg5_)) {}
1486 };
1487 
1488 /* for static class methods and non-class functions */
1489 
1490 template <class... FreeArgs>
1491 class Callback0_static: public CallbackArg<FreeArgs...> {
1492 public:
1493  typedef void (*Func)(FreeArgs...);
1494 private:
1495  Func func;
1496 public:
1497  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1498  func(free_args...);
1499  }
1500  Callback0_static(Func func_): func(func_) {}
1501 };
1502 
1503 template <bool unref, class BoundArg, class... FreeArgs>
1504 class Callback1_static: public CallbackArg<FreeArgs...> {
1505 public:
1506  typedef void (*Func)(BoundArg, FreeArgs...);
1507 private:
1508  Func func;
1510 public:
1511  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1512  func(arg, free_args...);
1513  }
1514  template <class Arg>
1515  Callback1_static(Func func_, Arg&& arg_): func(func_), arg(std::forward<Arg>(arg_)) {}
1516 };
1517 
1518 template <bool unref, class BoundArg1, class BoundArg2, class... FreeArgs>
1519 class Callback2_static: public CallbackArg<FreeArgs...> {
1520 public:
1521  typedef void (*Func)(BoundArg1, BoundArg2, FreeArgs...);
1522 private:
1523  Func func;
1526 public:
1527  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1528  func(arg1, arg2, free_args...);
1529  }
1530  template <class Arg1, class Arg2>
1531  Callback2_static(Func func_, Arg1&& arg1_,
1532  Arg2&& arg2_): func(func_),
1533  arg1(std::forward<Arg1>(arg1_)),
1534  arg2(std::forward<Arg2>(arg2_)) {}
1535 };
1536 
1537 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1538 class Callback3_static: public CallbackArg<FreeArgs...> {
1539 public:
1540  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...);
1541 private:
1542  Func func;
1546 public:
1547  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1548  func(arg1, arg2, arg3, free_args...);
1549  }
1550  template <class Arg1, class Arg2, class Arg3>
1552  Arg1&& arg1_,
1553  Arg2&& arg2_,
1554  Arg3&& arg3_):
1555  func(func_),
1556  arg1(std::forward<Arg1>(arg1_)),
1557  arg2(std::forward<Arg2>(arg2_)),
1558  arg3(std::forward<Arg3>(arg3_)) {}
1559 };
1560 
1561 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
1562  class BoundArg4, class... FreeArgs>
1563 class Callback4_static: public CallbackArg<FreeArgs...> {
1564 public:
1565  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...);
1566 private:
1567  Func func;
1572 public:
1573  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1574  func(arg1, arg2, arg3, arg4, free_args...);
1575  }
1576  template <class Arg1, class Arg2, class Arg3, class Arg4>
1578  Arg1&& arg1_,
1579  Arg2&& arg2_,
1580  Arg3&& arg3_,
1581  Arg4&& arg4_):
1582  func(func_),
1583  arg1(std::forward<Arg1>(arg1_)),
1584  arg2(std::forward<Arg2>(arg2_)),
1585  arg3(std::forward<Arg3>(arg3_)),
1586  arg4(std::forward<Arg4>(arg4_)) {}
1587 };
1588 
1589 template <bool unref, class BoundArg1, class BoundArg2, class BoundArg3,
1590  class BoundArg4, class BoundArg5, class... FreeArgs>
1591 class Callback5_static: public CallbackArg<FreeArgs...> {
1592 public:
1593  typedef void (*Func)(BoundArg1, BoundArg2, BoundArg3,
1594  BoundArg4, BoundArg5, FreeArgs...);
1595 private:
1596  Func func;
1602 public:
1603  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {
1604  func(arg1, arg2, arg3, arg4, arg5, free_args...);
1605  }
1606  template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
1608  Arg1&& arg1_,
1609  Arg2&& arg2_,
1610  Arg3&& arg3_,
1611  Arg4&& arg4_,
1612  Arg5&& arg5_):
1613  func(func_),
1614  arg1(std::forward<Arg1>(arg1_)),
1615  arg2(std::forward<Arg2>(arg2_)),
1616  arg3(std::forward<Arg3>(arg3_)),
1617  arg4(std::forward<Arg4>(arg4_)),
1618  arg5(std::forward<Arg5>(arg5_)) {}
1619 };
1620 
1621 // TODO: Version 2.0.9 provides a Callback_lambda class for callable
1622 // objects which makes the specialized Callback_function class
1623 // redundant. At an API break we can remove the Callback_function
1624 // class and modify the Callback::make() helper function overload for
1625 // std::function objects to construct a Callback_lambda object
1626 // instead. Doing it now would not affect ABI compatibility as the
1627 // library produces these only by base pointer, but a user may have
1628 // instantiated them by hand in user code.
1629 template <class... FreeArgs>
1630 class Callback_function: public CallbackArg<FreeArgs...> {
1631  std::function<void(FreeArgs...)> f;
1632 public:
1633  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {f(free_args...);}
1634  Callback_function(const std::function<void(FreeArgs...)>& f_): f(f_) {}
1635  Callback_function(std::function<void(FreeArgs...)>&& f_): f(std::move(f_)) {}
1636 };
1637 
1638 // generic class for callable objects such as lambdas
1639 template <class Lambda, class... FreeArgs>
1640 class Callback_lambda: public CallbackArg<FreeArgs...> {
1641  // making 'l' mutable means that Callback_lamdba objects can contain
1642  // mutable lambda expressions
1643  mutable Lambda l;
1644 public:
1645  void dispatch(typename Cgu::Param<FreeArgs>::ParamType... free_args) const {l(free_args...);}
1646  template <class L> Callback_lambda(L&& l_): l(std::forward<L>(l_)) {}
1647 };
1648 
1649 /* Convenience functions making callback objects on freestore. These
1650  * can for example be passed as the first argument of the
1651  * Thread::start() method in thread.h. They are also used by the
1652  * Callback::post() function.
1653 */
1654 
1655 /**
1656  * A convenience function to make Callback::CallbackArg objects
1657  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1658  * is exhausted and the system throws in that case. This exception
1659  * will not be thrown if the library has been installed using the
1660  * \--with-glib-memory-slices-no-compat configuration option (instead
1661  * glib will terminate the program if it is unable to obtain memory
1662  * from the operating system).
1663  */
1664 template <class T, class... FreeArgs>
1665 CallbackArg<FreeArgs...>* make(T& t,
1666  void (T::*func)(FreeArgs...)) {
1667  return new Callback0<T, FreeArgs...>{t, func};
1668 }
1669 
1670 /**
1671  * DEPRECATED.
1672  *
1673  * Since this function constructs a callback which does not take a
1674  * bound argument, it is a synonym for make() (the two are identical).
1675  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1676  * is exhausted and the system throws in that case. This exception
1677  * will not be thrown if the library has been installed using the
1678  * \--with-glib-memory-slices-no-compat configuration option (instead
1679  * glib will terminate the program if it is unable to obtain memory
1680  * from the operating system).
1681  */
1682 template <class T, class... FreeArgs>
1683 CallbackArg<FreeArgs...>* make_val(T& t,
1684  void (T::*func)(FreeArgs...)) {
1685  return new Callback0<T, FreeArgs...>{t, func};
1686 }
1687 
1688 /**
1689  * Since this function constructs a callback which does not take a
1690  * bound argument, it is a synonym for make() (the two are identical).
1691  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1692  * is exhausted and the system throws in that case. This exception
1693  * will not be thrown if the library has been installed using the
1694  * \--with-glib-memory-slices-no-compat configuration option (instead
1695  * glib will terminate the program if it is unable to obtain memory
1696  * from the operating system).
1697  *
1698  * Since 2.0.0-rc3
1699  */
1700 template <class T, class... FreeArgs>
1701 CallbackArg<FreeArgs...>* make_ref(T& t,
1702  void (T::*func)(FreeArgs...)) {
1703  return new Callback0<T, FreeArgs...>{t, func};
1704 }
1705 
1706 /**
1707  * A convenience function to make Callback::CallbackArg objects
1708  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1709  * is exhausted and the system throws in that case (this exception
1710  * will not be thrown if the library has been installed using the
1711  * \--with-glib-memory-slices-no-compat configuration option: instead
1712  * glib will terminate the program if it is unable to obtain memory
1713  * from the operating system). It will also throw if the copy
1714  * constructor of a bound argument throws and it is not a reference
1715  * argument.
1716  */
1717 template <class T, class BoundArg, class... FreeArgs>
1718 CallbackArg<FreeArgs...>* make(T& t,
1719  void (T::*func)(BoundArg, FreeArgs...),
1720  BoundArg arg) {
1721  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
1722 }
1723 
1724 /**
1725  * DEPRECATED: use Callback::make_ref() instead.
1726  *
1727  * An alternative function to make Callback::CallbackArg objects,
1728  * which is for use where a target function receives an argument of
1729  * class type by value which is to be a bound argument, so the
1730  * compiler is not able to carry out copy elision when constructing
1731  * the callback object.
1732  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1733  * is exhausted and the system throws in that case (this exception
1734  * will not be thrown if the library has been installed using the
1735  * \--with-glib-memory-slices-no-compat configuration option: instead
1736  * glib will terminate the program if it is unable to obtain memory
1737  * from the operating system). It will also throw if the copy
1738  * constructor of a bound argument throws and it is not a reference
1739  * argument.
1740  */
1741 template <class T, class BoundArg, class... FreeArgs>
1742 CallbackArg<FreeArgs...>* make_val(T& t,
1743  void (T::*func)(BoundArg, FreeArgs...),
1744  const BoundArg& arg) {
1745  return new Callback1<false, T, BoundArg, FreeArgs...>{t, func, arg};
1746 }
1747 
1748 /**
1749  * An alternative function to make Callback::CallbackArg objects,
1750  * which is for use where a target function either receives a class
1751  * type bound argument by value, or receives a bound argument by
1752  * reference to const in a case where the generated CallbackArg object
1753  * is to store a copy of that argument instead of just keeping a
1754  * reference.
1755  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1756  * is exhausted and the system throws in that case (this exception
1757  * will not be thrown if the library has been installed using the
1758  * \--with-glib-memory-slices-no-compat configuration option: instead
1759  * glib will terminate the program if it is unable to obtain memory
1760  * from the operating system). It will also throw if the copy or move
1761  * constructor of a bound argument throws.
1762  *
1763  * Since 2.0.0-rc3
1764  */
1765 template <class T, class BoundArg, class Arg, class... FreeArgs>
1766 CallbackArg<FreeArgs...>* make_ref(T& t,
1767  void (T::*func)(BoundArg, FreeArgs...),
1768  Arg&& arg) {
1769  return new Callback1<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
1770 }
1771 
1772 /**
1773  * A convenience function to make Callback::CallbackArg objects
1774  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1775  * is exhausted and the system throws in that case (this exception
1776  * will not be thrown if the library has been installed using the
1777  * \--with-glib-memory-slices-no-compat configuration option: instead
1778  * glib will terminate the program if it is unable to obtain memory
1779  * from the operating system). It will also throw if the copy
1780  * constructor of a bound argument throws and it is not a reference
1781  * argument.
1782  */
1783 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1784 CallbackArg<FreeArgs...>* make(T& t,
1785  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1786  BoundArg1 arg1,
1787  BoundArg2 arg2) {
1788  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
1789 }
1790 
1791 /**
1792  * DEPRECATED: use Callback::make_ref() instead.
1793  *
1794  * An alternative function to make Callback::CallbackArg objects,
1795  * which is for use where a target function receives an argument of
1796  * class type by value which is to be a bound argument, so the
1797  * compiler is not able to carry out copy elision when constructing
1798  * the callback object.
1799  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1800  * is exhausted and the system throws in that case (this exception
1801  * will not be thrown if the library has been installed using the
1802  * \--with-glib-memory-slices-no-compat configuration option: instead
1803  * glib will terminate the program if it is unable to obtain memory
1804  * from the operating system). It will also throw if the copy
1805  * constructor of a bound argument throws and it is not a reference
1806  * argument.
1807  */
1808 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
1809 CallbackArg<FreeArgs...>* make_val(T& t,
1810  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1811  const BoundArg1& arg1,
1812  const BoundArg2& arg2) {
1813  return new Callback2<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
1814 }
1815 
1816 /**
1817  * An alternative function to make Callback::CallbackArg objects,
1818  * which is for use where a target function either receives a class
1819  * type bound argument by value, or receives a bound argument by
1820  * reference to const in a case where the generated CallbackArg object
1821  * is to store a copy of that argument instead of just keeping a
1822  * reference.
1823  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1824  * is exhausted and the system throws in that case (this exception
1825  * will not be thrown if the library has been installed using the
1826  * \--with-glib-memory-slices-no-compat configuration option: instead
1827  * glib will terminate the program if it is unable to obtain memory
1828  * from the operating system). It will also throw if the copy or move
1829  * constructor of a bound argument throws.
1830  *
1831  * Since 2.0.0-rc3
1832  */
1833 template <class T, class BoundArg1, class BoundArg2,
1834  class Arg1, class Arg2, class... FreeArgs>
1835 CallbackArg<FreeArgs...>* make_ref(T& t,
1836  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...),
1837  Arg1&& arg1,
1838  Arg2&& arg2) {
1839  return new Callback2<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
1840  std::forward<Arg1>(arg1),
1841  std::forward<Arg2>(arg2)};
1842 }
1843 
1844 /**
1845  * A convenience function to make Callback::CallbackArg objects
1846  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1847  * is exhausted and the system throws in that case (this exception
1848  * will not be thrown if the library has been installed using the
1849  * \--with-glib-memory-slices-no-compat configuration option: instead
1850  * glib will terminate the program if it is unable to obtain memory
1851  * from the operating system). It will also throw if the copy
1852  * constructor of a bound argument throws and it is not a reference
1853  * argument.
1854  */
1855 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1856 CallbackArg<FreeArgs...>* make(T& t,
1857  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1858  BoundArg1 arg1,
1859  BoundArg2 arg2,
1860  BoundArg3 arg3) {
1861  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
1862 }
1863 
1864 /**
1865  * DEPRECATED: use Callback::make_ref() instead.
1866  *
1867  * An alternative function to make Callback::CallbackArg objects,
1868  * which is for use where a target function receives an argument of
1869  * class type by value which is to be a bound argument, so the
1870  * compiler is not able to carry out copy elision when constructing
1871  * the callback object.
1872  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1873  * is exhausted and the system throws in that case (this exception
1874  * will not be thrown if the library has been installed using the
1875  * \--with-glib-memory-slices-no-compat configuration option: instead
1876  * glib will terminate the program if it is unable to obtain memory
1877  * from the operating system). It will also throw if the copy
1878  * constructor of a bound argument throws and it is not a reference
1879  * argument.
1880  */
1881 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
1882 CallbackArg<FreeArgs...>* make_val(T& t,
1883  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1884  const BoundArg1& arg1,
1885  const BoundArg2& arg2,
1886  const BoundArg3& arg3) {
1887  return new Callback3<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
1888 }
1889 
1890 /**
1891  * An alternative function to make Callback::CallbackArg objects,
1892  * which is for use where a target function either receives a class
1893  * type bound argument by value, or receives a bound argument by
1894  * reference to const in a case where the generated CallbackArg object
1895  * is to store a copy of that argument instead of just keeping a
1896  * reference.
1897  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1898  * is exhausted and the system throws in that case (this exception
1899  * will not be thrown if the library has been installed using the
1900  * \--with-glib-memory-slices-no-compat configuration option: instead
1901  * glib will terminate the program if it is unable to obtain memory
1902  * from the operating system). It will also throw if the copy or move
1903  * constructor of a bound argument throws.
1904  *
1905  * Since 2.0.0-rc3
1906  */
1907 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1908  class Arg1, class Arg2, class Arg3, class... FreeArgs>
1909 CallbackArg<FreeArgs...>* make_ref(T& t,
1910  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
1911  Arg1&& arg1,
1912  Arg2&& arg2,
1913  Arg3&& arg3) {
1914  return new Callback3<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
1915  std::forward<Arg1>(arg1),
1916  std::forward<Arg2>(arg2),
1917  std::forward<Arg3>(arg3)};
1918 }
1919 
1920 /**
1921  * A convenience function to make Callback::CallbackArg objects
1922  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1923  * is exhausted and the system throws in that case (this exception
1924  * will not be thrown if the library has been installed using the
1925  * \--with-glib-memory-slices-no-compat configuration option: instead
1926  * glib will terminate the program if it is unable to obtain memory
1927  * from the operating system). It will also throw if the copy
1928  * constructor of a bound argument throws and it is not a reference
1929  * argument.
1930  */
1931 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1932  class BoundArg4, class... FreeArgs>
1933 CallbackArg<FreeArgs...>* make(T& t,
1934  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1935  BoundArg4, FreeArgs...),
1936  BoundArg1 arg1,
1937  BoundArg2 arg2,
1938  BoundArg3 arg3,
1939  BoundArg4 arg4) {
1940  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
1941  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
1942 }
1943 
1944 /**
1945  * DEPRECATED: use Callback::make_ref() instead.
1946  *
1947  * An alternative function to make Callback::CallbackArg objects,
1948  * which is for use where a target function receives an argument of
1949  * class type by value which is to be a bound argument, so the
1950  * compiler is not able to carry out copy elision when constructing
1951  * the callback object.
1952  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1953  * is exhausted and the system throws in that case (this exception
1954  * will not be thrown if the library has been installed using the
1955  * \--with-glib-memory-slices-no-compat configuration option: instead
1956  * glib will terminate the program if it is unable to obtain memory
1957  * from the operating system). It will also throw if the copy
1958  * constructor of a bound argument throws and it is not a reference
1959  * argument.
1960  */
1961 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
1962  class BoundArg4, class... FreeArgs>
1963 CallbackArg<FreeArgs...>* make_val(T& t,
1964  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1965  BoundArg4, FreeArgs...),
1966  const BoundArg1& arg1,
1967  const BoundArg2& arg2,
1968  const BoundArg3& arg3,
1969  const BoundArg4& arg4) {
1970  return new Callback4<false, T, BoundArg1, BoundArg2, BoundArg3,
1971  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
1972 }
1973 
1974 /**
1975  * An alternative function to make Callback::CallbackArg objects,
1976  * which is for use where a target function either receives a class
1977  * type bound argument by value, or receives a bound argument by
1978  * reference to const in a case where the generated CallbackArg object
1979  * is to store a copy of that argument instead of just keeping a
1980  * reference.
1981  * @exception std::bad_alloc It might throw std::bad_alloc if memory
1982  * is exhausted and the system throws in that case (this exception
1983  * will not be thrown if the library has been installed using the
1984  * \--with-glib-memory-slices-no-compat configuration option: instead
1985  * glib will terminate the program if it is unable to obtain memory
1986  * from the operating system). It will also throw if the copy or move
1987  * constructor of a bound argument throws.
1988  *
1989  * Since 2.0.0-rc3
1990  */
1991 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
1992  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
1993 CallbackArg<FreeArgs...>* make_ref(T& t,
1994  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
1995  BoundArg4, FreeArgs...),
1996  Arg1&& arg1,
1997  Arg2&& arg2,
1998  Arg3&& arg3,
1999  Arg4&& arg4) {
2000  return new Callback4<true, T, BoundArg1, BoundArg2, BoundArg3,
2001  BoundArg4, FreeArgs...>{t, func,
2002  std::forward<Arg1>(arg1),
2003  std::forward<Arg2>(arg2),
2004  std::forward<Arg3>(arg3),
2005  std::forward<Arg4>(arg4)};
2006 }
2007 
2008 /**
2009  * A convenience function to make Callback::CallbackArg objects
2010  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2011  * is exhausted and the system throws in that case (this exception
2012  * will not be thrown if the library has been installed using the
2013  * \--with-glib-memory-slices-no-compat configuration option: instead
2014  * glib will terminate the program if it is unable to obtain memory
2015  * from the operating system). It will also throw if the copy
2016  * constructor of a bound argument throws and it is not a reference
2017  * argument.
2018  */
2019 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2020  class BoundArg4, class BoundArg5, class... FreeArgs>
2021 CallbackArg<FreeArgs...>* make(T& t,
2022  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2023  BoundArg4, BoundArg5, FreeArgs...),
2024  BoundArg1 arg1,
2025  BoundArg2 arg2,
2026  BoundArg3 arg3,
2027  BoundArg4 arg4,
2028  BoundArg5 arg5) {
2029  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
2030  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2031 }
2032 
2033 /**
2034  * DEPRECATED: use Callback::make_ref() instead.
2035  *
2036  * An alternative function to make Callback::CallbackArg objects,
2037  * which is for use where a target function receives an argument of
2038  * class type by value which is to be a bound argument, so the
2039  * compiler is not able to carry out copy elision when constructing
2040  * the callback object.
2041  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2042  * is exhausted and the system throws in that case (this exception
2043  * will not be thrown if the library has been installed using the
2044  * \--with-glib-memory-slices-no-compat configuration option: instead
2045  * glib will terminate the program if it is unable to obtain memory
2046  * from the operating system). It will also throw if the copy
2047  * constructor of a bound argument throws and it is not a reference
2048  * argument.
2049  */
2050 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2051  class BoundArg4, class BoundArg5, class... FreeArgs>
2052 CallbackArg<FreeArgs...>* make_val(T& t,
2053  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2054  BoundArg4, BoundArg5, FreeArgs...),
2055  const BoundArg1& arg1,
2056  const BoundArg2& arg2,
2057  const BoundArg3& arg3,
2058  const BoundArg4& arg4,
2059  const BoundArg5& arg5) {
2060  return new Callback5<false, T, BoundArg1, BoundArg2, BoundArg3,
2061  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2062 }
2063 
2064 /**
2065  * An alternative function to make Callback::CallbackArg objects,
2066  * which is for use where a target function either receives a class
2067  * type bound argument by value, or receives a bound argument by
2068  * reference to const in a case where the generated CallbackArg object
2069  * is to store a copy of that argument instead of just keeping a
2070  * reference.
2071  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2072  * is exhausted and the system throws in that case (this exception
2073  * will not be thrown if the library has been installed using the
2074  * \--with-glib-memory-slices-no-compat configuration option: instead
2075  * glib will terminate the program if it is unable to obtain memory
2076  * from the operating system). It will also throw if the copy or move
2077  * constructor of a bound argument throws.
2078  *
2079  * Since 2.0.0-rc3
2080  */
2081 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2082  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2083 CallbackArg<FreeArgs...>* make_ref(T& t,
2084  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2085  BoundArg4, BoundArg5, FreeArgs...),
2086  Arg1&& arg1,
2087  Arg2&& arg2,
2088  Arg3&& arg3,
2089  Arg4&& arg4,
2090  Arg5&& arg5) {
2091  return new Callback5<true, T, BoundArg1, BoundArg2, BoundArg3,
2092  BoundArg4, BoundArg5, FreeArgs...>{t, func,
2093  std::forward<Arg1>(arg1),
2094  std::forward<Arg2>(arg2),
2095  std::forward<Arg3>(arg3),
2096  std::forward<Arg4>(arg4),
2097  std::forward<Arg5>(arg5)};
2098 }
2099 
2100 /* const versions, for binding to const methods */
2101 
2102 /**
2103  * A convenience function to make Callback::CallbackArg objects
2104  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2105  * is exhausted and the system throws in that case. This exception
2106  * will not be thrown if the library has been installed using the
2107  * \--with-glib-memory-slices-no-compat configuration option (instead
2108  * glib will terminate the program if it is unable to obtain memory
2109  * from the operating system).
2110  */
2111 template <class T, class... FreeArgs>
2112 CallbackArg<FreeArgs...>* make(const T& t,
2113  void (T::*func)(FreeArgs...) const) {
2114  return new Callback0_const<T, FreeArgs...>{t, func};
2115 }
2116 
2117 /**
2118  * DEPRECATED.
2119  *
2120  * Since this function constructs a callback which does not take a
2121  * bound argument, it is a synonym for make() (the two are identical).
2122  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2123  * is exhausted and the system throws in that case. This exception
2124  * will not be thrown if the library has been installed using the
2125  * \--with-glib-memory-slices-no-compat configuration option (instead
2126  * glib will terminate the program if it is unable to obtain memory
2127  * from the operating system).
2128  */
2129 template <class T, class... FreeArgs>
2130 CallbackArg<FreeArgs...>* make_val(const T& t,
2131  void (T::*func)(FreeArgs...) const) {
2132  return new Callback0_const<T, FreeArgs...>{t, func};
2133 }
2134 
2135 /**
2136  * Since this function constructs a callback which does not take a
2137  * bound argument, it is a synonym for make() (the two are identical).
2138  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2139  * is exhausted and the system throws in that case. This exception
2140  * will not be thrown if the library has been installed using the
2141  * \--with-glib-memory-slices-no-compat configuration option (instead
2142  * glib will terminate the program if it is unable to obtain memory
2143  * from the operating system).
2144  *
2145  * Since 2.0.0-rc3
2146  */
2147 template <class T, class... FreeArgs>
2148 CallbackArg<FreeArgs...>* make_ref(const T& t,
2149  void (T::*func)(FreeArgs...) const) {
2150  return new Callback0_const<T, FreeArgs...>{t, func};
2151 }
2152 
2153 /**
2154  * A convenience function to make Callback::CallbackArg objects
2155  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2156  * is exhausted and the system throws in that case (this exception
2157  * will not be thrown if the library has been installed using the
2158  * \--with-glib-memory-slices-no-compat configuration option: instead
2159  * glib will terminate the program if it is unable to obtain memory
2160  * from the operating system). It will also throw if the copy
2161  * constructor of a bound argument throws and it is not a reference
2162  * argument.
2163  */
2164 template <class T, class BoundArg, class... FreeArgs>
2165 CallbackArg<FreeArgs...>* make(const T& t,
2166  void (T::*func)(BoundArg, FreeArgs...) const,
2167  BoundArg arg) {
2168  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
2169 }
2170 
2171 /**
2172  * DEPRECATED: use Callback::make_ref() instead.
2173  *
2174  * An alternative function to make Callback::CallbackArg objects,
2175  * which is for use where a target function receives an argument of
2176  * class type by value which is to be a bound argument, so the
2177  * compiler is not able to carry out copy elision when constructing
2178  * the callback object.
2179  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2180  * is exhausted and the system throws in that case (this exception
2181  * will not be thrown if the library has been installed using the
2182  * \--with-glib-memory-slices-no-compat configuration option: instead
2183  * glib will terminate the program if it is unable to obtain memory
2184  * from the operating system). It will also throw if the copy
2185  * constructor of a bound argument throws and it is not a reference
2186  * argument.
2187  */
2188 template <class T, class BoundArg, class... FreeArgs>
2189 CallbackArg<FreeArgs...>* make_val(const T& t,
2190  void (T::*func)(BoundArg, FreeArgs...) const,
2191  const BoundArg& arg) {
2192  return new Callback1_const<false, T, BoundArg, FreeArgs...>{t, func, arg};
2193 }
2194 
2195 /**
2196  * An alternative function to make Callback::CallbackArg objects,
2197  * which is for use where a target function either receives a class
2198  * type bound argument by value, or receives a bound argument by
2199  * reference to const in a case where the generated CallbackArg object
2200  * is to store a copy of that argument instead of just keeping a
2201  * reference.
2202  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2203  * is exhausted and the system throws in that case (this exception
2204  * will not be thrown if the library has been installed using the
2205  * \--with-glib-memory-slices-no-compat configuration option: instead
2206  * glib will terminate the program if it is unable to obtain memory
2207  * from the operating system). It will also throw if the copy or move
2208  * constructor of a bound argument throws.
2209  *
2210  * Since 2.0.0-rc3
2211  */
2212 template <class T, class BoundArg, class Arg, class... FreeArgs>
2213 CallbackArg<FreeArgs...>* make_ref(const T& t,
2214  void (T::*func)(BoundArg, FreeArgs...) const,
2215  Arg&& arg) {
2216  return new Callback1_const<true, T, BoundArg, FreeArgs...>{t, func, std::forward<Arg>(arg)};
2217 }
2218 
2219 /**
2220  * A convenience function to make Callback::CallbackArg objects
2221  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2222  * is exhausted and the system throws in that case (this exception
2223  * will not be thrown if the library has been installed using the
2224  * \--with-glib-memory-slices-no-compat configuration option: instead
2225  * glib will terminate the program if it is unable to obtain memory
2226  * from the operating system). It will also throw if the copy
2227  * constructor of a bound argument throws and it is not a reference
2228  * argument.
2229  */
2230 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
2231 CallbackArg<FreeArgs...>* make(const T& t,
2232  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2233  BoundArg1 arg1,
2234  BoundArg2 arg2) {
2235  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
2236 }
2237 
2238 /**
2239  * DEPRECATED: use Callback::make_ref() instead.
2240  *
2241  * An alternative function to make Callback::CallbackArg objects,
2242  * which is for use where a target function receives an argument of
2243  * class type by value which is to be a bound argument, so the
2244  * compiler is not able to carry out copy elision when constructing
2245  * the callback object.
2246  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2247  * is exhausted and the system throws in that case (this exception
2248  * will not be thrown if the library has been installed using the
2249  * \--with-glib-memory-slices-no-compat configuration option: instead
2250  * glib will terminate the program if it is unable to obtain memory
2251  * from the operating system). It will also throw if the copy
2252  * constructor of a bound argument throws and it is not a reference
2253  * argument.
2254  */
2255 template <class T, class BoundArg1, class BoundArg2, class... FreeArgs>
2256 CallbackArg<FreeArgs...>* make_val(const T& t,
2257  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2258  const BoundArg1& arg1,
2259  const BoundArg2& arg2) {
2260  return new Callback2_const<false, T, BoundArg1, BoundArg2, FreeArgs...>{t, func, arg1, arg2};
2261 }
2262 
2263 /**
2264  * An alternative function to make Callback::CallbackArg objects,
2265  * which is for use where a target function either receives a class
2266  * type bound argument by value, or receives a bound argument by
2267  * reference to const in a case where the generated CallbackArg object
2268  * is to store a copy of that argument instead of just keeping a
2269  * reference.
2270  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2271  * is exhausted and the system throws in that case (this exception
2272  * will not be thrown if the library has been installed using the
2273  * \--with-glib-memory-slices-no-compat configuration option: instead
2274  * glib will terminate the program if it is unable to obtain memory
2275  * from the operating system). It will also throw if the copy or move
2276  * constructor of a bound argument throws.
2277  *
2278  * Since 2.0.0-rc3
2279  */
2280 template <class T, class BoundArg1, class BoundArg2,
2281  class Arg1, class Arg2, class... FreeArgs>
2282 CallbackArg<FreeArgs...>* make_ref(const T& t,
2283  void (T::*func)(BoundArg1, BoundArg2, FreeArgs...) const,
2284  Arg1&& arg1,
2285  Arg2&& arg2) {
2286  return new Callback2_const<true, T, BoundArg1, BoundArg2, FreeArgs...>{t, func,
2287  std::forward<Arg1>(arg1),
2288  std::forward<Arg2>(arg2)};
2289 }
2290 
2291 /**
2292  * A convenience function to make Callback::CallbackArg objects
2293  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2294  * is exhausted and the system throws in that case (this exception
2295  * will not be thrown if the library has been installed using the
2296  * \--with-glib-memory-slices-no-compat configuration option: instead
2297  * glib will terminate the program if it is unable to obtain memory
2298  * from the operating system). It will also throw if the copy
2299  * constructor of a bound argument throws and it is not a reference
2300  * argument.
2301  */
2302 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2303 CallbackArg<FreeArgs...>* make(const T& t,
2304  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2305  BoundArg1 arg1,
2306  BoundArg2 arg2,
2307  BoundArg3 arg3) {
2308  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
2309 }
2310 
2311 /**
2312  * DEPRECATED: use Callback::make_ref() instead.
2313  *
2314  * An alternative function to make Callback::CallbackArg objects,
2315  * which is for use where a target function receives an argument of
2316  * class type by value which is to be a bound argument, so the
2317  * compiler is not able to carry out copy elision when constructing
2318  * the callback object.
2319  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2320  * is exhausted and the system throws in that case (this exception
2321  * will not be thrown if the library has been installed using the
2322  * \--with-glib-memory-slices-no-compat configuration option: instead
2323  * glib will terminate the program if it is unable to obtain memory
2324  * from the operating system). It will also throw if the copy
2325  * constructor of a bound argument throws and it is not a reference
2326  * argument.
2327  */
2328 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2329 CallbackArg<FreeArgs...>* make_val(const T& t,
2330  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2331  const BoundArg1& arg1,
2332  const BoundArg2& arg2,
2333  const BoundArg3& arg3) {
2334  return new Callback3_const<false, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func, arg1, arg2, arg3};
2335 }
2336 
2337 /**
2338  * An alternative function to make Callback::CallbackArg objects,
2339  * which is for use where a target function either receives a class
2340  * type bound argument by value, or receives a bound argument by
2341  * reference to const in a case where the generated CallbackArg object
2342  * is to store a copy of that argument instead of just keeping a
2343  * reference.
2344  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2345  * is exhausted and the system throws in that case (this exception
2346  * will not be thrown if the library has been installed using the
2347  * \--with-glib-memory-slices-no-compat configuration option: instead
2348  * glib will terminate the program if it is unable to obtain memory
2349  * from the operating system). It will also throw if the copy or move
2350  * constructor of a bound argument throws.
2351  *
2352  * Since 2.0.0-rc3
2353  */
2354 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2355  class Arg1, class Arg2, class Arg3, class... FreeArgs>
2356 CallbackArg<FreeArgs...>* make_ref(const T& t,
2357  void (T::*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const,
2358  Arg1&& arg1,
2359  Arg2&& arg2,
2360  Arg3&& arg3) {
2361  return new Callback3_const<true, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{t, func,
2362  std::forward<Arg1>(arg1),
2363  std::forward<Arg2>(arg2),
2364  std::forward<Arg3>(arg3)};
2365 }
2366 
2367 /**
2368  * A convenience function to make Callback::CallbackArg objects
2369  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2370  * is exhausted and the system throws in that case (this exception
2371  * will not be thrown if the library has been installed using the
2372  * \--with-glib-memory-slices-no-compat configuration option: instead
2373  * glib will terminate the program if it is unable to obtain memory
2374  * from the operating system). It will also throw if the copy
2375  * constructor of a bound argument throws and it is not a reference
2376  * argument.
2377  */
2378 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2379  class BoundArg4, class... FreeArgs>
2380 CallbackArg<FreeArgs...>* make(const T& t,
2381  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2382  BoundArg4, FreeArgs...) const,
2383  BoundArg1 arg1,
2384  BoundArg2 arg2,
2385  BoundArg3 arg3,
2386  BoundArg4 arg4) {
2387  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2388  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
2389 }
2390 
2391 /**
2392  * DEPRECATED: use Callback::make_ref() instead.
2393  *
2394  * An alternative function to make Callback::CallbackArg objects,
2395  * which is for use where a target function receives an argument of
2396  * class type by value which is to be a bound argument, so the
2397  * compiler is not able to carry out copy elision when constructing
2398  * the callback object.
2399  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2400  * is exhausted and the system throws in that case (this exception
2401  * will not be thrown if the library has been installed using the
2402  * \--with-glib-memory-slices-no-compat configuration option: instead
2403  * glib will terminate the program if it is unable to obtain memory
2404  * from the operating system). It will also throw if the copy
2405  * constructor of a bound argument throws and it is not a reference
2406  * argument.
2407  */
2408 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2409  class BoundArg4, class... FreeArgs>
2410 CallbackArg<FreeArgs...>* make_val(const T& t,
2411  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2412  BoundArg4, FreeArgs...) const,
2413  const BoundArg1& arg1,
2414  const BoundArg2& arg2,
2415  const BoundArg3& arg3,
2416  const BoundArg4& arg4) {
2417  return new Callback4_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2418  BoundArg4, FreeArgs...>{t, func, arg1, arg2, arg3, arg4};
2419 }
2420 
2421 /**
2422  * An alternative function to make Callback::CallbackArg objects,
2423  * which is for use where a target function either receives a class
2424  * type bound argument by value, or receives a bound argument by
2425  * reference to const in a case where the generated CallbackArg object
2426  * is to store a copy of that argument instead of just keeping a
2427  * reference.
2428  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2429  * is exhausted and the system throws in that case (this exception
2430  * will not be thrown if the library has been installed using the
2431  * \--with-glib-memory-slices-no-compat configuration option: instead
2432  * glib will terminate the program if it is unable to obtain memory
2433  * from the operating system). It will also throw if the copy or move
2434  * constructor of a bound argument throws.
2435  *
2436  * Since 2.0.0-rc3
2437  */
2438 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2439  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
2440 CallbackArg<FreeArgs...>* make_ref(const T& t,
2441  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2442  BoundArg4, FreeArgs...) const,
2443  Arg1&& arg1,
2444  Arg2&& arg2,
2445  Arg3&& arg3,
2446  Arg4&& arg4) {
2447  return new Callback4_const<true, T, BoundArg1, BoundArg2, BoundArg3,
2448  BoundArg4, FreeArgs...>{t, func,
2449  std::forward<Arg1>(arg1),
2450  std::forward<Arg2>(arg2),
2451  std::forward<Arg3>(arg3),
2452  std::forward<Arg4>(arg4)};
2453 }
2454 
2455 /**
2456  * A convenience function to make Callback::CallbackArg objects
2457  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2458  * is exhausted and the system throws in that case (this exception
2459  * will not be thrown if the library has been installed using the
2460  * \--with-glib-memory-slices-no-compat configuration option: instead
2461  * glib will terminate the program if it is unable to obtain memory
2462  * from the operating system). It will also throw if the copy
2463  * constructor of a bound argument throws and it is not a reference
2464  * argument.
2465  */
2466 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2467  class BoundArg4, class BoundArg5, class... FreeArgs>
2468 CallbackArg<FreeArgs...>* make(const T& t,
2469  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2470  BoundArg4, BoundArg5, FreeArgs...) const,
2471  BoundArg1 arg1,
2472  BoundArg2 arg2,
2473  BoundArg3 arg3,
2474  BoundArg4 arg4,
2475  BoundArg5 arg5) {
2476  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2477  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2478 }
2479 
2480 /**
2481  * DEPRECATED: use Callback::make_ref() instead.
2482  *
2483  * An alternative function to make Callback::CallbackArg objects,
2484  * which is for use where a target function receives an argument of
2485  * class type by value which is to be a bound argument, so the
2486  * compiler is not able to carry out copy elision when constructing
2487  * the callback object.
2488  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2489  * is exhausted and the system throws in that case (this exception
2490  * will not be thrown if the library has been installed using the
2491  * \--with-glib-memory-slices-no-compat configuration option: instead
2492  * glib will terminate the program if it is unable to obtain memory
2493  * from the operating system). It will also throw if the copy
2494  * constructor of a bound argument throws and it is not a reference
2495  * argument.
2496  */
2497 template <class T, class BoundArg1, class BoundArg2, class BoundArg3,
2498  class BoundArg4, class BoundArg5, class... FreeArgs>
2499 CallbackArg<FreeArgs...>* make_val(const T& t,
2500  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2501  BoundArg4, BoundArg5, FreeArgs...) const,
2502  const BoundArg1& arg1,
2503  const BoundArg2& arg2,
2504  const BoundArg3& arg3,
2505  const BoundArg4& arg4,
2506  const BoundArg5& arg5) {
2507  return new Callback5_const<false, T, BoundArg1, BoundArg2, BoundArg3,
2508  BoundArg4, BoundArg5, FreeArgs...>{t, func, arg1, arg2, arg3, arg4, arg5};
2509 }
2510 
2511 /**
2512  * An alternative function to make Callback::CallbackArg objects,
2513  * which is for use where a target function either receives a class
2514  * type bound argument by value, or receives a bound argument by
2515  * reference to const in a case where the generated CallbackArg object
2516  * is to store a copy of that argument instead of just keeping a
2517  * reference.
2518  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2519  * is exhausted and the system throws in that case (this exception
2520  * will not be thrown if the library has been installed using the
2521  * \--with-glib-memory-slices-no-compat configuration option: instead
2522  * glib will terminate the program if it is unable to obtain memory
2523  * from the operating system). It will also throw if the copy or move
2524  * constructor of a bound argument throws.
2525  *
2526  * Since 2.0.0-rc3
2527  */
2528 template <class T, class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2529  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2530 CallbackArg<FreeArgs...>* make_ref(const T& t,
2531  void (T::*func)(BoundArg1, BoundArg2, BoundArg3,
2532  BoundArg4, BoundArg5, FreeArgs...) const,
2533  Arg1&& arg1,
2534  Arg2&& arg2,
2535  Arg3&& arg3,
2536  Arg4&& arg4,
2537  Arg5&& arg5) {
2538  return new Callback5_const<true, T, BoundArg1, BoundArg2, BoundArg3,
2539  BoundArg4, BoundArg5, FreeArgs...>{t, func,
2540  std::forward<Arg1>(arg1),
2541  std::forward<Arg2>(arg2),
2542  std::forward<Arg3>(arg3),
2543  std::forward<Arg4>(arg4),
2544  std::forward<Arg5>(arg5)};
2545 }
2546 
2547 /* for static class methods and non-class functions */
2548 
2549 /**
2550  * A convenience function to make Callback::CallbackArg objects
2551  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2552  * is exhausted and the system throws in that case. This exception
2553  * will not be thrown if the library has been installed using the
2554  * \--with-glib-memory-slices-no-compat configuration option (instead
2555  * glib will terminate the program if it is unable to obtain memory
2556  * from the operating system).
2557  */
2558 template <class... FreeArgs>
2559 CallbackArg<FreeArgs...>* make(void (*func)(FreeArgs...)) {
2560  return new Callback0_static<FreeArgs...>{func};
2561 }
2562 
2563 /**
2564  * DEPRECATED.
2565  *
2566  * Since this function constructs a callback which does not take a
2567  * bound argument, it is a synonym for make() (the two are identical).
2568  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2569  * is exhausted and the system throws in that case. This exception
2570  * will not be thrown if the library has been installed using the
2571  * \--with-glib-memory-slices-no-compat configuration option (instead
2572  * glib will terminate the program if it is unable to obtain memory
2573  * from the operating system).
2574  */
2575 template <class... FreeArgs>
2576 CallbackArg<FreeArgs...>* make_val(void (*func)(FreeArgs...)) {
2577  return new Callback0_static<FreeArgs...>{func};
2578 }
2579 
2580 /**
2581  * Since this function constructs a callback which does not take a
2582  * bound argument, it is a synonym for make() (the two are identical).
2583  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2584  * is exhausted and the system throws in that case. This exception
2585  * will not be thrown if the library has been installed using the
2586  * \--with-glib-memory-slices-no-compat configuration option (instead
2587  * glib will terminate the program if it is unable to obtain memory
2588  * from the operating system).
2589  *
2590  * Since 2.0.0-rc3
2591  */
2592 template <class... FreeArgs>
2593 CallbackArg<FreeArgs...>* make_ref(void (*func)(FreeArgs...)) {
2594  return new Callback0_static<FreeArgs...>{func};
2595 }
2596 
2597 /**
2598  * A convenience function to make Callback::CallbackArg objects
2599  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2600  * is exhausted and the system throws in that case (this exception
2601  * will not be thrown if the library has been installed using the
2602  * \--with-glib-memory-slices-no-compat configuration option: instead
2603  * glib will terminate the program if it is unable to obtain memory
2604  * from the operating system). It will also throw if the copy
2605  * constructor of a bound argument throws and it is not a reference
2606  * argument.
2607  */
2608 template <class BoundArg, class... FreeArgs>
2609 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg, FreeArgs...),
2610  BoundArg arg) {
2611  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
2612 }
2613 
2614 /**
2615  * DEPRECATED: use Callback::make_ref() instead.
2616  *
2617  * An alternative function to make Callback::CallbackArg objects,
2618  * which is for use where a target function receives an argument of
2619  * class type by value which is to be a bound argument, so the
2620  * compiler is not able to carry out copy elision when constructing
2621  * the callback object.
2622  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2623  * is exhausted and the system throws in that case (this exception
2624  * will not be thrown if the library has been installed using the
2625  * \--with-glib-memory-slices-no-compat configuration option: instead
2626  * glib will terminate the program if it is unable to obtain memory
2627  * from the operating system). It will also throw if the copy
2628  * constructor of a bound argument throws and it is not a reference
2629  * argument.
2630  */
2631 template <class BoundArg, class... FreeArgs>
2632 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg, FreeArgs...),
2633  const BoundArg& arg) {
2634  return new Callback1_static<false, BoundArg, FreeArgs...>{func, arg};
2635 }
2636 
2637 /**
2638  * An alternative function to make Callback::CallbackArg objects,
2639  * which is for use where a target function either receives a class
2640  * type bound argument by value, or receives a bound argument by
2641  * reference to const in a case where the generated CallbackArg object
2642  * is to store a copy of that argument instead of just keeping a
2643  * reference.
2644  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2645  * is exhausted and the system throws in that case (this exception
2646  * will not be thrown if the library has been installed using the
2647  * \--with-glib-memory-slices-no-compat configuration option: instead
2648  * glib will terminate the program if it is unable to obtain memory
2649  * from the operating system). It will also throw if the copy or move
2650  * constructor of a bound argument throws.
2651  *
2652  * Since 2.0.0-rc3
2653  */
2654 template <class BoundArg, class Arg, class... FreeArgs>
2655 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg, FreeArgs...),
2656  Arg&& arg) {
2657  return new Callback1_static<true, BoundArg, FreeArgs...>{func, std::forward<Arg>(arg)};
2658 }
2659 
2660 /**
2661  * A convenience function to make Callback::CallbackArg objects
2662  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2663  * is exhausted and the system throws in that case (this exception
2664  * will not be thrown if the library has been installed using the
2665  * \--with-glib-memory-slices-no-compat configuration option: instead
2666  * glib will terminate the program if it is unable to obtain memory
2667  * from the operating system). It will also throw if the copy
2668  * constructor of a bound argument throws and it is not a reference
2669  * argument.
2670  */
2671 template <class BoundArg1, class BoundArg2, class... FreeArgs>
2672 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2673  BoundArg1 arg1,
2674  BoundArg2 arg2) {
2675  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
2676 }
2677 
2678 /**
2679  * DEPRECATED: use Callback::make_ref() instead.
2680  *
2681  * An alternative function to make Callback::CallbackArg objects,
2682  * which is for use where a target function receives an argument of
2683  * class type by value which is to be a bound argument, so the
2684  * compiler is not able to carry out copy elision when constructing
2685  * the callback object.
2686  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2687  * is exhausted and the system throws in that case (this exception
2688  * will not be thrown if the library has been installed using the
2689  * \--with-glib-memory-slices-no-compat configuration option: instead
2690  * glib will terminate the program if it is unable to obtain memory
2691  * from the operating system). It will also throw if the copy
2692  * constructor of a bound argument throws and it is not a reference
2693  * argument.
2694  */
2695 template <class BoundArg1, class BoundArg2, class... FreeArgs>
2696 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2697  const BoundArg1& arg1,
2698  const BoundArg2& arg2) {
2699  return new Callback2_static<false, BoundArg1, BoundArg2, FreeArgs...>{func, arg1, arg2};
2700 }
2701 
2702 /**
2703  * An alternative function to make Callback::CallbackArg objects,
2704  * which is for use where a target function either receives a class
2705  * type bound argument by value, or receives a bound argument by
2706  * reference to const in a case where the generated CallbackArg object
2707  * is to store a copy of that argument instead of just keeping a
2708  * reference.
2709  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2710  * is exhausted and the system throws in that case (this exception
2711  * will not be thrown if the library has been installed using the
2712  * \--with-glib-memory-slices-no-compat configuration option: instead
2713  * glib will terminate the program if it is unable to obtain memory
2714  * from the operating system). It will also throw if the copy or move
2715  * constructor of a bound argument throws.
2716  *
2717  * Since 2.0.0-rc3
2718  */
2719 template <class BoundArg1, class BoundArg2, class Arg1, class Arg2, class... FreeArgs>
2720 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, FreeArgs...),
2721  Arg1&& arg1,
2722  Arg2&& arg2) {
2723  return new Callback2_static<true, BoundArg1, BoundArg2, FreeArgs...>{func,
2724  std::forward<Arg1>(arg1),
2725  std::forward<Arg2>(arg2)};
2726 }
2727 
2728 /**
2729  * A convenience function to make Callback::CallbackArg objects
2730  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2731  * is exhausted and the system throws in that case (this exception
2732  * will not be thrown if the library has been installed using the
2733  * \--with-glib-memory-slices-no-compat configuration option: instead
2734  * glib will terminate the program if it is unable to obtain memory
2735  * from the operating system). It will also throw if the copy
2736  * constructor of a bound argument throws and it is not a reference
2737  * argument.
2738  */
2739 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2740 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2741  BoundArg1 arg1,
2742  BoundArg2 arg2,
2743  BoundArg3 arg3) {
2744  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
2745 }
2746 
2747 /**
2748  * DEPRECATED: use Callback::make_ref() instead.
2749  *
2750  * An alternative function to make Callback::CallbackArg objects,
2751  * which is for use where a target function receives an argument of
2752  * class type by value which is to be a bound argument, so the
2753  * compiler is not able to carry out copy elision when constructing
2754  * the callback object.
2755  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2756  * is exhausted and the system throws in that case (this exception
2757  * will not be thrown if the library has been installed using the
2758  * \--with-glib-memory-slices-no-compat configuration option: instead
2759  * glib will terminate the program if it is unable to obtain memory
2760  * from the operating system). It will also throw if the copy
2761  * constructor of a bound argument throws and it is not a reference
2762  * argument.
2763  */
2764 template <class BoundArg1, class BoundArg2, class BoundArg3, class... FreeArgs>
2765 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2766  const BoundArg1& arg1,
2767  const BoundArg2& arg2,
2768  const BoundArg3& arg3) {
2769  return new Callback3_static<false, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func, arg1, arg2, arg3};
2770 }
2771 
2772 /**
2773  * An alternative function to make Callback::CallbackArg objects,
2774  * which is for use where a target function either receives a class
2775  * type bound argument by value, or receives a bound argument by
2776  * reference to const in a case where the generated CallbackArg object
2777  * is to store a copy of that argument instead of just keeping a
2778  * reference.
2779  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2780  * is exhausted and the system throws in that case (this exception
2781  * will not be thrown if the library has been installed using the
2782  * \--with-glib-memory-slices-no-compat configuration option: instead
2783  * glib will terminate the program if it is unable to obtain memory
2784  * from the operating system). It will also throw if the copy or move
2785  * constructor of a bound argument throws.
2786  *
2787  * Since 2.0.0-rc3
2788  */
2789 template <class BoundArg1, class BoundArg2, class BoundArg3,
2790  class Arg1, class Arg2, class Arg3, class... FreeArgs>
2791 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...),
2792  Arg1&& arg1,
2793  Arg2&& arg2,
2794  Arg3&& arg3) {
2795  return new Callback3_static<true, BoundArg1, BoundArg2, BoundArg3, FreeArgs...>{func,
2796  std::forward<Arg1>(arg1),
2797  std::forward<Arg2>(arg2),
2798  std::forward<Arg3>(arg3)};
2799 }
2800 
2801 /**
2802  * A convenience function to make Callback::CallbackArg objects
2803  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2804  * is exhausted and the system throws in that case (this exception
2805  * will not be thrown if the library has been installed using the
2806  * \--with-glib-memory-slices-no-compat configuration option: instead
2807  * glib will terminate the program if it is unable to obtain memory
2808  * from the operating system). It will also throw if the copy
2809  * constructor of a bound argument throws and it is not a reference
2810  * argument.
2811  */
2812 template <class BoundArg1, class BoundArg2, class BoundArg3,
2813  class BoundArg4, class... FreeArgs>
2814 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2815  BoundArg4, FreeArgs...),
2816  BoundArg1 arg1,
2817  BoundArg2 arg2,
2818  BoundArg3 arg3,
2819  BoundArg4 arg4) {
2820  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
2821  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
2822 }
2823 
2824 /**
2825  * DEPRECATED: use Callback::make_ref() instead.
2826  *
2827  * An alternative function to make Callback::CallbackArg objects,
2828  * which is for use where a target function receives an argument of
2829  * class type by value which is to be a bound argument, so the
2830  * compiler is not able to carry out copy elision when constructing
2831  * the callback object.
2832  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2833  * is exhausted and the system throws in that case (this exception
2834  * will not be thrown if the library has been installed using the
2835  * \--with-glib-memory-slices-no-compat configuration option: instead
2836  * glib will terminate the program if it is unable to obtain memory
2837  * from the operating system). It will also throw if the copy
2838  * constructor of a bound argument throws and it is not a reference
2839  * argument.
2840  */
2841 template <class BoundArg1, class BoundArg2, class BoundArg3,
2842  class BoundArg4, class... FreeArgs>
2843 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2844  BoundArg4, FreeArgs...),
2845  const BoundArg1& arg1,
2846  const BoundArg2& arg2,
2847  const BoundArg3& arg3,
2848  const BoundArg4& arg4) {
2849  return new Callback4_static<false, BoundArg1, BoundArg2, BoundArg3,
2850  BoundArg4, FreeArgs...>{func, arg1, arg2, arg3, arg4};
2851 }
2852 
2853 /**
2854  * An alternative function to make Callback::CallbackArg objects,
2855  * which is for use where a target function either receives a class
2856  * type bound argument by value, or receives a bound argument by
2857  * reference to const in a case where the generated CallbackArg object
2858  * is to store a copy of that argument instead of just keeping a
2859  * reference.
2860  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2861  * is exhausted and the system throws in that case (this exception
2862  * will not be thrown if the library has been installed using the
2863  * \--with-glib-memory-slices-no-compat configuration option: instead
2864  * glib will terminate the program if it is unable to obtain memory
2865  * from the operating system). It will also throw if the copy or move
2866  * constructor of a bound argument throws.
2867  *
2868  * Since 2.0.0-rc3
2869  */
2870 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4,
2871  class Arg1, class Arg2, class Arg3, class Arg4, class... FreeArgs>
2872 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2873  BoundArg4, FreeArgs...),
2874  Arg1&& arg1,
2875  Arg2&& arg2,
2876  Arg3&& arg3,
2877  Arg4&& arg4) {
2878  return new Callback4_static<true, BoundArg1, BoundArg2, BoundArg3,
2879  BoundArg4, FreeArgs...>{func,
2880  std::forward<Arg1>(arg1),
2881  std::forward<Arg2>(arg2),
2882  std::forward<Arg3>(arg3),
2883  std::forward<Arg4>(arg4)};
2884 }
2885 
2886 /**
2887  * A convenience function to make Callback::CallbackArg objects
2888  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2889  * is exhausted and the system throws in that case (this exception
2890  * will not be thrown if the library has been installed using the
2891  * \--with-glib-memory-slices-no-compat configuration option: instead
2892  * glib will terminate the program if it is unable to obtain memory
2893  * from the operating system). It will also throw if the copy
2894  * constructor of a bound argument throws and it is not a reference
2895  * argument.
2896  */
2897 template <class BoundArg1, class BoundArg2, class BoundArg3,
2898  class BoundArg4, class BoundArg5, class... FreeArgs>
2899 CallbackArg<FreeArgs...>* make(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2900  BoundArg4, BoundArg5, FreeArgs...),
2901  BoundArg1 arg1,
2902  BoundArg2 arg2,
2903  BoundArg3 arg3,
2904  BoundArg4 arg4,
2905  BoundArg5 arg5) {
2906  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
2907  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
2908 }
2909 
2910 /**
2911  * DEPRECATED: use Callback::make_ref() instead.
2912  *
2913  * An alternative function to make Callback::CallbackArg objects,
2914  * which is for use where a target function receives an argument of
2915  * class type by value which is to be a bound argument, so the
2916  * compiler is not able to carry out copy elision when constructing
2917  * the callback object.
2918  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2919  * is exhausted and the system throws in that case (this exception
2920  * will not be thrown if the library has been installed using the
2921  * \--with-glib-memory-slices-no-compat configuration option: instead
2922  * glib will terminate the program if it is unable to obtain memory
2923  * from the operating system). It will also throw if the copy
2924  * constructor of a bound argument throws and it is not a reference
2925  * argument.
2926  */
2927 template <class BoundArg1, class BoundArg2, class BoundArg3,
2928  class BoundArg4, class BoundArg5, class... FreeArgs>
2929 CallbackArg<FreeArgs...>* make_val(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2930  BoundArg4, BoundArg5, FreeArgs...),
2931  const BoundArg1& arg1,
2932  const BoundArg2& arg2,
2933  const BoundArg3& arg3,
2934  const BoundArg4& arg4,
2935  const BoundArg5& arg5) {
2936  return new Callback5_static<false, BoundArg1, BoundArg2, BoundArg3,
2937  BoundArg4, BoundArg5, FreeArgs...>{func, arg1, arg2, arg3, arg4, arg5};
2938 }
2939 
2940 /**
2941  * An alternative function to make Callback::CallbackArg objects,
2942  * which is for use where a target function either receives a class
2943  * type bound argument by value, or receives a bound argument by
2944  * reference to const in a case where the generated CallbackArg object
2945  * is to store a copy of that argument instead of just keeping a
2946  * reference.
2947  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2948  * is exhausted and the system throws in that case (this exception
2949  * will not be thrown if the library has been installed using the
2950  * \--with-glib-memory-slices-no-compat configuration option: instead
2951  * glib will terminate the program if it is unable to obtain memory
2952  * from the operating system). It will also throw if the copy or move
2953  * constructor of a bound argument throws.
2954  *
2955  * Since 2.0.0-rc3
2956  */
2957 template <class BoundArg1, class BoundArg2, class BoundArg3, class BoundArg4, class BoundArg5,
2958  class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class... FreeArgs>
2959 CallbackArg<FreeArgs...>* make_ref(void (*func)(BoundArg1, BoundArg2, BoundArg3,
2960  BoundArg4, BoundArg5, FreeArgs...),
2961  Arg1&& arg1,
2962  Arg2&& arg2,
2963  Arg3&& arg3,
2964  Arg4&& arg4,
2965  Arg5&& arg5) {
2966  return new Callback5_static<true, BoundArg1, BoundArg2, BoundArg3,
2967  BoundArg4, BoundArg5, FreeArgs...>{func,
2968  std::forward<Arg1>(arg1),
2969  std::forward<Arg2>(arg2),
2970  std::forward<Arg3>(arg3),
2971  std::forward<Arg4>(arg4),
2972  std::forward<Arg5>(arg5)};
2973 }
2974 
2975 /* for std::function objects */
2976 
2977 /**
2978  * A convenience function to make Callback::CallbackArg objects from
2979  * std::function objects.
2980  * @exception std::bad_alloc It might throw std::bad_alloc if memory
2981  * is exhausted and the system throws in that case (this exception
2982  * will not be thrown if the library has been installed using the
2983  * \--with-glib-memory-slices-no-compat configuration option: instead
2984  * glib will terminate the program if it is unable to obtain memory
2985  * from the operating system). It will also throw if the copy
2986  * constructor of a bound argument throws and it is not a reference
2987  * argument.
2988  */
2989 template <class... FreeArgs>
2990 CallbackArg<FreeArgs...>* make(const std::function<void(FreeArgs...)>& f) {
2991  return new Callback_function<FreeArgs...>{f};
2992 }
2993 
2994 /**
2995  * DEPRECATED.
2996  *
2997  * A convenience function to make Callback::Callback objects from
2998  * std::function objects. Since this function takes no bound argument
2999  * (and bound arguments are bound into the std::function object), it
3000  * is a synonym for make() (the two are identical).
3001  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3002  * is exhausted and the system throws in that case (this exception
3003  * will not be thrown if the library has been installed using the
3004  * \--with-glib-memory-slices-no-compat configuration option: instead
3005  * glib will terminate the program if it is unable to obtain memory
3006  * from the operating system). It will also throw if the copy
3007  * constructor of a bound argument throws and it is not a reference
3008  * argument.
3009  */
3010 template <class... FreeArgs>
3011 CallbackArg<FreeArgs...>* make_val(const std::function<void(FreeArgs...)>& f) {
3012  return new Callback_function<FreeArgs...>{f};
3013 }
3014 
3015 /**
3016  * A convenience function to make Callback::Callback objects from
3017  * std::function objects. Since this function takes no bound argument
3018  * (and bound arguments are bound into the std::function object), it
3019  * is a synonym for make() (the two are identical).
3020  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3021  * is exhausted and the system throws in that case (this exception
3022  * will not be thrown if the library has been installed using the
3023  * \--with-glib-memory-slices-no-compat configuration option: instead
3024  * glib will terminate the program if it is unable to obtain memory
3025  * from the operating system). It will also throw if the copy
3026  * constructor of a bound argument throws and it is not a reference
3027  * argument.
3028  */
3029 template <class... FreeArgs>
3030 CallbackArg<FreeArgs...>* make_ref(const std::function<void(FreeArgs...)>& f) {
3031  return new Callback_function<FreeArgs...>{f};
3032 }
3033 
3034 /**
3035  * A convenience function to make Callback::CallbackArg objects from
3036  * std::function objects.
3037  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3038  * is exhausted and the system throws in that case (this exception
3039  * will not be thrown if the library has been installed using the
3040  * \--with-glib-memory-slices-no-compat configuration option: instead
3041  * glib will terminate the program if it is unable to obtain memory
3042  * from the operating system). It will also throw if the copy
3043  * constructor of a bound argument throws and it is not a reference
3044  * argument.
3045  */
3046 template <class... FreeArgs>
3047 CallbackArg<FreeArgs...>* make(std::function<void(FreeArgs...)>&& f) {
3048  return new Callback_function<FreeArgs...>{std::move(f)};
3049 }
3050 
3051 /**
3052  * DEPRECATED.
3053  *
3054  * A convenience function to make Callback::Callback objects from
3055  * std::function objects. Since this function takes no bound argument
3056  * (and bound arguments are bound into the std::function object), it
3057  * is a synonym for make() (the two are identical).
3058  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3059  * is exhausted and the system throws in that case (this exception
3060  * will not be thrown if the library has been installed using the
3061  * \--with-glib-memory-slices-no-compat configuration option: instead
3062  * glib will terminate the program if it is unable to obtain memory
3063  * from the operating system). It will also throw if the copy or move
3064  * constructor of a bound argument throws and it is not a reference
3065  * argument.
3066  */
3067 template <class... FreeArgs>
3068 CallbackArg<FreeArgs...>* make_val(std::function<void(FreeArgs...)>&& f) {
3069  return new Callback_function<FreeArgs...>{std::move(f)};
3070 }
3071 
3072 /**
3073  * A convenience function to make Callback::Callback objects from
3074  * std::function objects. Since this function takes no bound argument
3075  * (and bound arguments are bound into the std::function object), it
3076  * is a synonym for make() (the two are identical).
3077  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3078  * is exhausted and the system throws in that case (this exception
3079  * will not be thrown if the library has been installed using the
3080  * \--with-glib-memory-slices-no-compat configuration option: instead
3081  * glib will terminate the program if it is unable to obtain memory
3082  * from the operating system). It will also throw if the copy or move
3083  * constructor of a bound argument throws and it is not a reference
3084  * argument.
3085  */
3086 template <class... FreeArgs>
3087 CallbackArg<FreeArgs...>* make_ref(std::function<void(FreeArgs...)>&& f) {
3088  return new Callback_function<FreeArgs...>{std::move(f)};
3089 }
3090 
3091 // This helper function to construct Callback_lambda objects could be
3092 // implemented as a further overload of Callback::make(). No best
3093 // match ambiguities would arise, because even when Callback::make()
3094 // is passed a function pointer without bound arguments, the overload
3095 // of Callback::make taking a function pointer (as opposed to a
3096 // generic callable object) would still comprise the best match.
3097 // However, to construct Callback_lambda objects, the unbound
3098 // arguments need to be specified by hand, which doesn't happen with
3099 // Callback::make() (it would only be necessary to specify an explicit
3100 // type where a mutable reference argument is to be bound to the
3101 // callback object). It seems to me to be less confusing to the user
3102 // therefore to have a separate Callback::lambda() helper function.
3103 // However, if you disagree please let me know.
3104 
3105 // template parameter packs do not need to be placed last in the case
3106 // of function templates, as type deduction is available for the last
3107 // parameter: there is in fact no function parameter pack in
3108 // Callback::lambda() (function parameter packs must come last).
3109 /**
3110  * A convenience function to make Callback::CallbackArg objects from
3111  * C++11/14 lambda expressions, or from any other arbitrary callable
3112  * object. The types of the unbound arguments (if any) must be
3113  * explicitly specified as template parameters, as they cannot be
3114  * deduced. From version 2.0.10, this function can be called for
3115  * lambda expressions which are declared mutable (in version 2.0.9,
3116  * this function could only be called for non-mutable lambda
3117  * expressions). From version 2.0.16, this function can be passed
3118  * callable objects which are lvalues as well as rvalues (prior to
3119  * version 2.0.16, it could only be passed callable objects which are
3120  * rvalues).
3121  * @exception std::bad_alloc It might throw std::bad_alloc if memory
3122  * is exhausted and the system throws in that case (this exception
3123  * will not be thrown if the library has been installed using the
3124  * \--with-glib-memory-slices-no-compat configuration option: instead
3125  * glib will terminate the program if it is unable to obtain memory
3126  * from the operating system). It will also throw if the copy or move
3127  * constructor of an object captured by the lambda expression throws.
3128  *
3129  * Since 2.0.9
3130  */
3131 template <class... FreeArgs, class Lambda>
3132 CallbackArg<FreeArgs...>* lambda(Lambda&& l) {
3133  typedef typename std::remove_const<typename std::remove_reference<Lambda>::type>::type LType;
3134  return new Callback_lambda<LType, FreeArgs...>{std::forward<Lambda>(l)};
3135 }
3136 
3137 } // namespace Callback
3138 
3139 class Releaser;
3140 
3141 namespace Callback {
3142 
3143 /**
3144  * Posts a callback for execution by a glib main loop. It is
3145  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
3146  * has been called. glib >= 2.32 does not require g_thread_init() to
3147  * be called. This function will not throw.
3148  * @param cb The callback object. Ownership is taken of this object,
3149  * and it will be deleted when it has been finished with.
3150  * @param priority The priority to be given to the callback in the
3151  * main loop. In ascending order of priorities, priorities are
3152  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
3153  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
3154  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
3155  * callback will appear in the event list in the main loop, not the
3156  * priority which the OS will adopt
3157  * @param context The glib main loop context in which the callback is
3158  * to be executed (the default of NULL will cause the callback to be
3159  * executed in the main program loop, and this is usually what is
3160  * wanted).
3161  * @note 1. Cancellation of the receiving thread is blocked when the
3162  * callback executes.
3163  * @note 2. If the callback throws an exception, the exception will be
3164  * consumed to protect the main loop and a g_critical() warning will
3165  * be issued.
3166  */
3167 void post(const Callback* cb, gint priority = G_PRIORITY_DEFAULT_IDLE,
3168  GMainContext* context = 0);
3169 
3170 /**
3171  * Posts a callback for execution by a glib main loop. It is
3172  * thread-safe provided that (if glib < 2.32 is used) g_thread_init()
3173  * has been called. glib >= 2.32 does not require g_thread_init() to
3174  * be called. This function will not throw.
3175  * @param cb The callback object. Ownership is taken of this object,
3176  * and it will be deleted when it has been finished with.
3177  * @param r A Releaser object for automatic disconnection of the
3178  * callback before it executes in the main loop (mainly relevant if
3179  * the callback represents a non-static member function of an object
3180  * which may be destroyed before the callback executes).
3181  * @param priority The priority to be given to the callback in the
3182  * main loop. In ascending order of priorities, priorities are
3183  * G_PRIORITY_LOW, G_PRIORITY_DEFAULT_IDLE, G_PRIORITY_HIGH_IDLE,
3184  * G_PRIORITY_DEFAULT and G_PRIORITY_HIGH. The default is
3185  * G_PRIORITY_DEFAULT_IDLE. This determines the order in which the
3186  * callback will appear in the event list in the main loop, not the
3187  * priority which the OS will adopt.
3188  * @param context The glib main loop context in which the callback is
3189  * to be executed (the default of NULL will cause the callback to be
3190  * executed in the main program loop, and this is usually what is
3191  * wanted).
3192  * @exception std::bad_alloc This function might throw std::bad_alloc
3193  * if memory is exhausted and the system throws in that case. If it
3194  * does so, the Callback object will be disposed of.
3195  * @exception Cgu::Thread::MutexError This function might throw
3196  * Cgu:Thread::MutexError if initialisation of the mutex in a
3197  * SafeEmitterArg object constructed by this function fails. If it
3198  * does so, the Callback object will be disposed of. (It is often not
3199  * worth checking for this exception, as it means either memory is
3200  * exhausted or pthread has run out of other resources to create new
3201  * mutexes.)
3202  * @note 1. Cancellation of the receiving thread is blocked when the
3203  * callback executes.
3204  * @note 2. If the callback throws an exception, the exception will be
3205  * consumed to protect the main loop and a g_critical() warning will
3206  * be issued.
3207  * @note 3. By virtue of the Releaser object, it is in theory possible
3208  * (if memory is exhausted and the system throws in that case) that an
3209  * internal SafeEmitterArg object will throw std::bad_alloc when
3210  * emitting/executing the callback in the glib main loop, with the
3211  * result that the relevant callback will not execute (instead the
3212  * exception will be consumed and a g_critical() warning will be
3213  * issued). This is rarely of any relevance because glib will abort
3214  * the program if it is itself unable to obtain memory from the
3215  * operating system. However, where it is relevant, design the
3216  * program so that it is not necessary to provide a releaser object.
3217  */
3218 void post(const Callback* cb, Releaser& r,
3219  gint priority = G_PRIORITY_DEFAULT_IDLE, GMainContext* context = 0);
3220 
3221 } // namespace Callback
3222 
3223 } // namespace Cgu
3224 
3225 #endif
void operator()(typename Cgu::Param< FreeArgs >::ParamType...args) const
Definition: callback.h:933
FunctorArg Functor
Definition: callback.h:732
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...) const
Definition: callback.h:1430
Callback3_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1416
void(* Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...)
Definition: callback.h:1593
Callback2_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1394
Definition: callback.h:1223
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...)
Definition: callback.h:1263
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1357
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1645
CallbackArg< FreeArgs...> * make_ref(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1701
SafeFunctorArg< T...> to_safe_functor(const CallbackArg< T...> *cb)
Definition: callback.h:1202
bool operator!=(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2)
Definition: callback.h:756
Definition: callback.h:1428
void(T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...)
Definition: callback.h:1242
void(* Func)(FreeArgs...)
Definition: callback.h:1493
CallbackArg< FreeArgs...> * make(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1665
Definition: callback.h:1630
void(* Func)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...)
Definition: callback.h:1540
Callback0(T &obj_, MemFunc func_)
Definition: callback.h:1219
FunctorArg(FunctorArg &&f)
Definition: callback.h:994
This is a smart pointer for managing the lifetime of objects allocated on freestore, with a thread safe reference count.
Definition: shared_ptr.h:644
void(T::* MemFunc)(FreeArgs...) const
Definition: callback.h:1352
SafeFunctorArg(const SafeFunctorArg &f)
Definition: callback.h:1101
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...)
Definition: callback.h:1289
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1633
Definition: callback.h:1261
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1547
STL namespace.
Struct which will conditionally convert a reference type to a value type.
Definition: param.h:103
Definition: callback.h:1364
Definition: callback.h:1504
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1249
Functor class holding a Callback::CallbackArg object.
Definition: callback.h:731
Definition: callback.h:1519
Definition: callback.h:1591
const T & ParamType
Definition: param.h:77
Definition: callback.h:1538
Callback_lambda(L &&l_)
Definition: callback.h:1646
Definition: callback.h:1563
Callback3(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1275
void(T::* MemFunc)(BoundArg1, BoundArg2, FreeArgs...) const
Definition: callback.h:1383
Definition: callback.h:1491
SafeFunctorArg()
Definition: callback.h:1119
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...) const
Definition: callback.h:1459
A specialization of std::hash for Cgu::Callback::FunctorArg, Cgu::Callback::SafeFunctorArg, Cgu::GobjHandle, Cgu::GvarHandle, Cgu::IntrusivePtr, Cgu::SharedHandle, Cgu::SharedLockHandle, Cgu::SharedPtr and Cgu::SharedLockPtr so that such objects may be keys of unordered associative containers.
Definition: callback.h:1402
Callback_function(std::function< void(FreeArgs...)> &&f_)
Definition: callback.h:1635
Callback_function(const std::function< void(FreeArgs...)> &f_)
Definition: callback.h:1634
SafeFunctorArg(const CallbackArg< FreeArgs...> *cb)
Definition: callback.h:1095
Definition: callback.h:1209
FunctorArg()
Definition: callback.h:1001
SafeFunctorArg SafeFunctor
Definition: callback.h:734
SafeFunctorArg(SafeFunctorArg &&f)
Definition: callback.h:1107
FunctorArg(const CallbackArg< FreeArgs...> *cb)
Definition: callback.h:982
Definition: callback.h:1457
void(T::* MemFunc)(BoundArg, FreeArgs...) const
Definition: callback.h:1366
void(* Func)(BoundArg1, BoundArg2, FreeArgs...)
Definition: callback.h:1521
bool operator==(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2)
Definition: callback.h:746
Callback4_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1443
Callback0_const(const T &obj_, MemFunc func_)
Definition: callback.h:1360
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, FreeArgs...) const
Definition: callback.h:1404
void(T::* MemFunc)(BoundArg, FreeArgs...)
Definition: callback.h:1225
Callback1(T &obj_, MemFunc func_, Arg &&arg_)
Definition: callback.h:1235
CallbackArg< FreeArgs...> * make_val(T &t, void(T::*func)(FreeArgs...))
Definition: callback.h:1683
CallbackArg< FreeArgs...> * lambda(Lambda &&l)
Definition: callback.h:3132
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1603
Definition: callback.h:1381
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1390
Callback4(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1302
Callback5_const(const T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1474
FunctorArg & operator=(FunctorArg &&f)
Definition: callback.h:949
Definition: callback.h:1640
Definition: callback.h:1316
Callback1_const(const T &obj_, MemFunc func_, Arg &&arg_)
Definition: callback.h:1376
FunctorArg & operator=(const FunctorArg &f)
Definition: callback.h:942
void(T::* MemFunc)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs...)
Definition: callback.h:1318
Definition: application.h:44
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1412
FunctorArg(const FunctorArg &f)
Definition: callback.h:988
virtual void dispatch(typename Cgu::Param< FreeArgs >::ParamType...args) const =0
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1511
Callback4_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_)
Definition: callback.h:1577
SafeFunctorArg & operator=(const SafeFunctorArg &f)
Definition: callback.h:1055
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1329
Callback3_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_)
Definition: callback.h:1551
Functor class holding a Callback::CallbackArg object, with thread-safe reference count.
Definition: callback.h:732
bool operator<(const FunctorArg< T...> &f1, const FunctorArg< T...> &f2)
Definition: callback.h:774
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1372
Callback5(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1333
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1497
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1470
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1271
void(* Func)(BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs...)
Definition: callback.h:1565
void operator()(typename Cgu::Param< FreeArgs >::ParamType...args) const
Definition: callback.h:1046
Callback2_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1531
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1573
Callback2(T &obj_, MemFunc func_, Arg1 &&arg1_, Arg2 &&arg2_)
Definition: callback.h:1253
void(* Func)(BoundArg, FreeArgs...)
Definition: callback.h:1506
Definition: callback.h:1240
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1439
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1527
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1231
CallbackArg()
Definition: callback.h:628
SafeFunctorArg & operator=(SafeFunctorArg &&f)
Definition: callback.h:1062
Definition: callback.h:1350
CallbackArg Callback
Definition: callback.h:522
Callback1_static(Func func_, Arg &&arg_)
Definition: callback.h:1515
virtual ~CallbackArg()
Definition: callback.h:634
std::unique_ptr< const CallbackArg< T...> > to_unique(const CallbackArg< T...> *cb)
Definition: callback.h:725
The callback interface class.
Definition: callback.h:522
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition: cgu_config.h:84
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1298
void dispatch(typename Cgu::Param< FreeArgs >::ParamType...free_args) const
Definition: callback.h:1216
A class used for tracking EmitterArg and SafeEmitterArg connections.
Definition: emitter.h:333
Callback0_static(Func func_)
Definition: callback.h:1500
void(T::* MemFunc)(FreeArgs...)
Definition: callback.h:1211
FunctorArg< T...> to_functor(const CallbackArg< T...> *cb)
Definition: callback.h:1162
Callback5_static(Func func_, Arg1 &&arg1_, Arg2 &&arg2_, Arg3 &&arg3_, Arg4 &&arg4_, Arg5 &&arg5_)
Definition: callback.h:1607
void post(const Callback *cb, gint priority=G_PRIORITY_DEFAULT_IDLE, GMainContext *context=0)
Definition: callback.h:1287