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(
double&,
size_t)>& func,
263 if (!m_funcs_d_sz.count(name)) {
265 "for function named '{}' with signature "
266 "'double(size_t)'.", name);
268 *m_funcs_d_sz[name] =
makeDelegate(name, func, when, m_base_d_sz[name]);
273 const function<
int(
size_t&,
const string&)>& func,
276 if (!m_funcs_sz_csr.count(name)) {
278 "for function '{}' with signature "
279 "'size_t(const string&)'.", name);
281 *m_funcs_sz_csr[name] =
makeDelegate(name, func, when, m_base_sz_csr[name]);
287 const function<
void(SparseTriplets&)>& func,
290 if (!m_funcs_v_vET.count(name)) {
292 "for function named '{}' with signature "
293 "'void(SparseTriplets&)'.", name);
295 *m_funcs_v_vET[name] =
makeDelegate(func, when, *m_funcs_v_vET[name]);
300 const shared_ptr<ExternalHandle>& handle) {
311 return shared_ptr<ExternalHandle>();
317 void install(
const string& name, function<
void()>& target,
318 const function<
void()>& func)
321 m_funcs_v[name] = ⌖
325 void install(
const string& name, function<
void(
bool)>& target,
326 const function<
void(
bool)>& func)
329 m_funcs_v_b[name] = ⌖
333 void install(
const string& name, function<
void(
double)>& target,
334 const function<
void(
double)>& func)
337 m_funcs_v_d[name] = ⌖
342 const function<
void(
AnyMap&)>& func)
345 m_funcs_v_AMr[name] = ⌖
355 m_funcs_v_cAMr_cUSr[name] = ⌖
360 void install(
const string& name, function<
void(
const string&,
void*)>& target,
361 const function<
void(
const string&,
void*)>& func)
364 m_funcs_v_csr_vp[name] = ⌖
369 function<
void(span<double>)>& target,
370 const function<
void(span<double>)>& func)
373 m_funcs_v_dp[name] = ⌖
378 function<
void(
double, span<double>)>& target,
379 const function<
void(
double, span<double>)>& func)
382 m_funcs_v_d_dp[name] = ⌖
388 function<
void(
double, span<double>, span<double>)>& target,
389 const function<
void(
double, span<double>, span<double>)>& func)
392 m_funcs_v_d_dp_dp[name] = ⌖
398 function<
void(span<double>, span<double>, span<double>)>& target,
399 const function<
void(span<double>, span<double>, span<double>)>& base)
402 m_funcs_v_dp_dp_dp[name] = ⌖
406 void install(
const string& name, function<
double(
void*)>& target,
407 const function<
double(
void*)>& func)
410 m_funcs_d_vp[name] = ⌖
415 function<
string(
size_t)>& target,
416 const function<
string(
size_t)>& base)
419 m_funcs_s_sz[name] = ⌖
420 m_base_s_sz[name] = base;
425 function<
double(
size_t)>& target,
426 const function<
double(
size_t)>& base)
429 m_funcs_d_sz[name] = ⌖
430 m_base_d_sz[name] = base;
435 function<
size_t(
const string&)>& target,
436 const function<
size_t(
const string&)>& base)
439 m_funcs_sz_csr[name] = ⌖
440 m_base_sz_csr[name] = base;
447 function<
void(SparseTriplets&)>& target,
448 const function<
void(SparseTriplets&)>& base)
451 m_funcs_v_vET[name] = ⌖
455 template <
typename BaseFunc,
class ... Args>
457 const function<
void(Args ...)>& func,
461 if (when ==
"before") {
462 return [base, func](Args ... args) {
466 }
else if (when ==
"after") {
467 return [base, func](Args ... args) {
471 }
else if (when ==
"replace") {
472 return [func](Args ... args) {
477 "'when' must be one of 'before', 'after', or 'replace';"
483 template <
typename ReturnType,
class ... Args>
486 const function<
int(ReturnType&, Args ...)>& func,
488 const function<ReturnType(Args ...)>& base)
490 if (when ==
"before") {
491 return [base, func](Args ... args) {
496 int done = func(ret, args ...);
500 return base(args ...);
503 }
else if (when ==
"after") {
504 return [base, func](Args ... args) {
507 ReturnType ret1 = base(args ...);
509 int done = func(ret2, args ...);
516 }
else if (when ==
"replace") {
517 return [base, name, func,
this](Args ... args) {
519 int has_ret = func(ret, args ...);
521 throw CanteraError(
"Lambda generated by Delegator::makeDelegate",
522 "Method '{}' of class '{}' did not return a value of type '{}'.",
529 "For function named '{}':\n"
530 "'when' must be one of 'before', 'after', or 'replace';"
531 " not '{}'", name, when);
538 return span<double>(
const_cast<double*
>(s.data()), s.size());
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;
576 function<void(
double, span<double>, span<double>)>*> m_funcs_v_d_dp_dp;
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;
582 map<string, function<double(
void*)>> m_base_d_vp;
583 map<string, function<double(
void*)>*> m_funcs_d_vp;
586 map<string, function<string(
size_t)>> m_base_s_sz;
587 map<string, function<string(
size_t)>*> m_funcs_s_sz;
590 map<string, function<double(
size_t)>> m_base_d_sz;
591 map<string, function<double(
size_t)>*> m_funcs_d_sz;
593 map<string, function<size_t(
const string&)>> m_base_sz_csr;
594 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 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.
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).
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.