13#include "cantera/numerics/eigen_sparse.h"
105 void setDelegate(
const string& name,
const function<
void()>& func,
108 if (!m_funcs_v.count(name)) {
110 "for function named '{}' with signature 'void()'.", name);
112 *m_funcs_v[name] =
makeDelegate(func, when, *m_funcs_v[name]);
116 void setDelegate(
const string& name,
const function<
void(
bool)>& func,
119 if (!m_funcs_v_b.count(name)) {
121 "for function named '{}' with signature 'void(bool)'.", name);
123 *m_funcs_v_b[name] =
makeDelegate(func, when, *m_funcs_v_b[name]);
127 void setDelegate(
const string& name,
const function<
void(
double)>& func,
130 if (!m_funcs_v_d.count(name)) {
132 "for function named '{}' with signature 'void(double)'.", name);
134 *m_funcs_v_d[name] =
makeDelegate(func, when, *m_funcs_v_d[name]);
141 if (!m_funcs_v_AMr.count(name)) {
143 "for function named '{}' with signature 'void(AnyMap&)'.", name);
145 *m_funcs_v_AMr[name] =
makeDelegate(func, when, *m_funcs_v_AMr[name]);
154 if (!m_funcs_v_cAMr_cUSr.count(name)) {
156 "for function named '{}' with signature "
157 "'void(const AnyMap&, const UnitStack&)'.",
160 *m_funcs_v_cAMr_cUSr[name] =
makeDelegate(func, when, *m_funcs_v_cAMr_cUSr[name]);
166 const function<
void(
const string&,
void*)>& func,
169 if (!m_funcs_v_csr_vp.count(name)) {
171 "for function named '{}' with signature 'void(const string&, void*)'.");
173 *m_funcs_v_csr_vp[name] =
makeDelegate(func, when, *m_funcs_v_csr_vp[name]);
178 const function<
void(span<double>)>& func,
181 if (!m_funcs_v_dp.count(name)) {
183 "for function named '{}' with signature 'void(span<double>)'.", name);
185 *m_funcs_v_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp[name]);
192 const function<
void(
double, span<double>)>& func,
195 if (!m_funcs_v_d_dp.count(name)) {
197 "for function named '{}' with signature 'void(double, span<double>)'.",
200 *m_funcs_v_d_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp[name]);
207 const function<
void(
double, span<double>, span<double>)>& func,
210 if (!m_funcs_v_d_dp_dp.count(name)) {
212 "for function named '{}' with signature "
213 "'void(double, span<double>, span<double>)'.", name);
215 *m_funcs_v_d_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp_dp[name]);
222 const function<
void(span<double>, span<double>, span<double>)>& func,
225 if (!m_funcs_v_dp_dp_dp.count(name)) {
227 "for function named '{}' with signature "
228 "'void(span<double>, span<double>, span<double>)'.", name);
230 *m_funcs_v_dp_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp_dp_dp[name]);
235 const function<
int(
double&,
void*)>& func,
238 if (!m_funcs_d_vp.count(name)) {
240 "for function named '{}' with signature 'double(void*)'.", name);
242 *m_funcs_d_vp[name] =
makeDelegate(name, func, when, m_base_d_vp[name]);
247 const function<
int(
string&,
size_t)>& func,
250 if (!m_funcs_s_sz.count(name)) {
252 "for function named '{}' with signature "
253 "'string(size_t)'.", name);
255 *m_funcs_s_sz[name] =
makeDelegate(name, func, when, m_base_s_sz[name]);
260 const function<
int(
size_t&,
const string&)>& func,
263 if (!m_funcs_sz_csr.count(name)) {
265 "for function '{}' with signature "
266 "'size_t(const string&)'.", name);
268 *m_funcs_sz_csr[name] =
makeDelegate(name, func, when, m_base_sz_csr[name]);
274 const function<
void(SparseTriplets&)>& func,
277 if (!m_funcs_v_vET.count(name)) {
279 "for function named '{}' with signature "
280 "'void(SparseTriplets&)'.", name);
282 *m_funcs_v_vET[name] =
makeDelegate(func, when, *m_funcs_v_vET[name]);
287 const shared_ptr<ExternalHandle>& handle) {
298 return shared_ptr<ExternalHandle>();
304 void install(
const string& name, function<
void()>& target,
305 const function<
void()>& func)
308 m_funcs_v[name] = ⌖
312 void install(
const string& name, function<
void(
bool)>& target,
313 const function<
void(
bool)>& func)
316 m_funcs_v_b[name] = ⌖
320 void install(
const string& name, function<
void(
double)>& target,
321 const function<
void(
double)>& func)
324 m_funcs_v_d[name] = ⌖
329 const function<
void(
AnyMap&)>& func)
332 m_funcs_v_AMr[name] = ⌖
342 m_funcs_v_cAMr_cUSr[name] = ⌖
347 void install(
const string& name, function<
void(
const string&,
void*)>& target,
348 const function<
void(
const string&,
void*)>& func)
351 m_funcs_v_csr_vp[name] = ⌖
356 function<
void(span<double>)>& target,
357 const function<
void(span<double>)>& func)
360 m_funcs_v_dp[name] = ⌖
365 function<
void(
double, span<double>)>& target,
366 const function<
void(
double, span<double>)>& func)
369 m_funcs_v_d_dp[name] = ⌖
375 function<
void(
double, span<double>, span<double>)>& target,
376 const function<
void(
double, span<double>, span<double>)>& func)
379 m_funcs_v_d_dp_dp[name] = ⌖
385 function<
void(span<double>, span<double>, span<double>)>& target,
386 const function<
void(span<double>, span<double>, span<double>)>& base)
389 m_funcs_v_dp_dp_dp[name] = ⌖
393 void install(
const string& name, function<
double(
void*)>& target,
394 const function<
double(
void*)>& func)
397 m_funcs_d_vp[name] = ⌖
402 function<
string(
size_t)>& target,
403 const function<
string(
size_t)>& base)
406 m_funcs_s_sz[name] = ⌖
407 m_base_s_sz[name] = base;
412 function<
size_t(
const string&)>& target,
413 const function<
size_t(
const string&)>& base)
416 m_funcs_sz_csr[name] = ⌖
417 m_base_sz_csr[name] = base;
424 function<
void(SparseTriplets&)>& target,
425 const function<
void(SparseTriplets&)>& base)
428 m_funcs_v_vET[name] = ⌖
432 template <
typename BaseFunc,
class ... Args>
434 const function<
void(Args ...)>& func,
438 if (when ==
"before") {
439 return [base, func](Args ... args) {
443 }
else if (when ==
"after") {
444 return [base, func](Args ... args) {
448 }
else if (when ==
"replace") {
449 return [func](Args ... args) {
454 "'when' must be one of 'before', 'after', or 'replace';"
460 template <
typename ReturnType,
class ... Args>
463 const function<
int(ReturnType&, Args ...)>& func,
465 const function<ReturnType(Args ...)>& base)
467 if (when ==
"before") {
468 return [base, func](Args ... args) {
473 int done = func(ret, args ...);
477 return base(args ...);
480 }
else if (when ==
"after") {
481 return [base, func](Args ... args) {
484 ReturnType ret1 = base(args ...);
486 int done = func(ret2, args ...);
493 }
else if (when ==
"replace") {
494 return [base, name, func,
this](Args ... args) {
496 int has_ret = func(ret, args ...);
498 throw CanteraError(
"Lambda generated by Delegator::makeDelegate",
499 "Method '{}' of class '{}' did not return a value of type '{}'.",
506 "For function named '{}':\n"
507 "'when' must be one of 'before', 'after', or 'replace';"
508 " not '{}'", name, when);
515 return span<double>(
const_cast<double*
>(s.data()), s.size());
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;
553 function<void(
double, span<double>, span<double>)>*> m_funcs_v_d_dp_dp;
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;
559 map<string, function<double(
void*)>> m_base_d_vp;
560 map<string, function<double(
void*)>*> m_funcs_d_vp;
562 map<string, function<string(
size_t)>> m_base_s_sz;
563 map<string, function<string(
size_t)>*> m_funcs_s_sz;
565 map<string, function<size_t(
const string&)>> m_base_sz_csr;
566 map<string, function<size_t(
const string&)>*> m_funcs_sz_csr;
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.
Base class for exceptions thrown by Cantera classes.
Delegate member functions of a C++ class to externally-specified functions.
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.
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.
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&)
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)
void setDelegate(const string &name, const function< void(bool)> &func, const string &when)
set delegates for member functions with the signature void(bool)
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.
void holdExternalHandle(const string &name, const shared_ptr< ExternalHandle > &handle)
Store a handle to a wrapper for the delegate from an external language interface.
string delegatorName() const
Get the name of the user-defined class in the extension language.
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.
void setDelegate(const string &name, const function< void(double)> &func, const string &when)
set delegates for member functions with the signature void(double)
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*)
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.
function< void(Args ...)> makeDelegate(const function< void(Args ...)> &func, const string &when, BaseFunc base)
Create a delegate for a function with no return value.
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.
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>,...
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>)
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.
map< string, shared_ptr< ExternalHandle > > m_handles
Handles to wrappers for the delegated object in external language interfaces.
void setDelegate(const string &name, const function< void(AnyMap &)> &func, const string &when)
set delegates for member functions with the signature void(AnyMap&)
void install(const string &name, function< void()> &target, const function< void()> &func)
Install a function with the signature void() as being delegatable.
void setDelegate(const string &name, const function< void(SparseTriplets &)> &func, const string &when)
Set delegates for member functions with the signature void(SparseTriplets&)
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)
void setDelegate(const string &name, const function< int(double &, void *)> &func, const string &when)
set delegates for member functions with the signature double(void*)
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...
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.
void setDelegate(const string &name, const function< void()> &func, const string &when)
Set delegates for member functions with the signature void().
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.
string m_delegatorName
Name of the class in the extension language.
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.
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.
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.
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>)
span< double > stripConst(const span< const double > &s)
Helper to remove const for cases where the delegated function signature uses span<const double>.
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>)
void setDelegatorName(const string &delegatorName)
Set the name of the user-defined class in the extension language.
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.
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.
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.
Namespace for the Cantera kernel.
Unit aggregation utility.