104 void setDelegate(
const string& name,
const function<
void()>& func,
107 if (!m_funcs_v.count(name)) {
109 "for function named '{}' with signature 'void()'.", name);
111 *m_funcs_v[name] =
makeDelegate(func, when, *m_funcs_v[name]);
115 void setDelegate(
const string& name,
const function<
void(
bool)>& func,
118 if (!m_funcs_v_b.count(name)) {
120 "for function named '{}' with signature 'void(bool)'.", name);
122 *m_funcs_v_b[name] =
makeDelegate(func, when, *m_funcs_v_b[name]);
126 void setDelegate(
const string& name,
const function<
void(
double)>& func,
129 if (!m_funcs_v_d.count(name)) {
131 "for function named '{}' with signature 'void(double)'.", name);
133 *m_funcs_v_d[name] =
makeDelegate(func, when, *m_funcs_v_d[name]);
140 if (!m_funcs_v_AMr.count(name)) {
142 "for function named '{}' with signature 'void(AnyMap&)'.", name);
144 *m_funcs_v_AMr[name] =
makeDelegate(func, when, *m_funcs_v_AMr[name]);
153 if (!m_funcs_v_cAMr_cUSr.count(name)) {
155 "for function named '{}' with signature "
156 "'void(const AnyMap&, const UnitStack&)'.",
159 *m_funcs_v_cAMr_cUSr[name] =
makeDelegate(func, when, *m_funcs_v_cAMr_cUSr[name]);
165 const function<
void(
const string&,
void*)>& func,
168 if (!m_funcs_v_csr_vp.count(name)) {
170 "for function named '{}' with signature 'void(const string&, void*)'.");
172 *m_funcs_v_csr_vp[name] =
makeDelegate(func, when, *m_funcs_v_csr_vp[name]);
177 const function<
void(span<double>)>& func,
180 if (!m_funcs_v_dp.count(name)) {
182 "for function named '{}' with signature 'void(span<double>)'.", name);
184 *m_funcs_v_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp[name]);
191 const function<
void(
double, span<double>)>& func,
194 if (!m_funcs_v_d_dp.count(name)) {
196 "for function named '{}' with signature 'void(double, span<double>)'.",
199 *m_funcs_v_d_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp[name]);
206 const function<
void(
double, span<double>, span<double>)>& func,
209 if (!m_funcs_v_d_dp_dp.count(name)) {
211 "for function named '{}' with signature "
212 "'void(double, span<double>, span<double>)'.", name);
214 *m_funcs_v_d_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp_dp[name]);
221 const function<
void(span<double>, span<double>, span<double>)>& func,
224 if (!m_funcs_v_dp_dp_dp.count(name)) {
226 "for function named '{}' with signature "
227 "'void(span<double>, span<double>, span<double>)'.", name);
229 *m_funcs_v_dp_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp_dp_dp[name]);
234 const function<
int(
double&,
void*)>& func,
237 if (!m_funcs_d_vp.count(name)) {
239 "for function named '{}' with signature 'double(void*)'.", name);
241 *m_funcs_d_vp[name] =
makeDelegate(name, func, when, m_base_d_vp[name]);
246 const function<
int(
string&,
size_t)>& func,
249 if (!m_funcs_s_sz.count(name)) {
251 "for function named '{}' with signature "
252 "'string(size_t)'.", name);
254 *m_funcs_s_sz[name] =
makeDelegate(name, func, when, m_base_s_sz[name]);
259 const function<
int(
size_t&,
const string&)>& func,
262 if (!m_funcs_sz_csr.count(name)) {
264 "for function '{}' with signature "
265 "'size_t(const string&)'.", name);
267 *m_funcs_sz_csr[name] =
makeDelegate(name, func, when, m_base_sz_csr[name]);
272 const shared_ptr<ExternalHandle>& handle) {
283 return shared_ptr<ExternalHandle>();
289 void install(
const string& name, function<
void()>& target,
290 const function<
void()>& func)
293 m_funcs_v[name] = ⌖
297 void install(
const string& name, function<
void(
bool)>& target,
298 const function<
void(
bool)>& func)
301 m_funcs_v_b[name] = ⌖
305 void install(
const string& name, function<
void(
double)>& target,
306 const function<
void(
double)>& func)
309 m_funcs_v_d[name] = ⌖
314 const function<
void(
AnyMap&)>& func)
317 m_funcs_v_AMr[name] = ⌖
327 m_funcs_v_cAMr_cUSr[name] = ⌖
332 void install(
const string& name, function<
void(
const string&,
void*)>& target,
333 const function<
void(
const string&,
void*)>& func)
336 m_funcs_v_csr_vp[name] = ⌖
341 function<
void(span<double>)>& target,
342 const function<
void(span<double>)>& func)
345 m_funcs_v_dp[name] = ⌖
350 function<
void(
double, span<double>)>& target,
351 const function<
void(
double, span<double>)>& func)
354 m_funcs_v_d_dp[name] = ⌖
360 function<
void(
double, span<double>, span<double>)>& target,
361 const function<
void(
double, span<double>, span<double>)>& func)
364 m_funcs_v_d_dp_dp[name] = ⌖
370 function<
void(span<double>, span<double>, span<double>)>& target,
371 const function<
void(span<double>, span<double>, span<double>)>& base)
374 m_funcs_v_dp_dp_dp[name] = ⌖
378 void install(
const string& name, function<
double(
void*)>& target,
379 const function<
double(
void*)>& func)
382 m_funcs_d_vp[name] = ⌖
387 function<
string(
size_t)>& target,
388 const function<
string(
size_t)>& base)
391 m_funcs_s_sz[name] = ⌖
392 m_base_s_sz[name] = base;
397 function<
size_t(
const string&)>& target,
398 const function<
size_t(
const string&)>& base)
401 m_funcs_sz_csr[name] = ⌖
402 m_base_sz_csr[name] = base;
406 template <
typename BaseFunc,
class ... Args>
408 const function<
void(Args ...)>& func,
412 if (when ==
"before") {
413 return [base, func](Args ... args) {
417 }
else if (when ==
"after") {
418 return [base, func](Args ... args) {
422 }
else if (when ==
"replace") {
423 return [func](Args ... args) {
428 "'when' must be one of 'before', 'after', or 'replace';"
434 template <
typename ReturnType,
class ... Args>
437 const function<
int(ReturnType&, Args ...)>& func,
439 const function<ReturnType(Args ...)>& base)
441 if (when ==
"before") {
442 return [base, func](Args ... args) {
447 int done = func(ret, args ...);
451 return base(args ...);
454 }
else if (when ==
"after") {
455 return [base, func](Args ... args) {
458 ReturnType ret1 = base(args ...);
460 int done = func(ret2, args ...);
467 }
else if (when ==
"replace") {
468 return [base, name, func,
this](Args ... args) {
470 int has_ret = func(ret, args ...);
472 throw CanteraError(
"Lambda generated by Delegator::makeDelegate",
473 "Method '{}' of class '{}' did not return a value of type '{}'.",
480 "For function named '{}':\n"
481 "'when' must be one of 'before', 'after', or 'replace';"
482 " not '{}'", name, when);
489 return span<double>(
const_cast<double*
>(s.data()), s.size());
517 map<string, function<void()>*> m_funcs_v;
518 map<string, function<void(
bool)>*> m_funcs_v_b;
519 map<string, function<void(
double)>*> m_funcs_v_d;
520 map<string, function<void(
AnyMap&)>*> m_funcs_v_AMr;
521 map<string, function<void(
const AnyMap&,
const UnitStack&)>*> m_funcs_v_cAMr_cUSr;
522 map<string, function<void(
const string&,
void*)>*> m_funcs_v_csr_vp;
523 map<string, function<void(span<double>)>*> m_funcs_v_dp;
524 map<string, function<void(
double, span<double>)>*> m_funcs_v_d_dp;
526 function<void(
double, span<double>, span<double>)>*> m_funcs_v_d_dp_dp;
528 function<void(span<double>, span<double>, span<double>)>*> m_funcs_v_dp_dp_dp;
531 map<string, function<double(
void*)>> m_base_d_vp;
532 map<string, function<double(
void*)>*> m_funcs_d_vp;
534 map<string, function<string(
size_t)>> m_base_s_sz;
535 map<string, function<string(
size_t)>*> m_funcs_s_sz;
537 map<string, function<size_t(
const string&)>> m_base_sz_csr;
538 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< 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 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.