4#ifndef CT_PY_UTILS_UTILS_H
5#define CT_PY_UTILS_UTILS_H
8#include "sundials/sundials_config.h"
14static std::map<std::string, PyObject*> mapped_PyWarnings = {
16 {
"Bytes", PyExc_BytesWarning},
17 {
"Cantera", PyExc_UserWarning},
18 {
"Deprecation", PyExc_DeprecationWarning},
19 {
"Future", PyExc_FutureWarning},
20 {
"Import", PyExc_ImportWarning},
21 {
"PendingDeprecation", PyExc_PendingDeprecationWarning},
22 {
"Resource", PyExc_ResourceWarning},
23 {
"Runtime", PyExc_RuntimeWarning},
24 {
"Syntax", PyExc_SyntaxWarning},
25 {
"Unicode", PyExc_UnicodeWarning},
26 {
"User", PyExc_UserWarning}
30inline std::string get_cantera_version_py()
32 return CANTERA_VERSION;
36inline std::string get_cantera_git_commit_py()
46inline std::string get_sundials_version()
48 return SUNDIALS_VERSION;
54 void write(
const std::string& s)
override {
56 static const size_t N = 999;
57 for (
size_t i = 0; i < s.size(); i+=N) {
58 PySys_WriteStdout(
"%s", s.substr(i, N).c_str());
64 PySys_WriteStdout(
"%s",
"\n");
68 void warn(
const std::string& warning,
const std::string& msg)
override {
69 if (mapped_PyWarnings.find(warning) != mapped_PyWarnings.end()) {
70 PyErr_WarnEx(mapped_PyWarnings[warning], msg.c_str(), 1);
73 PyErr_WarnEx(PyExc_Warning, msg.c_str(), 1);
77 void error(
const std::string& msg)
override {
78 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...