Library of Assembled Shared Sources
dispatcher_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 dispatcher_r_x.tmpl.h
5 * by param_expander.py on Tue Oct 7 01:22:02 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#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_IMPL_DISPATCHER_R_2_H
51#define LASS_GUARDIAN_OF_INCLUSION_UTIL_IMPL_DISPATCHER_R_2_H
52
54#include "../callback_common.h"
55
56// --- NEW INTERFACES ----------------------------------------------------------
57
58namespace lass
59{
60namespace util
61{
62namespace impl
63{
64
65/** abstract base class of all dispatchers for lass::util::CallbackR2.
66 * @internal
67 * @sa CallbackR2
68 * @author Bram de Greve [Bramz]
69 */
70template
71<
72 typename R, typename P1, typename P2
73>
74class DispatcherR2: public TDispatcherAllocatorBase
75{
76public:
77
78 DispatcherR2() {}
79 virtual ~DispatcherR2() {}
80
81 R call(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const
82 {
83 return doCall(iP1, iP2);
84 }
85 bool isEquivalent(const DispatcherR2<R, P1, P2>* iOther) const
86 {
87 return doIsEquivalent(iOther);
88 }
89
90private:
91
92 virtual R doCall(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const = 0;
93 virtual bool doIsEquivalent(const DispatcherR2<R, P1, P2>* iOther) const = 0;
94
95 DispatcherR2(const DispatcherR2<R, P1, P2>& iOther);
96 DispatcherR2& operator=(const DispatcherR2<R, P1, P2>& iOther);
97};
98
99
100
101/** Dispatcher for lass::util::CallbackR2 to a function or equivalent callable entinty.
102 * @internal
103 * @sa CallbackR2
104 * @author Bram de Greve [Bramz]
105 */
106template
107<
108 typename R, typename P1, typename P2,
109 typename FunctionType,
110 typename Enable = void
111>
112class DispatcherR2Function: public DispatcherR2<R, P1, P2>
113{
114public:
115
116 typedef FunctionType TFunction;
117 typedef DispatcherR2Function<R, P1, P2, FunctionType, Enable> TSelf;
118
119 DispatcherR2Function(typename CallTraits<TFunction>::TParam iFunction):
120 function_(iFunction)
121 {
122 }
123
124 const TFunction& function() const
125 {
126 return function_;
127 }
128
129private:
130
131 R doCall(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const override
132 {
133 if (!function_)
134 {
135 LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR0. Can't return a value.");
136 }
137 return function_(iP1, iP2);
138 }
139
140 bool doIsEquivalent(const DispatcherR2<R, P1, P2>* other) const override
141 {
142 if constexpr (impl::IsEqualityComparable<TFunction>::value)
143 {
144 return other && typeid( *other ) == typeid( TSelf )
145 && static_cast<const TSelf*>(other)->function_ == function_;
146 }
147 else
148 {
149 return false;
150 }
151 }
152
153 TFunction function_;
154};
155
156
157
158#if !LASS_HAVE_LAMBDA_OPERATOR_NOT
159
160/** Dispatcher for lass::util::CallbackR0 to a callable that does not support operator!
161 * @internal
162 * @sa CallbackR0
163 * @author Bram de Greve [Bramz]
164 *
165 * With C++11, lambdas can also be used as callables. But the MSVC compiler did not support
166 * the unary ! operator. This was fixed in VS 2019 version 16.2.
167 * https://twitter.com/lunasorcery/status/1092870113374687232
168 */
169template
170<
171 typename R, typename P1, typename P2,
172 typename FunctionType
173>
174class DispatcherR2Function
175 <
176 R, P1, P2,
177 FunctionType,
178 typename meta::EnableIf<!HasOperatorNot<FunctionType>::value>::Type
179 >
180 : public DispatcherR2<R, P1, P2>
181{
182public:
183
184 typedef FunctionType TFunction;
185
186 DispatcherR2Function(typename CallTraits<TFunction>::TParam iFunction):
187 function_(iFunction)
188 {
189 }
190
191 const TFunction& function() const
192 {
193 return function_;
194 }
195
196private:
197
198 R doCall(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const override
199 {
200 return function_(iP1, iP2);
201 }
202
203 bool doIsEquivalent(const DispatcherR2<R, P1, P2>* /*iOther*/) const override
204 {
205 return false;
206 }
207
208 TFunction function_;
209};
210
211#endif
212
213
214
215/** Dispatcher for lass::util::CallbackR2 to an object/method pair.
216 * @internal
217 * @sa CallbackR2
218 * @author Bram de Greve [Bramz]
219 */
220template
221<
222 typename R, typename P1, typename P2,
223 typename ObjectPtr, typename Method
224>
225class DispatcherR2Method: public DispatcherR2<R, P1, P2>
226{
227public:
228
229 typedef DispatcherR2Method<R, P1, P2, ObjectPtr, Method> TSelf;
230
231 DispatcherR2Method(typename CallTraits<ObjectPtr>::TParam iObject,
232 typename CallTraits<Method>::TParam iMethod):
233 object_(iObject),
234 method_(iMethod)
235 {
236 }
237
238private:
239
240 R doCall(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const override
241 {
242 if (!object_ || !method_)
243 {
244 LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR0. Can't return a value.");
245 }
246 return ((*object_).*method_)(iP1, iP2);
247 }
248
249 bool doIsEquivalent(const DispatcherR2<R, P1, P2>* iOther) const override
250 {
251 const TSelf* other = dynamic_cast<const TSelf*>(iOther);
252 return other && object_ == other->object_ && method_ == other->method_;
253 }
254
255 ObjectPtr object_;
256 Method method_;
257};
258
259
260
261}
262
263}
264
265}
266
267#endif // Guardian of Inclusion
268
269
270// EOF
library for template meta programming
Definition bool.h:76
general utility, debug facilities, ...
Library for Assembled Shared Sources.
Definition config.h:53