117 void setDelegate(
const string& name,
const function<
void()>& func,
120 if (!m_funcs_v.count(name)) {
122 "for function named '{}' with signature 'void()'.", name);
124 *m_funcs_v[name] =
makeDelegate(func, when, *m_funcs_v[name]);
128 void setDelegate(
const string& name,
const function<
void(
bool)>& func,
131 if (!m_funcs_v_b.count(name)) {
133 "for function named '{}' with signature 'void(bool)'.", name);
135 *m_funcs_v_b[name] =
makeDelegate(func, when, *m_funcs_v_b[name]);
139 void setDelegate(
const string& name,
const function<
void(
double)>& func,
142 if (!m_funcs_v_d.count(name)) {
144 "for function named '{}' with signature 'void(double)'.", name);
146 *m_funcs_v_d[name] =
makeDelegate(func, when, *m_funcs_v_d[name]);
153 if (!m_funcs_v_AMr.count(name)) {
155 "for function named '{}' with signature 'void(AnyMap&)'.", name);
157 *m_funcs_v_AMr[name] =
makeDelegate(func, when, *m_funcs_v_AMr[name]);
166 if (!m_funcs_v_cAMr_cUSr.count(name)) {
168 "for function named '{}' with signature "
169 "'void(const AnyMap&, const UnitStack&)'.",
172 *m_funcs_v_cAMr_cUSr[name] =
makeDelegate(func, when, *m_funcs_v_cAMr_cUSr[name]);
178 const function<
void(
const string&,
void*)>& func,
181 if (!m_funcs_v_csr_vp.count(name)) {
183 "for function named '{}' with signature 'void(const string&, void*)'.");
185 *m_funcs_v_csr_vp[name] =
makeDelegate(func, when, *m_funcs_v_csr_vp[name]);
190 const function<
void(std::array<size_t, 1>,
double*)>& func,
193 if (!m_funcs_v_dp.count(name)) {
195 "for function named '{}' with signature 'void(double*)'.", name);
197 *m_funcs_v_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp[name]);
203 const function<
void(std::array<size_t, 1>,
double,
double*)>& func,
206 if (!m_funcs_v_d_dp.count(name)) {
208 "for function named '{}' with signature 'void(double, double*)'.",
211 *m_funcs_v_d_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp[name]);
218 const function<
void(std::array <size_t, 2>,
double,
double*,
double*)>& func,
221 if (!m_funcs_v_d_dp_dp.count(name)) {
223 "for function named '{}' with signature "
224 "'void(double, double*, double*)'.", name);
226 *m_funcs_v_d_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp_dp[name]);
233 const function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& func,
236 if (!m_funcs_v_dp_dp_dp.count(name)) {
238 "for function named '{}' with signature "
239 "'void(double*, double*, double*)'.", name);
241 *m_funcs_v_dp_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp_dp_dp[name]);
246 const function<
int(
double&,
void*)>& func,
249 if (!m_funcs_d_vp.count(name)) {
251 "for function named '{}' with signature 'double(void*)'.", name);
253 *m_funcs_d_vp[name] =
makeDelegate(name, func, when, m_base_d_vp[name]);
258 const function<
int(
string&,
size_t)>& func,
261 if (!m_funcs_s_sz.count(name)) {
263 "for function named '{}' with signature "
264 "'string(size_t)'.", name);
266 *m_funcs_s_sz[name] =
makeDelegate(name, func, when, m_base_s_sz[name]);
271 const function<
int(
size_t&,
const string&)>& func,
274 if (!m_funcs_sz_csr.count(name)) {
276 "for function '{}' with signature "
277 "'size_t(const string&)'.", name);
279 *m_funcs_sz_csr[name] =
makeDelegate(name, func, when, m_base_sz_csr[name]);
284 const shared_ptr<ExternalHandle>& handle) {
295 return shared_ptr<ExternalHandle>();
301 void install(
const string& name, function<
void()>& target,
302 const function<
void()>& func)
305 m_funcs_v[name] = ⌖
309 void install(
const string& name, function<
void(
bool)>& target,
310 const function<
void(
bool)>& func)
313 m_funcs_v_b[name] = ⌖
317 void install(
const string& name, function<
void(
double)>& target,
318 const function<
void(
double)>& func)
321 m_funcs_v_d[name] = ⌖
326 const function<
void(
AnyMap&)>& func)
329 m_funcs_v_AMr[name] = ⌖
339 m_funcs_v_cAMr_cUSr[name] = ⌖
344 void install(
const string& name, function<
void(
const string&,
void*)>& target,
345 const function<
void(
const string&,
void*)>& func)
348 m_funcs_v_csr_vp[name] = ⌖
353 function<
void(std::array<size_t, 1>,
double*)>& target,
354 const function<
void(std::array<size_t, 1>,
double*)>& func)
357 m_funcs_v_dp[name] = ⌖
362 function<
void(std::array<size_t, 1>,
double,
double*)>& target,
363 const function<
void(std::array<size_t, 1>,
double,
double*)>& func)
366 m_funcs_v_d_dp[name] = ⌖
372 function<
void(std::array<size_t, 2>,
double,
double*,
double*)>& target,
373 const function<
void(std::array<size_t, 2>,
double,
double*,
double*)>& func)
376 m_funcs_v_d_dp_dp[name] = ⌖
382 function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& target,
383 const function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& base)
386 m_funcs_v_dp_dp_dp[name] = ⌖
390 void install(
const string& name, function<
double(
void*)>& target,
391 const function<
double(
void*)>& func)
394 m_funcs_d_vp[name] = ⌖
399 function<
string(
size_t)>& target,
400 const function<
string(
size_t)>& base)
403 m_funcs_s_sz[name] = ⌖
404 m_base_s_sz[name] = base;
409 function<
size_t(
const string&)>& target,
410 const function<
size_t(
const string&)>& base)
413 m_funcs_sz_csr[name] = ⌖
414 m_base_sz_csr[name] = base;
418 template <
typename BaseFunc,
class ... Args>
420 const function<
void(Args ...)>& func,
424 if (when ==
"before") {
425 return [base, func](Args ... args) {
429 }
else if (when ==
"after") {
430 return [base, func](Args ... args) {
434 }
else if (when ==
"replace") {
435 return [func](Args ... args) {
440 "'when' must be one of 'before', 'after', or 'replace';"
446 template <
typename ReturnType,
class ... Args>
449 const function<
int(ReturnType&, Args ...)>& func,
451 const function<ReturnType(Args ...)>& base)
453 if (when ==
"before") {
454 return [base, func](Args ... args) {
459 int done = func(ret, args ...);
463 return base(args ...);
466 }
else if (when ==
"after") {
467 return [base, func](Args ... args) {
470 ReturnType ret1 = base(args ...);
472 int done = func(ret2, args ...);
479 }
else if (when ==
"replace") {
480 return [base, name, func,
this](Args ... args) {
482 int has_ret = func(ret, args ...);
484 throw CanteraError(
"Lambda generated by Delegator::makeDelegate",
485 "Method '{}' of class '{}' did not return a value of type '{}'.",
492 "For function named '{}':\n"
493 "'when' must be one of 'before', 'after', or 'replace';"
494 " not '{}'", name, when);
523 map<string, function<void()>*> m_funcs_v;
524 map<string, function<void(
bool)>*> m_funcs_v_b;
525 map<string, function<void(
double)>*> m_funcs_v_d;
526 map<string, function<void(
AnyMap&)>*> m_funcs_v_AMr;
527 map<string, function<void(
const AnyMap&,
const UnitStack&)>*> m_funcs_v_cAMr_cUSr;
528 map<string, function<void(
const string&,
void*)>*> m_funcs_v_csr_vp;
529 map<string, function<void(std::array<size_t, 1>,
double*)>*> m_funcs_v_dp;
530 map<string, function<void(std::array<size_t, 1>,
double,
double*)>*> m_funcs_v_d_dp;
532 function<void(std::array<size_t, 2>,
double,
double*,
double*)>*> m_funcs_v_d_dp_dp;
534 function<void(std::array<size_t, 3>,
double*,
double*,
double*)>*> m_funcs_v_dp_dp_dp;
537 map<string, function<double(
void*)>> m_base_d_vp;
538 map<string, function<double(
void*)>*> m_funcs_d_vp;
540 map<string, function<string(
size_t)>> m_base_s_sz;
541 map<string, function<string(
size_t)>*> m_funcs_s_sz;
543 map<string, function<size_t(
const string&)>> m_base_sz_csr;
544 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 install(const string &name, function< void(std::array< size_t, 3 >, double *, double *, double *)> &target, const function< void(std::array< size_t, 3 >, double *, double *, double *)> &base)
Install a function with the signature void(double*, double*, double*) 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(std::array< size_t, 1 >, double, double *)> &func, const string &when)
Set delegates for member functions with the signature void(double, 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 install(const string &name, function< double(void *)> &target, const function< double(void *)> &func)
Install a function with the signature double(void*) as being delegatable.
void setDelegate(const string &name, const function< void(std::array< size_t, 2 >, double, double *, double *)> &func, const string &when)
Set delegates for member functions with the signature void(double, double*, double*)
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 install(const string &name, function< void(std::array< size_t, 1 >, double *)> &target, const function< void(std::array< size_t, 1 >, double *)> &func)
Install a function with the signature void(double*) as being delegatable.
void setDelegate(const string &name, const function< void(std::array< size_t, 1 >, double *)> &func, const string &when)
Set delegates for member functions with the signature void(double*)
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(std::array< size_t, 1 >, double, double *)> &target, const function< void(std::array< size_t, 1 >, double, double *)> &func)
Install a function with the signature void(double, double*) 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.
void install(const string &name, function< void(std::array< size_t, 2 >, double, double *, double *)> &target, const function< void(std::array< size_t, 2 >, double, double *, double *)> &func)
Install a function with the signature void(double, double*, double*) as being delegatable.
string m_delegatorName
Name of the class in the extension language.
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 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 setDelegate(const string &name, const function< void(std::array< size_t, 3 >, double *, double *, double *)> &func, const string &when)
Set delegates for member functions with the signature void(double*, double*, double*)
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.