Library of Assembled Shared Sources
callback_r_2.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_r_x.tmpl.h
5 * by param_expander.py on Tue Oct 7 01:22:01 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-2025 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/** @class lass::util::CallbackR2
53 * @ingroup Callback
54 * @brief callback with 2 parameter2 and with returnvalue.
55 * @date 2002
56 * @author Bram de Greve [Bramz] (contact: bram@cocamware.com)
57 *
58 * It's a single object that can hold a reference to a free function or an
59 * object/(const) method pair. Once the callback is constructed, it works
60 * completely transparent. All it shows to the client is a function that
61 * takes 2 parameter(s) and gives a returnvalue.
62 */
63
64
65
66#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_2_H
67#define LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_2_H
68
69
70
71// --- OLD INTERFACES ----------------------------------------------------------
72
73#include "util_common.h"
74#include "shared_ptr.h"
75#include "callback_common.h"
76#include "impl/dispatcher_r_2.h"
77
78
79
80
81// --- NEW INTERFACES ----------------------------------------------------------
82
83namespace lass
84{
85namespace util
86{
87
88
89// THE CALLBACK:
90// This is the actuall class you use to hold callbacks:
91
92template
93<
94 typename R,
95 typename P1, typename P2
96>
98{
99public:
100
101 typedef CallbackR2<R, P1, P2> TSelf;
102 typedef SharedPtr< impl::DispatcherR2<R, P1, P2> > TDispatcherPtr;
103
104 // STRUCTORS
105
106 /** Default constructor, construct empty callback.
107 */
109 {
110 }
111
112 /** Construct function callback
113 */
114 template <typename FunctionType>
115 CallbackR2(FunctionType iFunction):
116 dispatcher_(new impl::DispatcherR2Function<R, P1, P2, FunctionType>(iFunction))
117 {
118 }
119
120 /** Construct object/method callback.
121 */
122 template <typename ObjectPtr, typename Method>
123 CallbackR2(ObjectPtr iObject, Method iMethod):
124 dispatcher_(new impl::DispatcherR2Method<R, P1, P2, ObjectPtr, Method>(iObject, iMethod))
125 {
126 }
127
128 /** copy constructor
129 */
130 CallbackR2(const TSelf& iOther):
131 dispatcher_(iOther.dispatcher_)
132 {
133 }
134
135 /** move constructor
136 */
137 CallbackR2(TSelf&& iOther) noexcept:
138 dispatcher_(std::move(iOther.dispatcher_))
139 {
140 }
141
142
143 // OPERATORS
144
145 /** assignment operator
146 */
147 TSelf& operator=(const TSelf& iOther)
148 {
149 TSelf temp(iOther);
150 swap(temp);
151 return *this;
152 }
153
154 /** assignment operator
155 */
156 TSelf& operator=(TSelf&& iOther) noexcept
157 {
158 dispatcher_ = std::move(iOther.dispatcher_);
159 return *this;
160 }
161
162 /** THE operator. Executes the callback.
163 */
164 R operator()(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const
165 {
166 if (isEmpty())
167 {
168 LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR2. Can't return a value.");
169 }
170 return dispatcher_->call(iP1, iP2);
171 }
172
173
174 // METHODS
175
176 /** Reset to empty callback.
177 */
178 void reset()
179 {
180 dispatcher_.reset();
181 }
182
183 /** Returns true if no callback dispatcher is assigned to this object.
184 */
185 bool isEmpty() const
186 {
187 return dispatcher_.isEmpty();
188 }
189
190 /** return this->isEmpty()
191 */
192 bool operator!() const
193 {
194 return dispatcher_.isEmpty();
195 }
196
197 /** return !this->isEmpty())
198 */
199 explicit operator bool() const
200 {
201 return !dispatcher_.isEmpty();
202 }
203
204 /** Swaps the dispatcher of this callback with the dispatcher of another.
205 */
206 void swap(TSelf& iOther)
207 {
208 dispatcher_.swap(iOther.dispatcher_);
209 }
210
211 /** return true if two callbacks call the same function/method,
212 * NEEDS RTTI!
213 */
214 bool operator==(const TSelf& iOther) const
215 {
216 if (dispatcher_ == iOther.dispatcher_)
217 {
218 return true;
219 }
220 return dispatcher_ && dispatcher_->isEquivalent(iOther.dispatcher_.get());
221 }
222
223 const TDispatcherPtr& dispatcher() const
224 {
225 return dispatcher_;
226 }
227
228private:
229
230 TDispatcherPtr dispatcher_;
231};
232
233
234
235/** return true if two callbacks are different
236 * @relates CallbackR2
237 */
238template<typename R, typename P1, typename P2>
240{
241 return !(iA == iB);
242}
243
244
245/** make a CallbackR2 from a function
246 * @relates CallbackR2
247 */
248template <typename R, typename P1, typename P2> inline
249CallbackR2<R, P1, P2> makeCallback(R (*iFunction)(P1, P2))
250{
251 return CallbackR2<R, P1, P2>(iFunction);
252}
253
254
255
256/** make a CallbackR2 from a function
257 * @relates CallbackR2
258 */
259template <typename R, typename P1, typename P2> inline
261{
262 return iCallback;
263}
264
265
266
267/** make a CallbackR2 from a object and method
268 * @relates CallbackR2
269 */
270template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2> inline
271CallbackR2<R, P1, P2> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2))
272{
273 return CallbackR2<R, P1, P2>(iObject, iMethod);
274}
275
276
277
278/** make a CallbackR2 from a object and const method
279 * @relates CallbackR2
280 */
281template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2> inline
282CallbackR2<R, P1, P2> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2) const)
283{
284 return CallbackR2<R, P1, P2>(iObject, iMethod);
285}
286
287
288
289}
290
291}
292
293#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_CALLBACK_R2
294#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_PYTHON_H
296#endif
297
298#endif // Guardian of Inclusion
299
300// EOF
R operator()(typename util::CallTraits< P1 >::TParam iP1, typename util::CallTraits< P2 >::TParam iP2) const
THE operator.
CallbackR2< R, P1, P2 > makeCallback(ObjectPtr iObject, R(Object::*iMethod)(P1, P2))
make a CallbackR2 from a object and method
TSelf & operator=(const TSelf &iOther)
assignment operator
CallbackR2< R, P1, P2 > makeCallback(ObjectPtr iObject, R(Object::*iMethod)(P1, P2) const)
make a CallbackR2 from a object and const method
bool operator==(const TSelf &iOther) const
return true if two callbacks call the same function/method, NEEDS RTTI!
void reset()
Reset to empty callback.
CallbackR2(FunctionType iFunction)
Construct function callback.
bool isEmpty() const
Returns true if no callback dispatcher is assigned to this object.
bool operator!() const
return this->isEmpty()
CallbackR2(TSelf &&iOther) noexcept
move constructor
CallbackR2(const TSelf &iOther)
copy constructor
CallbackR2< R, P1, P2 > makeCallback(R(*iFunction)(P1, P2))
make a CallbackR2 from a function
bool operator!=(const CallbackR2< R, P1, P2 > &iA, const CallbackR2< R, P1, P2 > &iB)
return true if two callbacks are different
void swap(TSelf &iOther)
Swaps the dispatcher of this callback with the dispatcher of another.
const CallbackR2< R, P1, P2 > & makeCallback(const CallbackR2< R, P1, P2 > &iCallback)
make a CallbackR2 from a function
TSelf & operator=(TSelf &&iOther) noexcept
assignment operator
CallbackR2(ObjectPtr iObject, Method iMethod)
Construct object/method callback.
CallbackR2()
Default constructor, construct empty callback.
general utility, debug facilities, ...
Library for Assembled Shared Sources.
Definition config.h:53