1 #ifndef CT_CYTHON_FUNC_WRAPPER
2 #define CT_CYTHON_FUNC_WRAPPER
10 typedef double(*callback_wrapper)(double,
void*,
void**);
17 CallbackError(
void* type,
void* value) :
18 m_type((PyObject*) type),
19 m_value((PyObject*) value)
22 const char*
what()
const throw() {
26 PyObject* name = PyObject_GetAttrString(m_type,
"__name__");
27 PyObject* value_str = PyObject_Str(m_value);
29 #if PY_MAJOR_VERSION > 2
30 PyObject* name_bytes = PyUnicode_AsASCIIString(name);
31 PyObject* value_bytes = PyUnicode_AsASCIIString(value_str);
33 PyObject* name_bytes = PyObject_Bytes(name);
34 PyObject* value_bytes = PyObject_Bytes(value_str);
39 Py_DECREF(name_bytes);
48 Py_DECREF(value_bytes);
54 Py_XDECREF(value_str);
69 Func1Py(callback_wrapper callback,
void* pyobj) :
74 double eval(
double t)
const {
75 void* err[2] = {0, 0};
76 double y = m_callback(t, m_pyobj, err);
78 throw CallbackError(err[0], err[1]);
84 callback_wrapper m_callback;
92 inline int translate_exception()
95 if (!PyErr_Occurred()) {
100 }
catch (
const CallbackError& exn) {
102 PyErr_SetObject(exn.m_type, exn.m_value);
103 }
catch (
const std::out_of_range& exn) {
104 PyErr_SetString(PyExc_IndexError, exn.what());
105 }
catch (
const std::exception& exn) {
106 PyErr_SetString(PyExc_Exception, exn.what());
108 PyErr_SetString(PyExc_Exception,
"Unknown exception");
std::string formattedMessage_
Formatted message returned by what()
virtual doublereal eval(doublereal t) const
Evaluate the function.
const char * what() const
Get a description of the error.
Base class for 'functor' classes that evaluate a function of one variable.
Base class for exceptions thrown by Cantera classes.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...