Cantera  4.0.0a1
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.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.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
100 void setDelegatorName(const string& delegatorName) {
102 }
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 `size_t(string)`
259 void setDelegate(const string& name,
260 const function<int(size_t&, const string&)>& func,
261 const string& when)
262 {
263 if (!m_funcs_sz_csr.count(name)) {
264 throw NotImplementedError("Delegator::setDelegate",
265 "for function '{}' with signature "
266 "'size_t(const string&)'.", name);
267 }
268 *m_funcs_sz_csr[name] = makeDelegate(name, func, when, m_base_sz_csr[name]);
269 }
270
271 //! Set delegates for member functions with the signature `void(SparseTriplets&)`
272 //! @since New in %Cantera 4.0.
273 void setDelegate(const string& name,
274 const function<void(SparseTriplets&)>& func,
275 const string& when)
276 {
277 if (!m_funcs_v_vET.count(name)) {
278 throw NotImplementedError("Delegator::setDelegate",
279 "for function named '{}' with signature "
280 "'void(SparseTriplets&)'.", name);
281 }
282 *m_funcs_v_vET[name] = makeDelegate(func, when, *m_funcs_v_vET[name]);
283 }
284
285 //! Store a handle to a wrapper for the delegate from an external language interface
286 void holdExternalHandle(const string& name,
287 const shared_ptr<ExternalHandle>& handle) {
288 m_handles[name] = handle;
289 }
290
291 //! Get the handle for a wrapper for the delegate from the external language
292 //! interface specified by *name*.
293 //! Returns a null pointer if the requested handle does not exist.
294 shared_ptr<ExternalHandle> getExternalHandle(const string& name) const {
295 if (m_handles.count(name)) {
296 return m_handles.at(name);
297 } else {
298 return shared_ptr<ExternalHandle>();
299 }
300 }
301
302protected:
303 //! Install a function with the signature `void()` as being delegatable
304 void install(const string& name, function<void()>& target,
305 const function<void()>& func)
306 {
307 target = func;
308 m_funcs_v[name] = &target;
309 }
310
311 //! Install a function with the signature `void(bool)` as being delegatable
312 void install(const string& name, function<void(bool)>& target,
313 const function<void(bool)>& func)
314 {
315 target = func;
316 m_funcs_v_b[name] = &target;
317 }
318
319 //! Install a function with the signature `void(double)` as being delegatable
320 void install(const string& name, function<void(double)>& target,
321 const function<void(double)>& func)
322 {
323 target = func;
324 m_funcs_v_d[name] = &target;
325 }
326
327 //! Install a function with the signature `void(AnyMap&)` as being delegatable
328 void install(const string& name, function<void(AnyMap&)>& target,
329 const function<void(AnyMap&)>& func)
330 {
331 target = func;
332 m_funcs_v_AMr[name] = &target;
333 }
334
335 //! Install a function with the signature `void(const AnyMap&, const UnitStack&)`
336 //! as being delegatable
337 void install(const string& name,
338 function<void(const AnyMap&, const UnitStack&)>& target,
339 const function<void(const AnyMap&, const UnitStack&)>& func)
340 {
341 target = func;
342 m_funcs_v_cAMr_cUSr[name] = &target;
343 }
344
345 //! Install a function with the signature `void(const string&, void*)` as being
346 //! delegatable
347 void install(const string& name, function<void(const string&, void*)>& target,
348 const function<void(const string&, void*)>& func)
349 {
350 target = func;
351 m_funcs_v_csr_vp[name] = &target;
352 }
353
354 //! Install a function with the signature `void(span<double>)` as being delegatable
355 void install(const string& name,
356 function<void(span<double>)>& target,
357 const function<void(span<double>)>& func)
358 {
359 target = func;
360 m_funcs_v_dp[name] = &target;
361 }
362
363 //! Install a function with the signature `void(double, span<double>)` as being delegatable
364 void install(const string& name,
365 function<void(double, span<double>)>& target,
366 const function<void(double, span<double>)>& func)
367 {
368 target = func;
369 m_funcs_v_d_dp[name] = &target;
370 }
371
372 //! Install a function with the signature `void(double, span<double>, span<double>)`
373 //! as being delegatable
374 void install(const string& name,
375 function<void(double, span<double>, span<double>)>& target,
376 const function<void(double, span<double>, span<double>)>& func)
377 {
378 target = func;
379 m_funcs_v_d_dp_dp[name] = &target;
380 }
381
382 //! Install a function with the signature
383 //! `void(span<double>, span<double>, span<double>)` as being delegatable
384 void install(const string& name,
385 function<void(span<double>, span<double>, span<double>)>& target,
386 const function<void(span<double>, span<double>, span<double>)>& base)
387 {
388 target = base;
389 m_funcs_v_dp_dp_dp[name] = &target;
390 }
391
392 //! Install a function with the signature `double(void*)` as being delegatable
393 void install(const string& name, function<double(void*)>& target,
394 const function<double(void*)>& func)
395 {
396 target = func;
397 m_funcs_d_vp[name] = &target;
398 }
399
400 //! Install a function with the signature `string(size_t)` as being delegatable
401 void install(const string& name,
402 function<string(size_t)>& target,
403 const function<string(size_t)>& base)
404 {
405 target = base;
406 m_funcs_s_sz[name] = &target;
407 m_base_s_sz[name] = base;
408 }
409
410 //! Install a function with the signature `size_t(string)` as being delegatable
411 void install(const string& name,
412 function<size_t(const string&)>& target,
413 const function<size_t(const string&)>& base)
414 {
415 target = base;
416 m_funcs_sz_csr[name] = &target;
417 m_base_sz_csr[name] = base;
418 }
419
420 //! Install a function with the signature `void(SparseTriplets&)`
421 //! as being delegatable
422 //! @since New in %Cantera 4.0.
423 void install(const string& name,
424 function<void(SparseTriplets&)>& target,
425 const function<void(SparseTriplets&)>& base)
426 {
427 target = base;
428 m_funcs_v_vET[name] = &target;
429 }
430
431 //! Create a delegate for a function with no return value
432 template <typename BaseFunc, class ... Args>
433 function<void(Args ...)> makeDelegate(
434 const function<void(Args ...)>& func,
435 const string& when,
436 BaseFunc base)
437 {
438 if (when == "before") {
439 return [base, func](Args ... args) {
440 func(args ...);
441 base(args ...);
442 };
443 } else if (when == "after") {
444 return [base, func](Args ... args) {
445 base(args ...);
446 func(args ...);
447 };
448 } else if (when == "replace") {
449 return [func](Args ... args) {
450 func(args ...);
451 };
452 } else {
453 throw CanteraError("Delegator::makeDelegate",
454 "'when' must be one of 'before', 'after', or 'replace';"
455 " not '{}", when);
456 }
457 }
458
459 //! Create a delegate for a function with a return value
460 template <typename ReturnType, class ... Args>
461 function<ReturnType(Args ...)> makeDelegate(
462 const string& name,
463 const function<int(ReturnType&, Args ...)>& func,
464 const string& when,
465 const function<ReturnType(Args ...)>& base)
466 {
467 if (when == "before") {
468 return [base, func](Args ... args) {
469 // Call the provided delegate first. If it sets the return
470 // value, return that, otherwise return the value from the
471 // original method
472 ReturnType ret;
473 int done = func(ret, args ...);
474 if (done) {
475 return ret;
476 } else {
477 return base(args ...);
478 }
479 };
480 } else if (when == "after") {
481 return [base, func](Args ... args) {
482 // Add the value returned by the original method and the
483 // provided delegate
484 ReturnType ret1 = base(args ...);
485 ReturnType ret2;
486 int done = func(ret2, args ...);
487 if (done) {
488 return ret1 + ret2;
489 } else {
490 return ret1;
491 }
492 };
493 } else if (when == "replace") {
494 return [base, name, func, this](Args ... args) {
495 ReturnType ret;
496 int has_ret = func(ret, args ...);
497 if (!has_ret) {
498 throw CanteraError("Lambda generated by Delegator::makeDelegate",
499 "Method '{}' of class '{}' did not return a value of type '{}'.",
500 name, delegatorName(), demangle(typeid(ret)));
501 }
502 return ret;
503 };
504 } else {
505 throw CanteraError("Delegator::makeDelegate",
506 "For function named '{}':\n"
507 "'when' must be one of 'before', 'after', or 'replace';"
508 " not '{}'", name, when);
509 }
510 }
511
512 //! Helper to remove const for cases where the delegated function signature uses
513 //! `span<const double>`.
514 span<double> stripConst(const span<const double>& s) {
515 return span<double>(const_cast<double*>(s.data()), s.size());
516 }
517
518 //! @name Containers for delegates and base class implementations.
519 //!
520 //! Maps named `m_funcs_*` hold the current delegate. For functions with a return
521 //! value, `m_base_*` holds a pointer to the base class's implementation of the
522 //! function.
523 //!
524 //! These containers use a naming scheme based on the signature of the corresponding
525 //! member functions. Following the prefix `_m_funcs_` is a notation of the return
526 //! type, followed by an underscore, then the notations for each argument, separated
527 //! by underscores. The following shorthand is used for different return / argument
528 //! types:
529 //!
530 //! - `v` for `void`
531 //! - `b` for `bool`
532 //! - `d` for `double`
533 //! - `s` for `string`
534 //! - `sz` for `size_t`
535 //! - `AM` for `AnyMap`
536 //! - `US` for `UnitStack`
537 //! - `ET` for `Eigen::Triplet<double>`
538 //! - prefix `c` for `const` arguments
539 //! - suffix `r` for reference arguments
540 //! - suffix `p` for span arguments (for example, `dp` for `span<double>`)
541 //! @{
542
543 // Delegates with no return value
544 map<string, function<void()>*> m_funcs_v;
545 map<string, function<void(bool)>*> m_funcs_v_b;
546 map<string, function<void(double)>*> m_funcs_v_d;
547 map<string, function<void(AnyMap&)>*> m_funcs_v_AMr;
548 map<string, function<void(const AnyMap&, const UnitStack&)>*> m_funcs_v_cAMr_cUSr;
549 map<string, function<void(const string&, void*)>*> m_funcs_v_csr_vp;
550 map<string, function<void(span<double>)>*> m_funcs_v_dp;
551 map<string, function<void(double, span<double>)>*> m_funcs_v_d_dp;
552 map<string,
553 function<void(double, span<double>, span<double>)>*> m_funcs_v_d_dp_dp;
554 map<string,
555 function<void(span<double>, span<double>, span<double>)>*> m_funcs_v_dp_dp_dp;
556 map<string, function<void(SparseTriplets&)>*> m_funcs_v_vET;
557
558 // Delegates with a return value
559 map<string, function<double(void*)>> m_base_d_vp;
560 map<string, function<double(void*)>*> m_funcs_d_vp;
561
562 map<string, function<string(size_t)>> m_base_s_sz;
563 map<string, function<string(size_t)>*> m_funcs_s_sz;
564
565 map<string, function<size_t(const string&)>> m_base_sz_csr;
566 map<string, function<size_t(const string&)>*> m_funcs_sz_csr;
567 //! @}
568
569 //! Handles to wrappers for the delegated object in external language interfaces.
570 //! Used to provide access to these wrappers as well as managing cleanup functions
571 //! called from the destructor of the derived ExternalHandle class.
572 map<string, shared_ptr<ExternalHandle>> m_handles;
573
574 //! Name of the class in the extension language
576};
577
578}
579
580#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:320
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:461
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:312
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:286
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:328
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:411
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:433
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:337
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:393
map< string, shared_ptr< ExternalHandle > > m_handles
Handles to wrappers for the delegated object in external language interfaces.
Definition Delegator.h:572
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:304
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:273
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:259
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:384
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:423
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:401
string m_delegatorName
Name of the class in the extension language.
Definition Delegator.h:575
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:374
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:364
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:347
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:514
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:294
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:355
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