Cantera
Loading...
Searching...
No Matches
Delegator.h
Go to the documentation of this file.
1//! @file Delegator.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_DELEGATOR_H
7#define CT_DELEGATOR_H
8
10#include "cantera/base/Units.h"
13#include "cantera/numerics/eigen_sparse.h"
14
15namespace Cantera
16{
17
18//! Delegate member functions of a C++ class to externally-specified functions
19/*!
20 * This base class provides functions for setting delegates for the member
21 * functions of a C++ class at runtime. The purpose of this capability is to
22 * allow the class to be extended using functions defined in any programming
23 * language that provides a C API for calling functions in that language.
24 *
25 * Delegates are specified as `std::function` objects that are responsible for
26 * encapsulating the data specific to the target language and calling the
27 * appropriate function in the target language. For methods with a return value, the
28 * `std::function` has a modified signature where the return value is passed by
29 * reference as the first argument and the method returns an `int`. The delegate should
30 * return zero if it does not set the arguments value, and a non-zero value if it does.
31 *
32 * Delegated methods can be specified to either "replace" the original class's
33 * method, or to run "before" or "after" the original method, using the `when`
34 * parameter of the `setDelegate` method. There are two special cases for delegates of
35 * methods with return values:
36 * - If the "before" delegate specifies a value for the return parameter (and then
37 * returns with a non-zero status value), this value will be returned and the original
38 * method will not be called. Otherwise, the original method will be called and its
39 * value will be returned.
40 * - If an "after" delegate specifies a return value (and returns with a non-zero
41 * status value), this value will be added to the value returned by the original
42 * method, and this combined result will be then be returned. The meaning of "added"
43 * is determined by the `+` operator for the return type, for example addition for
44 * numeric types or concatenation for strings.
45 *
46 * ## Implementation for each delegated function type
47 *
48 * Several functions and member variables are defined in this base class for each
49 * distinct function signature that can be delegated by a derived class such as
50 * ReactorDelegator. These are:
51 * - The `install` function stores the address of a function that will be called by
52 * a derived delegator class in the corresponding `m_funcs_...` map, and sets the
53 * default implementation of this method (which should be to call the base class
54 * implementation). For delegates with a return type, a copy of this default
55 * implementation is also stored in the corresponding `m_base_...` map
56 * - The `setDelegate` function wraps the user-provided delegate in a function that
57 * handles whether the delegate is to be called before, after, or instead of the base
58 * class's implementation. This function is then stored at the address specified in
59 * the corresponding `m_funcs_...` map.
60 * - `m_funcs_...` is a mapping between member function names and the addresses
61 * of the functions that will be called to implement these functions in the derived
62 * delegator class.
63 * - `m_base_...` is a mapping between member function names and the default
64 * implementations of these member functions, for delegates with return values
65 *
66 * Additional implementation for each function type is specific to the programming
67 * language that the delegate is written in. For the Python delegates, see additional
68 * documentation in `delegator.py` and `_delegate_callbacks.pyx`.
69 *
70 * ## Implementation for specific delegated functions
71 *
72 * Beyond the implementation of particular function signatures, there are no elements
73 * of the Delegator class that are specific to individual delegated functions, which
74 * are handled by derived classes such as ReactorDelegator, which will also inherit from
75 * another base class such as Reactor.
76 *
77 * Delegation of a member function (for example, `Reactor::eval`) is handled by several
78 * elements:
79 * - A `std::function` member variable to hold a delegate function, or its default
80 * implementation.
81 * - An override of the member function whose implementation calls the stored delegate.
82 * - A call to `install` from the constructor of the derived delegator class, which
83 * takes the member function name, a reference to the `std::function` member variable
84 * described above, and a lambda function that implements the default behavior, that
85 * is, calling the equivalent base class method.
86 *
87 * Additional implementation for each function is specific to the programming language
88 * that the delegate is written in. For Python delegates, see additional documentation
89 * in `delegator.py` and `_delegate_callbacks.pyx`.
90 */
92{
93public:
94 //! Get the name of the user-defined class in the extension language
95 string delegatorName() const {
96 return m_delegatorName;
97 }
98
99 //! Set the name of the user-defined class in the extension language
103
104 //! Set delegates for member functions with the signature `void()`.
105 void setDelegate(const string& name, const function<void()>& func,
106 const string& when)
107 {
108 if (!m_funcs_v.count(name)) {
109 throw NotImplementedError("Delegator::setDelegate",
110 "for function named '{}' with signature 'void()'.", name);
111 }
112 *m_funcs_v[name] = makeDelegate(func, when, *m_funcs_v[name]);
113 }
114
115 //! set delegates for member functions with the signature `void(bool)`
116 void setDelegate(const string& name, const function<void(bool)>& func,
117 const string& when)
118 {
119 if (!m_funcs_v_b.count(name)) {
120 throw NotImplementedError("Delegator::setDelegate",
121 "for function named '{}' with signature 'void(bool)'.", name);
122 }
123 *m_funcs_v_b[name] = makeDelegate(func, when, *m_funcs_v_b[name]);
124 }
125
126 //! set delegates for member functions with the signature `void(double)`
127 void setDelegate(const string& name, const function<void(double)>& func,
128 const string& when)
129 {
130 if (!m_funcs_v_d.count(name)) {
131 throw NotImplementedError("Delegator::setDelegate",
132 "for function named '{}' with signature 'void(double)'.", name);
133 }
134 *m_funcs_v_d[name] = makeDelegate(func, when, *m_funcs_v_d[name]);
135 }
136
137 //! set delegates for member functions with the signature `void(AnyMap&)`
138 void setDelegate(const string& name, const function<void(AnyMap&)>& func,
139 const string& when)
140 {
141 if (!m_funcs_v_AMr.count(name)) {
142 throw NotImplementedError("Delegator::setDelegate",
143 "for function named '{}' with signature 'void(AnyMap&)'.", name);
144 }
145 *m_funcs_v_AMr[name] = makeDelegate(func, when, *m_funcs_v_AMr[name]);
146 }
147
148 //! set delegates for member functions with the signature
149 //! `void(AnyMap&, UnitStack&)`
150 void setDelegate(const string& name,
151 const function<void(const AnyMap&, const UnitStack&)>& func,
152 const string& when)
153 {
154 if (!m_funcs_v_cAMr_cUSr.count(name)) {
155 throw NotImplementedError("Delegator::setDelegate",
156 "for function named '{}' with signature "
157 "'void(const AnyMap&, const UnitStack&)'.",
158 name);
159 }
160 *m_funcs_v_cAMr_cUSr[name] = makeDelegate(func, when, *m_funcs_v_cAMr_cUSr[name]);
161 }
162
163 //! set delegates for member functions with the signature
164 //! `void(const string&, void*)`
165 void setDelegate(const string& name,
166 const function<void(const string&, void*)>& func,
167 const string& when)
168 {
169 if (!m_funcs_v_csr_vp.count(name)) {
170 throw NotImplementedError("Delegator::setDelegate",
171 "for function named '{}' with signature 'void(const string&, void*)'.");
172 }
173 *m_funcs_v_csr_vp[name] = makeDelegate(func, when, *m_funcs_v_csr_vp[name]);
174 }
175
176 //! Set delegates for member functions with the signature `void(span<double>)`
177 void setDelegate(const string& name,
178 const function<void(span<double>)>& func,
179 const string& when)
180 {
181 if (!m_funcs_v_dp.count(name)) {
182 throw NotImplementedError("Delegator::setDelegate",
183 "for function named '{}' with signature 'void(span<double>)'.", name);
184 }
185 *m_funcs_v_dp[name] = makeDelegate(func, when, *m_funcs_v_dp[name]);
186 }
187
188 //! Set delegates for member functions with the signature
189 //! `void(double, span<double>)`
191 const string& name,
192 const function<void(double, span<double>)>& func,
193 const string& when)
194 {
195 if (!m_funcs_v_d_dp.count(name)) {
196 throw NotImplementedError("Delegator::setDelegate",
197 "for function named '{}' with signature 'void(double, span<double>)'.",
198 name);
199 }
200 *m_funcs_v_d_dp[name] = makeDelegate(func, when, *m_funcs_v_d_dp[name]);
201 }
202
203 //! Set delegates for member functions with the signature
204 //! `void(double, span<double>, span<double>)`
206 const string& name,
207 const function<void(double, span<double>, span<double>)>& func,
208 const string& when)
209 {
210 if (!m_funcs_v_d_dp_dp.count(name)) {
211 throw NotImplementedError("Delegator::setDelegate",
212 "for function named '{}' with signature "
213 "'void(double, span<double>, span<double>)'.", name);
214 }
215 *m_funcs_v_d_dp_dp[name] = makeDelegate(func, when, *m_funcs_v_d_dp_dp[name]);
216 }
217
218 //! Set delegates for member functions with the signature
219 //! `void(span<double>, span<double>, span<double>)`
221 const string& name,
222 const function<void(span<double>, span<double>, span<double>)>& func,
223 const string& when)
224 {
225 if (!m_funcs_v_dp_dp_dp.count(name)) {
226 throw NotImplementedError("Delegator::setDelegate",
227 "for function named '{}' with signature "
228 "'void(span<double>, span<double>, span<double>)'.", name);
229 }
230 *m_funcs_v_dp_dp_dp[name] = makeDelegate(func, when, *m_funcs_v_dp_dp_dp[name]);
231 }
232
233 //! set delegates for member functions with the signature `double(void*)`
234 void setDelegate(const string& name,
235 const function<int(double&, void*)>& func,
236 const string& when)
237 {
238 if (!m_funcs_d_vp.count(name)) {
239 throw NotImplementedError("Delegator::setDelegate",
240 "for function named '{}' with signature 'double(void*)'.", name);
241 }
242 *m_funcs_d_vp[name] = makeDelegate(name, func, when, m_base_d_vp[name]);
243 }
244
245 //! Set delegates for member functions with the signature `string(size_t)`
246 void setDelegate(const string& name,
247 const function<int(string&, size_t)>& func,
248 const string& when)
249 {
250 if (!m_funcs_s_sz.count(name)) {
251 throw NotImplementedError("Delegator::setDelegate",
252 "for function named '{}' with signature "
253 "'string(size_t)'.", name);
254 }
255 *m_funcs_s_sz[name] = makeDelegate(name, func, when, m_base_s_sz[name]);
256 }
257
258 //! Set delegates for member functions with the signature `double(size_t)`
259 void setDelegate(const string& name,
260 const function<int(double&, size_t)>& func,
261 const string& when)
262 {
263 if (!m_funcs_d_sz.count(name)) {
264 throw NotImplementedError("Delegator::setDelegate",
265 "for function named '{}' with signature "
266 "'double(size_t)'.", name);
267 }
268 *m_funcs_d_sz[name] = makeDelegate(name, func, when, m_base_d_sz[name]);
269 }
270
271 //! Set delegates for member functions with the signature `size_t(string)`
272 void setDelegate(const string& name,
273 const function<int(size_t&, const string&)>& func,
274 const string& when)
275 {
276 if (!m_funcs_sz_csr.count(name)) {
277 throw NotImplementedError("Delegator::setDelegate",
278 "for function '{}' with signature "
279 "'size_t(const string&)'.", name);
280 }
281 *m_funcs_sz_csr[name] = makeDelegate(name, func, when, m_base_sz_csr[name]);
282 }
283
284 //! Set delegates for member functions with the signature `void(SparseTriplets&)`
285 //! @since New in %Cantera 4.0.
286 void setDelegate(const string& name,
287 const function<void(SparseTriplets&)>& func,
288 const string& when)
289 {
290 if (!m_funcs_v_vET.count(name)) {
291 throw NotImplementedError("Delegator::setDelegate",
292 "for function named '{}' with signature "
293 "'void(SparseTriplets&)'.", name);
294 }
295 *m_funcs_v_vET[name] = makeDelegate(func, when, *m_funcs_v_vET[name]);
296 }
297
298 //! Store a handle to a wrapper for the delegate from an external language interface
299 void holdExternalHandle(const string& name,
300 const shared_ptr<ExternalHandle>& handle) {
301 m_handles[name] = handle;
302 }
303
304 //! Get the handle for a wrapper for the delegate from the external language
305 //! interface specified by *name*.
306 //! Returns a null pointer if the requested handle does not exist.
307 shared_ptr<ExternalHandle> getExternalHandle(const string& name) const {
308 if (m_handles.count(name)) {
309 return m_handles.at(name);
310 } else {
311 return shared_ptr<ExternalHandle>();
312 }
313 }
314
315protected:
316 //! Install a function with the signature `void()` as being delegatable
317 void install(const string& name, function<void()>& target,
318 const function<void()>& func)
319 {
320 target = func;
321 m_funcs_v[name] = &target;
322 }
323
324 //! Install a function with the signature `void(bool)` as being delegatable
325 void install(const string& name, function<void(bool)>& target,
326 const function<void(bool)>& func)
327 {
328 target = func;
329 m_funcs_v_b[name] = &target;
330 }
331
332 //! Install a function with the signature `void(double)` as being delegatable
333 void install(const string& name, function<void(double)>& target,
334 const function<void(double)>& func)
335 {
336 target = func;
337 m_funcs_v_d[name] = &target;
338 }
339
340 //! Install a function with the signature `void(AnyMap&)` as being delegatable
341 void install(const string& name, function<void(AnyMap&)>& target,
342 const function<void(AnyMap&)>& func)
343 {
344 target = func;
345 m_funcs_v_AMr[name] = &target;
346 }
347
348 //! Install a function with the signature `void(const AnyMap&, const UnitStack&)`
349 //! as being delegatable
350 void install(const string& name,
351 function<void(const AnyMap&, const UnitStack&)>& target,
352 const function<void(const AnyMap&, const UnitStack&)>& func)
353 {
354 target = func;
355 m_funcs_v_cAMr_cUSr[name] = &target;
356 }
357
358 //! Install a function with the signature `void(const string&, void*)` as being
359 //! delegatable
360 void install(const string& name, function<void(const string&, void*)>& target,
361 const function<void(const string&, void*)>& func)
362 {
363 target = func;
364 m_funcs_v_csr_vp[name] = &target;
365 }
366
367 //! Install a function with the signature `void(span<double>)` as being delegatable
368 void install(const string& name,
369 function<void(span<double>)>& target,
370 const function<void(span<double>)>& func)
371 {
372 target = func;
373 m_funcs_v_dp[name] = &target;
374 }
375
376 //! Install a function with the signature `void(double, span<double>)` as being delegatable
377 void install(const string& name,
378 function<void(double, span<double>)>& target,
379 const function<void(double, span<double>)>& func)
380 {
381 target = func;
382 m_funcs_v_d_dp[name] = &target;
383 }
384
385 //! Install a function with the signature `void(double, span<double>, span<double>)`
386 //! as being delegatable
387 void install(const string& name,
388 function<void(double, span<double>, span<double>)>& target,
389 const function<void(double, span<double>, span<double>)>& func)
390 {
391 target = func;
392 m_funcs_v_d_dp_dp[name] = &target;
393 }
394
395 //! Install a function with the signature
396 //! `void(span<double>, span<double>, span<double>)` as being delegatable
397 void install(const string& name,
398 function<void(span<double>, span<double>, span<double>)>& target,
399 const function<void(span<double>, span<double>, span<double>)>& base)
400 {
401 target = base;
402 m_funcs_v_dp_dp_dp[name] = &target;
403 }
404
405 //! Install a function with the signature `double(void*)` as being delegatable
406 void install(const string& name, function<double(void*)>& target,
407 const function<double(void*)>& func)
408 {
409 target = func;
410 m_funcs_d_vp[name] = &target;
411 }
412
413 //! Install a function with the signature `string(size_t)` as being delegatable
414 void install(const string& name,
415 function<string(size_t)>& target,
416 const function<string(size_t)>& base)
417 {
418 target = base;
419 m_funcs_s_sz[name] = &target;
420 m_base_s_sz[name] = base;
421 }
422
423 //! Install a function with the signature `double(size_t)` as being delegatable
424 void install(const string& name,
425 function<double(size_t)>& target,
426 const function<double(size_t)>& base)
427 {
428 target = base;
429 m_funcs_d_sz[name] = &target;
430 m_base_d_sz[name] = base;
431 }
432
433 //! Install a function with the signature `size_t(string)` as being delegatable
434 void install(const string& name,
435 function<size_t(const string&)>& target,
436 const function<size_t(const string&)>& base)
437 {
438 target = base;
439 m_funcs_sz_csr[name] = &target;
440 m_base_sz_csr[name] = base;
441 }
442
443 //! Install a function with the signature `void(SparseTriplets&)`
444 //! as being delegatable
445 //! @since New in %Cantera 4.0.
446 void install(const string& name,
447 function<void(SparseTriplets&)>& target,
448 const function<void(SparseTriplets&)>& base)
449 {
450 target = base;
451 m_funcs_v_vET[name] = &target;
452 }
453
454 //! Create a delegate for a function with no return value
455 template <typename BaseFunc, class ... Args>
456 function<void(Args ...)> makeDelegate(
457 const function<void(Args ...)>& func,
458 const string& when,
459 BaseFunc base)
460 {
461 if (when == "before") {
462 return [base, func](Args ... args) {
463 func(args ...);
464 base(args ...);
465 };
466 } else if (when == "after") {
467 return [base, func](Args ... args) {
468 base(args ...);
469 func(args ...);
470 };
471 } else if (when == "replace") {
472 return [func](Args ... args) {
473 func(args ...);
474 };
475 } else {
476 throw CanteraError("Delegator::makeDelegate",
477 "'when' must be one of 'before', 'after', or 'replace';"
478 " not '{}", when);
479 }
480 }
481
482 //! Create a delegate for a function with a return value
483 template <typename ReturnType, class ... Args>
484 function<ReturnType(Args ...)> makeDelegate(
485 const string& name,
486 const function<int(ReturnType&, Args ...)>& func,
487 const string& when,
488 const function<ReturnType(Args ...)>& base)
489 {
490 if (when == "before") {
491 return [base, func](Args ... args) {
492 // Call the provided delegate first. If it sets the return
493 // value, return that, otherwise return the value from the
494 // original method
495 ReturnType ret;
496 int done = func(ret, args ...);
497 if (done) {
498 return ret;
499 } else {
500 return base(args ...);
501 }
502 };
503 } else if (when == "after") {
504 return [base, func](Args ... args) {
505 // Add the value returned by the original method and the
506 // provided delegate
507 ReturnType ret1 = base(args ...);
508 ReturnType ret2;
509 int done = func(ret2, args ...);
510 if (done) {
511 return ret1 + ret2;
512 } else {
513 return ret1;
514 }
515 };
516 } else if (when == "replace") {
517 return [base, name, func, this](Args ... args) {
518 ReturnType ret;
519 int has_ret = func(ret, args ...);
520 if (!has_ret) {
521 throw CanteraError("Lambda generated by Delegator::makeDelegate",
522 "Method '{}' of class '{}' did not return a value of type '{}'.",
523 name, delegatorName(), demangle(typeid(ret)));
524 }
525 return ret;
526 };
527 } else {
528 throw CanteraError("Delegator::makeDelegate",
529 "For function named '{}':\n"
530 "'when' must be one of 'before', 'after', or 'replace';"
531 " not '{}'", name, when);
532 }
533 }
534
535 //! Helper to remove const for cases where the delegated function signature uses
536 //! `span<const double>`.
537 span<double> stripConst(const span<const double>& s) {
538 return span<double>(const_cast<double*>(s.data()), s.size());
539 }
540
541 //! @name Containers for delegates and base class implementations.
542 //!
543 //! Maps named `m_funcs_*` hold the current delegate. For functions with a return
544 //! value, `m_base_*` holds a pointer to the base class's implementation of the
545 //! function.
546 //!
547 //! These containers use a naming scheme based on the signature of the corresponding
548 //! member functions. Following the prefix `_m_funcs_` is a notation of the return
549 //! type, followed by an underscore, then the notations for each argument, separated
550 //! by underscores. The following shorthand is used for different return / argument
551 //! types:
552 //!
553 //! - `v` for `void`
554 //! - `b` for `bool`
555 //! - `d` for `double`
556 //! - `s` for `string`
557 //! - `sz` for `size_t`
558 //! - `AM` for `AnyMap`
559 //! - `US` for `UnitStack`
560 //! - `ET` for `Eigen::Triplet<double>`
561 //! - prefix `c` for `const` arguments
562 //! - suffix `r` for reference arguments
563 //! - suffix `p` for span arguments (for example, `dp` for `span<double>`)
564 //! @{
565
566 // Delegates with no return value
567 map<string, function<void()>*> m_funcs_v;
568 map<string, function<void(bool)>*> m_funcs_v_b;
569 map<string, function<void(double)>*> m_funcs_v_d;
570 map<string, function<void(AnyMap&)>*> m_funcs_v_AMr;
571 map<string, function<void(const AnyMap&, const UnitStack&)>*> m_funcs_v_cAMr_cUSr;
572 map<string, function<void(const string&, void*)>*> m_funcs_v_csr_vp;
573 map<string, function<void(span<double>)>*> m_funcs_v_dp;
574 map<string, function<void(double, span<double>)>*> m_funcs_v_d_dp;
575 map<string,
576 function<void(double, span<double>, span<double>)>*> m_funcs_v_d_dp_dp;
577 map<string,
578 function<void(span<double>, span<double>, span<double>)>*> m_funcs_v_dp_dp_dp;
579 map<string, function<void(SparseTriplets&)>*> m_funcs_v_vET;
580
581 // Delegates with a return value
582 map<string, function<double(void*)>> m_base_d_vp;
583 map<string, function<double(void*)>*> m_funcs_d_vp;
584
585 // Delegates with a return value of type string
586 map<string, function<string(size_t)>> m_base_s_sz;
587 map<string, function<string(size_t)>*> m_funcs_s_sz;
588
589 // Delegates with a return value of type double
590 map<string, function<double(size_t)>> m_base_d_sz;
591 map<string, function<double(size_t)>*> m_funcs_d_sz;
592
593 map<string, function<size_t(const string&)>> m_base_sz_csr;
594 map<string, function<size_t(const string&)>*> m_funcs_sz_csr;
595 //! @}
596
597 //! Handles to wrappers for the delegated object in external language interfaces.
598 //! Used to provide access to these wrappers as well as managing cleanup functions
599 //! called from the destructor of the derived ExternalHandle class.
600 map<string, shared_ptr<ExternalHandle>> m_handles;
601
602 //! Name of the class in the extension language
604};
605
606}
607
608#endif
Header for unit conversion utilities, which are used to translate user input from input files (See In...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
Base class for exceptions thrown by Cantera classes.
Delegate member functions of a C++ class to externally-specified functions.
Definition Delegator.h:92
void install(const string &name, function< void(double)> &target, const function< void(double)> &func)
Install a function with the signature void(double) as being delegatable.
Definition Delegator.h:333
function< ReturnType(Args ...)> makeDelegate(const string &name, const function< int(ReturnType &, Args ...)> &func, const string &when, const function< ReturnType(Args ...)> &base)
Create a delegate for a function with a return value.
Definition Delegator.h:484
void setDelegate(const string &name, const function< void(const AnyMap &, const UnitStack &)> &func, const string &when)
set delegates for member functions with the signature void(AnyMap&, UnitStack&)
Definition Delegator.h:150
void setDelegate(const string &name, const function< int(string &, size_t)> &func, const string &when)
Set delegates for member functions with the signature string(size_t).
Definition Delegator.h:246
void setDelegate(const string &name, const function< void(bool)> &func, const string &when)
set delegates for member functions with the signature void(bool)
Definition Delegator.h:116
void install(const string &name, function< void(bool)> &target, const function< void(bool)> &func)
Install a function with the signature void(bool) as being delegatable.
Definition Delegator.h:325
void holdExternalHandle(const string &name, const shared_ptr< ExternalHandle > &handle)
Store a handle to a wrapper for the delegate from an external language interface.
Definition Delegator.h:299
string delegatorName() const
Get the name of the user-defined class in the extension language.
Definition Delegator.h:95
void install(const string &name, function< void(AnyMap &)> &target, const function< void(AnyMap &)> &func)
Install a function with the signature void(AnyMap&) as being delegatable.
Definition Delegator.h:341
void install(const string &name, function< double(size_t)> &target, const function< double(size_t)> &base)
Install a function with the signature double(size_t) as being delegatable.
Definition Delegator.h:424
void setDelegate(const string &name, const function< int(double &, size_t)> &func, const string &when)
Set delegates for member functions with the signature double(size_t).
Definition Delegator.h:259
void setDelegate(const string &name, const function< void(double)> &func, const string &when)
set delegates for member functions with the signature void(double)
Definition Delegator.h:127
void setDelegate(const string &name, const function< void(const string &, void *)> &func, const string &when)
set delegates for member functions with the signature void(const string&, void*)
Definition Delegator.h:165
void install(const string &name, function< size_t(const string &)> &target, const function< size_t(const string &)> &base)
Install a function with the signature size_t(string) as being delegatable.
Definition Delegator.h:434
function< void(Args ...)> makeDelegate(const function< void(Args ...)> &func, const string &when, BaseFunc base)
Create a delegate for a function with no return value.
Definition Delegator.h:456
void install(const string &name, function< void(const AnyMap &, const UnitStack &)> &target, const function< void(const AnyMap &, const UnitStack &)> &func)
Install a function with the signature void(const AnyMap&, const UnitStack&) as being delegatable.
Definition Delegator.h:350
void setDelegate(const string &name, const function< void(span< double >, span< double >, span< double >)> &func, const string &when)
Set delegates for member functions with the signature void(span<double>, span<double>,...
Definition Delegator.h:220
void setDelegate(const string &name, const function< void(span< double >)> &func, const string &when)
Set delegates for member functions with the signature void(span<double>).
Definition Delegator.h:177
void install(const string &name, function< double(void *)> &target, const function< double(void *)> &func)
Install a function with the signature double(void*) as being delegatable.
Definition Delegator.h:406
map< string, shared_ptr< ExternalHandle > > m_handles
Handles to wrappers for the delegated object in external language interfaces.
Definition Delegator.h:600
void setDelegate(const string &name, const function< void(AnyMap &)> &func, const string &when)
set delegates for member functions with the signature void(AnyMap&)
Definition Delegator.h:138
void install(const string &name, function< void()> &target, const function< void()> &func)
Install a function with the signature void() as being delegatable.
Definition Delegator.h:317
void setDelegate(const string &name, const function< void(SparseTriplets &)> &func, const string &when)
Set delegates for member functions with the signature void(SparseTriplets&).
Definition Delegator.h:286
void setDelegate(const string &name, const function< int(size_t &, const string &)> &func, const string &when)
Set delegates for member functions with the signature size_t(string).
Definition Delegator.h:272
void setDelegate(const string &name, const function< int(double &, void *)> &func, const string &when)
set delegates for member functions with the signature double(void*)
Definition Delegator.h:234
void install(const string &name, function< void(span< double >, span< double >, span< double >)> &target, const function< void(span< double >, span< double >, span< double >)> &base)
Install a function with the signature void(span<double>, span<double>, span<double>) as being delegat...
Definition Delegator.h:397
void install(const string &name, function< void(SparseTriplets &)> &target, const function< void(SparseTriplets &)> &base)
Install a function with the signature void(SparseTriplets&) as being delegatable.
Definition Delegator.h:446
void setDelegate(const string &name, const function< void()> &func, const string &when)
Set delegates for member functions with the signature void().
Definition Delegator.h:105
void install(const string &name, function< string(size_t)> &target, const function< string(size_t)> &base)
Install a function with the signature string(size_t) as being delegatable.
Definition Delegator.h:414
string m_delegatorName
Name of the class in the extension language.
Definition Delegator.h:603
void install(const string &name, function< void(double, span< double >, span< double >)> &target, const function< void(double, span< double >, span< double >)> &func)
Install a function with the signature void(double, span<double>, span<double>) as being delegatable.
Definition Delegator.h:387
void install(const string &name, function< void(double, span< double >)> &target, const function< void(double, span< double >)> &func)
Install a function with the signature void(double, span<double>) as being delegatable.
Definition Delegator.h:377
void install(const string &name, function< void(const string &, void *)> &target, const function< void(const string &, void *)> &func)
Install a function with the signature void(const string&, void*) as being delegatable.
Definition Delegator.h:360
void setDelegate(const string &name, const function< void(double, span< double >)> &func, const string &when)
Set delegates for member functions with the signature void(double, span<double>).
Definition Delegator.h:190
span< double > stripConst(const span< const double > &s)
Helper to remove const for cases where the delegated function signature uses span<const double>.
Definition Delegator.h:537
void setDelegate(const string &name, const function< void(double, span< double >, span< double >)> &func, const string &when)
Set delegates for member functions with the signature void(double, span<double>, span<double>).
Definition Delegator.h:205
void setDelegatorName(const string &delegatorName)
Set the name of the user-defined class in the extension language.
Definition Delegator.h:100
shared_ptr< ExternalHandle > getExternalHandle(const string &name) const
Get the handle for a wrapper for the delegate from the external language interface specified by name.
Definition Delegator.h:307
void install(const string &name, function< void(span< double >)> &target, const function< void(span< double >)> &func)
Install a function with the signature void(span<double>) as being delegatable.
Definition Delegator.h:368
An error indicating that an unimplemented function has been called.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
string demangle(const std::type_info &type)
Convert a type name to a human readable string, using boost::core::demangle if available.
Definition global.cpp:213
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
Unit aggregation utility.
Definition Units.h:105