Library of Assembled Shared Sources
callback.h
Go to the documentation of this file.
1/*
2 * *** ATTENTION! DO NOT MODIFY THIS FILE DIRECTLY! ***
3 *
4 * It has automatically been generated from callback.tmpl.h
5 * by param_expander.py on Mon Oct 6 22:51:36 2025.
6 */
7
8/** @file
9 * @author Bram de Greve (bram@cocamware.com)
10 * @author Tom De Muer (tom@cocamware.com)
11 *
12 * *** BEGIN LICENSE INFORMATION ***
13 *
14 * The contents of this file are subject to the Common Public Attribution License
15 * Version 1.0 (the "License"); you may not use this file except in compliance with
16 * the License. You may obtain a copy of the License at
17 * http://lass.sourceforge.net/cpal-license. The License is based on the
18 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
19 * use of software over a computer network and provide for limited attribution for
20 * the Original Developer. In addition, Exhibit A has been modified to be consistent
21 * with Exhibit B.
22 *
23 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
24 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
25 * language governing rights and limitations under the License.
26 *
27 * The Original Code is LASS - Library of Assembled Shared Sources.
28 *
29 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
30 * The Original Developer is the Initial Developer.
31 *
32 * All portions of the code written by the Initial Developer are:
33 * Copyright (C) 2004-2011 the Initial Developer.
34 * All Rights Reserved.
35 *
36 * Contributor(s):
37 *
38 * Alternatively, the contents of this file may be used under the terms of the
39 * GNU General Public License Version 2 or later (the GPL), in which case the
40 * provisions of GPL are applicable instead of those above. If you wish to allow use
41 * of your version of this file only under the terms of the GPL and not to allow
42 * others to use your version of this file under the CPAL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and other
44 * provisions required by the GPL License. If you do not delete the provisions above,
45 * a recipient may use your version of this file under either the CPAL or the GPL.
46 *
47 * *** END LICENSE INFORMATION ***
48 */
49
50
51
52/** @defgroup Callback Callback
53 * @brief library to wrap generalized callback functions in first class objects.
54 * @date 2002-2004
55 * @author Bram de Greve [Bramz] (contact: bram@cocamware.com)
56 *
57 * The use of this library is to treat function calls as first class objects, so you can pass them
58 * around to be called at a later time.
59 *
60 * @code
61 * int fun(int a, int b) { return a + b; }
62 * // ...
63 * CallbackR2<int, int, int> cb(fun);
64 * // ...
65 * int result = cb(1, 2); // result will be 3.
66 * @endcode
67 *
68 * Of course, the above example could be done just as easy with plain old C function pointers.
69 * That's true, but the advantage of this library will come forward when you want to call a
70 * method of a specific object instead. You can tell what method must be called, and on what
71 * object. Later, the caller can execute this without being aware this is a different case than
72 * above. There's no way you can do this with plain old function pointers.
73 *
74 * @code
75 * class Foo
76 * {
77 * int m_;
78 * public:
79 * Foo(int m): m_(m) {}
80 * int bar(int a, b) const { return m * (a + b); }
81 * };
82 * // ...
83 * Foo foo(4);
84 * CallbackR2<int, int, int> cb2(&foo, Foo::bar);
85 * // ...
86 * int result2 = cb2(1, 2); // result2 will be 12.
87 * @endcode
88 *
89 * Both constant as non-constant member functions are supported as dispatchers.
90 *
91 * It is also possible to bind a function with a little different signature, but of which the
92 * arguments can be implicit converted to the right type.
93 *
94 * @code
95 * float spam(float a, float b) { return a / b; }
96 * // ...
97 * CallbackR2<int, int, int> cb3(spam);
98 * // ...
99 * int result3 = cb3(5, 2); // result3 will be 2
100 * @endcode
101 *
102 * Callbacks can also be in an empty state. This is when the callback has no dispatcher, no
103 * function call is bounded to it. Callbacks will be empty when constructed by the default
104 * constructor, or when one of the arguments is a NULL pointer
105 *
106 * @code
107 * CallbackR0<double> cb4;
108 * assert(cb4.empty());
109 *
110 * CallbackR1<bool, float> cb5(0); // NULL function pointer
111 * assert(cb5.empty());
112 *
113 * CallbackR2<int, int, int> cb6(0, Foo::bar); // NULL ojbect pointer
114 * assert(cb6.empty());
115 * @endcode
116 *
117 * When executing empty callbacks, we have to distinguish two situations: callbacks without
118 * return value, and callbacks with return value.
119 * - In the former case, there's no danger. When the callback is executed, it has no dispatcher to
120 * call. Hence, it won't do anything and it will immediately return.
121 * - In the latter case, an exception will be thrown. When the callback is executed, it has to
122 * return a value. Since there's no dispatcher to call that can return this value, we're in
123 * troubles. An Exception will be thrown to handle this error.
124 *
125 * @code
126 * Callback2<int, const std::string&> cb7;
127 * assert(cb7.empty());
128 * cb7(4, "hello"); // OK, empty callback but no return value expected.
129 *
130 * Callback3<std::string, int, int> cb8;
131 * assert(cb8.empty());
132 * try
133 * {
134 * std::string result8 = cb8(12, 34); // ERROR, an exception will be thrown.
135 * }
136 * catch(CallbackEmptyCall)
137 * {
138 * // you'll end up here on an empty call.
139 * }
140 *
141 * std::string result8b = cb8 ? cb8(12, 34) : "bah"; // result8b will be "bah".
142 * @endcode
143 *
144 * @par Callbacks without return value:
145 *
146 * - @ref lass::util::Callback0
147 * - @ref lass::util::Callback1
148 * - @ref lass::util::Callback2
149 * - @ref lass::util::Callback3
150 * - @ref lass::util::Callback4
151 * - @ref lass::util::Callback5
152 * - @ref lass::util::Callback6
153 * - @ref lass::util::Callback7
154 * - @ref lass::util::Callback8
155 * - @ref lass::util::Callback9
156 * - @ref lass::util::Callback10
157 * - @ref lass::util::Callback11
158 * - @ref lass::util::Callback12
159 * - @ref lass::util::Callback13
160 * - @ref lass::util::Callback14
161 * - @ref lass::util::Callback15
162 *
163 * @par Callbacks with return value:
164 *
165 * - @ref lass::util::CallbackR0
166 * - @ref lass::util::CallbackR1
167 * - @ref lass::util::CallbackR2
168 * - @ref lass::util::CallbackR3
169 * - @ref lass::util::CallbackR4
170 * - @ref lass::util::CallbackR5
171 * - @ref lass::util::CallbackR6
172 * - @ref lass::util::CallbackR7
173 * - @ref lass::util::CallbackR8
174 * - @ref lass::util::CallbackR9
175 * - @ref lass::util::CallbackR10
176 * - @ref lass::util::CallbackR11
177 * - @ref lass::util::CallbackR12
178 * - @ref lass::util::CallbackR13
179 * - @ref lass::util::CallbackR14
180 * - @ref lass::util::CallbackR15
181 * *
182 * @par Acknowledgements:
183 * I want to thank Altair, Jaap Suter & especially Dirk Gerrits (who has spent an entire afternoon
184 * on this to help me. It was a waste of time for both of us, but we had a lot of fun, didn't we?)
185 */
186
187
188
189#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_H
190#define LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_H
191
192#include "callback_0.h"
193#include "callback_1.h"
194#include "callback_2.h"
195#include "callback_3.h"
196#include "callback_4.h"
197#include "callback_5.h"
198#include "callback_6.h"
199#include "callback_7.h"
200#include "callback_8.h"
201#include "callback_9.h"
202#include "callback_10.h"
203#include "callback_11.h"
204#include "callback_12.h"
205#include "callback_13.h"
206#include "callback_14.h"
207#include "callback_15.h"
208
209#include "callback_r_0.h"
210#include "callback_r_1.h"
211#include "callback_r_2.h"
212#include "callback_r_3.h"
213#include "callback_r_4.h"
214#include "callback_r_5.h"
215#include "callback_r_6.h"
216#include "callback_r_7.h"
217#include "callback_r_8.h"
218#include "callback_r_9.h"
219#include "callback_r_10.h"
220#include "callback_r_11.h"
221#include "callback_r_12.h"
222#include "callback_r_13.h"
223#include "callback_r_14.h"
224#include "callback_r_15.h"
225
226
227#endif
228
229// EOF