104 void setDelegate(
const std::string& name,
const std::function<
void()>& func,
105 const std::string& when)
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 std::string& name,
const std::function<
void(
bool)>& func,
116 const std::string& when)
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 std::string& name,
const std::function<
void(
double)>& func,
127 const std::string& when)
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]);
138 const std::function<
void(std::array<size_t, 1>,
double*)>& func,
139 const std::string& when)
141 if (!m_funcs_v_dp.count(name)) {
143 "for function named '{}' with signature 'void(double*)'.", name);
145 *m_funcs_v_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp[name]);
150 const std::string& name,
151 const std::function<
void(std::array<size_t, 1>,
double,
double*)>& func,
152 const std::string& when)
154 if (!m_funcs_v_d_dp.count(name)) {
156 "for function named '{}' with signature 'void(double, double*)'.",
159 *m_funcs_v_d_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp[name]);
165 const std::string& name,
166 const std::function<
void(std::array <size_t, 2>,
double,
double*,
double*)>& func,
167 const std::string& when)
169 if (!m_funcs_v_d_dp_dp.count(name)) {
171 "for function named '{}' with signature "
172 "'void(double, double*, double*)'.", name);
174 *m_funcs_v_d_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_d_dp_dp[name]);
180 const std::string& name,
181 const std::function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& func,
182 const std::string& when)
184 if (!m_funcs_v_dp_dp_dp.count(name)) {
186 "for function named '{}' with signature "
187 "'void(double*, double*, double*)'.", name);
189 *m_funcs_v_dp_dp_dp[name] =
makeDelegate(func, when, *m_funcs_v_dp_dp_dp[name]);
194 const std::function<
int(std::string&,
size_t)>& func,
195 const std::string& when)
197 if (!m_funcs_s_sz.count(name)) {
199 "for function named '{}' with signature "
200 "'string(size_t)'.", name);
202 *m_funcs_s_sz[name] =
makeDelegate(func, when, m_base_s_sz[name]);
207 const std::function<
int(
size_t&,
const std::string&)>& func,
208 const std::string& when)
210 if (!m_funcs_sz_csr.count(name)) {
212 "for function named '{}' with signature "
213 "'size_t(const string&)'.", name);
215 *m_funcs_sz_csr[name] =
makeDelegate(func, when, m_base_sz_csr[name]);
220 void install(
const std::string& name, std::function<
void()>& target,
221 const std::function<
void()>& func)
224 m_funcs_v[name] = ⌖
228 void install(
const std::string& name, std::function<
void(
bool)>& target,
229 const std::function<
void(
bool)>& func)
232 m_funcs_v_b[name] = ⌖
236 void install(
const std::string& name, std::function<
void(
double)>& target,
237 const std::function<
void(
double)>& func)
240 m_funcs_v_d[name] = ⌖
245 std::function<
void(std::array<size_t, 1>,
double*)>& target,
246 const std::function<
void(std::array<size_t, 1>,
double*)>& func)
249 m_funcs_v_dp[name] = ⌖
254 std::function<
void(std::array<size_t, 1>,
double,
double*)>& target,
255 const std::function<
void(std::array<size_t, 1>,
double,
double*)>& func)
258 m_funcs_v_d_dp[name] = ⌖
264 std::function<
void(std::array<size_t, 2>,
double,
double*,
double*)>& target,
265 const std::function<
void(std::array<size_t, 2>,
double,
double*,
double*)>& func)
268 m_funcs_v_d_dp_dp[name] = ⌖
274 std::function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& target,
275 const std::function<
void(std::array<size_t, 3>,
double*,
double*,
double*)>& base)
278 m_funcs_v_dp_dp_dp[name] = ⌖
283 std::function<std::string(
size_t)>& target,
284 const std::function<std::string(
size_t)>& base)
287 m_funcs_s_sz[name] = ⌖
288 m_base_s_sz[name] = base;
293 std::function<
size_t(
const std::string&)>& target,
294 const std::function<
size_t(
const std::string&)>& base)
297 m_funcs_sz_csr[name] = ⌖
298 m_base_sz_csr[name] = base;
302 template <
typename BaseFunc,
class ... Args>
304 const std::function<
void(Args ...)>& func,
305 const std::string& when,
308 if (when ==
"before") {
309 return [base, func](Args ... args) {
313 }
else if (when ==
"after") {
314 return [base, func](Args ... args) {
318 }
else if (when ==
"replace") {
319 return [func](Args ... args) {
324 "'when' must be one of 'before', 'after', or 'replace';"
330 template <
typename ReturnType,
class ... Args>
332 const std::function<
int(ReturnType&, Args ...)>& func,
333 const std::string& when,
334 const std::function<ReturnType(Args ...)>& base)
336 if (when ==
"before") {
337 return [base, func](Args ... args) {
342 int done = func(ret, args ...);
346 return base(args ...);
349 }
else if (when ==
"after") {
350 return [base, func](Args ... args) {
353 ReturnType ret1 = base(args ...);
355 int done = func(ret2, args ...);
362 }
else if (when ==
"replace") {
363 return [base, func](Args ... args) {
365 int has_ret = func(ret, args ...);
367 throw CanteraError(
"Lambda generated by Delegator::makeDelegate",
368 "Delegate for function of type '{}'\ndid not return a value",
375 "'when' must be one of 'before', 'after', or 'replace';"
403 std::map<std::string, std::function<void()>*> m_funcs_v;
404 std::map<std::string, std::function<void(
bool)>*> m_funcs_v_b;
405 std::map<std::string, std::function<void(
double)>*> m_funcs_v_d;
406 std::map<std::string,
407 std::function<void(std::array<size_t, 1>,
double*)>*> m_funcs_v_dp;
408 std::map<std::string,
409 std::function<void(std::array<size_t, 1>,
double,
double*)>*> m_funcs_v_d_dp;
410 std::map<std::string,
411 std::function<void(std::array<size_t, 2>,
double,
double*,
double*)>*> m_funcs_v_d_dp_dp;
412 std::map<std::string,
413 std::function<void(std::array<size_t, 3>,
double*,
double*,
double*)>*> m_funcs_v_dp_dp_dp;
416 std::map<std::string,
417 std::function<std::string(
size_t)>> m_base_s_sz;
418 std::map<std::string,
419 std::function<std::string(
size_t)>*> m_funcs_s_sz;
421 std::map<std::string,
422 std::function<size_t(
const std::string&)>> m_base_sz_csr;
423 std::map<std::string,
424 std::function<size_t(
const std::string&)>*> m_funcs_sz_csr;
Base class for exceptions thrown by Cantera classes.
Delegate member functions of a C++ class to externally-specified functions.
void install(const std::string &name, std::function< void(std::array< size_t, 3 >, double *, double *, double *)> &target, const std::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 setDelegate(const std::string &name, const std::function< void(std::array< size_t, 2 >, double, double *, double *)> &func, const std::string &when)
Set delegates for member functions with the signature void(double, double*, double*)
void install(const std::string &name, std::function< void()> &target, const std::function< void()> &func)
Install a function with the signature void() as being delegatable.
void setDelegate(const std::string &name, const std::function< int(size_t &, const std::string &)> &func, const std::string &when)
Set delegates for member functions with the signature size_t(string)
void setDelegate(const std::string &name, const std::function< void(double)> &func, const std::string &when)
set delegates for member functions with the signature void(double)
void install(const std::string &name, std::function< void(double)> &target, const std::function< void(double)> &func)
Install a function with the signature void(double) as being delegatable.
void install(const std::string &name, std::function< size_t(const std::string &)> &target, const std::function< size_t(const std::string &)> &base)
Install a function with the signature size_t(string) as being delegatable.
void setDelegate(const std::string &name, const std::function< void()> &func, const std::string &when)
Set delegates for member functions with the signature void().
std::function< void(Args ...)> makeDelegate(const std::function< void(Args ...)> &func, const std::string &when, BaseFunc base)
Create a delegate for a function with no return value.
void install(const std::string &name, std::function< void(std::array< size_t, 2 >, double, double *, double *)> &target, const std::function< void(std::array< size_t, 2 >, double, double *, double *)> &func)
Install a function with the signature void(double, double*, double*) as being delegatable.
void setDelegate(const std::string &name, const std::function< void(std::array< size_t, 1 >, double, double *)> &func, const std::string &when)
Set delegates for member functions with the signature void(double, double*)
void setDelegate(const std::string &name, const std::function< void(bool)> &func, const std::string &when)
set delegates for member functions with the signature void(bool)
void install(const std::string &name, std::function< void(std::array< size_t, 1 >, double *)> &target, const std::function< void(std::array< size_t, 1 >, double *)> &func)
Install a function with the signature void(double*) as being delegatable.
void install(const std::string &name, std::function< void(std::array< size_t, 1 >, double, double *)> &target, const std::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 std::string &name, const std::function< void(std::array< size_t, 3 >, double *, double *, double *)> &func, const std::string &when)
Set delegates for member functions with the signature void(double*, double*, double*)
void install(const std::string &name, std::function< std::string(size_t)> &target, const std::function< std::string(size_t)> &base)
Install a function with the signature string(size_t) as being delegatable.
void install(const std::string &name, std::function< void(bool)> &target, const std::function< void(bool)> &func)
Install a function with the signature void(bool) as being delegatable.
void setDelegate(const std::string &name, const std::function< void(std::array< size_t, 1 >, double *)> &func, const std::string &when)
Set delegates for member functions with the signature void(double*)
std::function< ReturnType(Args ...)> makeDelegate(const std::function< int(ReturnType &, Args ...)> &func, const std::string &when, const std::function< ReturnType(Args ...)> &base)
Create a delegate for a function with a return value.
void setDelegate(const std::string &name, const std::function< int(std::string &, size_t)> &func, const std::string &when)
Set delegates for member functions with the signature string(size_t)
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,...
Namespace for the Cantera kernel.
std::string demangle(const std::type_info &type)
Convert a type name to a human readable string, using boost::core::demangle if available.