4#ifndef CT_PY_UTILS_UTILS_H
5#define CT_PY_UTILS_UTILS_H
13static std::map<std::string, PyObject*> mapped_PyWarnings = {
15 {
"Bytes", PyExc_BytesWarning},
16 {
"Cantera", PyExc_UserWarning},
17 {
"Deprecation", PyExc_DeprecationWarning},
18 {
"Future", PyExc_FutureWarning},
19 {
"Import", PyExc_ImportWarning},
20 {
"PendingDeprecation", PyExc_PendingDeprecationWarning},
21 {
"Resource", PyExc_ResourceWarning},
22 {
"Runtime", PyExc_RuntimeWarning},
23 {
"Syntax", PyExc_SyntaxWarning},
24 {
"Unicode", PyExc_UnicodeWarning},
25 {
"User", PyExc_UserWarning}
29inline std::string get_cantera_version_py()
31 return CANTERA_VERSION;
35inline std::string get_cantera_git_commit_py()
45inline int get_sundials_version()
47 return CT_SUNDIALS_VERSION;
53 void write(
const std::string& s)
override {
55 static const size_t N = 999;
56 for (
size_t i = 0; i < s.size(); i+=N) {
57 PySys_WriteStdout(
"%s", s.substr(i, N).c_str());
63 PySys_WriteStdout(
"%s",
"\n");
67 void warn(
const std::string& warning,
const std::string& msg)
override {
68 if (mapped_PyWarnings.find(warning) != mapped_PyWarnings.end()) {
69 PyErr_WarnEx(mapped_PyWarnings[warning], msg.c_str(), 1);
72 PyErr_WarnEx(PyExc_Warning, msg.c_str(), 1);
76 void error(
const std::string& msg)
override {
77 PyErr_SetString(PyExc_RuntimeError, msg.c_str());
Base class for 'loggers' that write text messages to log files.
void writeendl() override
Write an end of line character and flush output.
void error(const std::string &msg) override
Write an error message and quit.
void write(const std::string &s) override
Write a log message.
void warn(const std::string &warning, const std::string &msg) override
Write a warning message.
Header for Base class for 'loggers' that write text messages to log files (see Logging and class Logg...