Rename runner -> runner-boost.

This commit is contained in:
Mikaël Capelle
2022-04-28 21:38:12 +02:00
parent dff9bd2404
commit d4f515ade1
25 changed files with 975 additions and 975 deletions
@@ -1,48 +1,48 @@
#ifndef Q_MOC_RUN
#include <boost/python.hpp>
#endif
#include <utility.h>
#include <QDebug>
#include "error.h"
using namespace MOBase;
namespace bpy = boost::python;
ErrWrapper & ErrWrapper::instance()
{
static ErrWrapper err;
return err;
}
void ErrWrapper::write(const char * message)
{
buffer << message;
if (buffer.tellp() != 0 && buffer.str().back() == '\n')
{
// actually put the string in a variable so it doesn't get destroyed as soon as we get a pointer to its data
std::string string = buffer.str().substr(0, buffer.str().length() - 1);
qCritical().nospace().noquote() << string.c_str();
buffer = std::stringstream();
}
if (recordingExceptionMessage)
{
lastException << message;
}
}
void ErrWrapper::startRecordingExceptionMessage()
{
recordingExceptionMessage = true;
lastException = std::stringstream();
}
void ErrWrapper::stopRecordingExceptionMessage()
{
recordingExceptionMessage = false;
}
QString ErrWrapper::getLastExceptionMessage()
{
return QString::fromStdString(lastException.str());
}
#ifndef Q_MOC_RUN
#include <boost/python.hpp>
#endif
#include <utility.h>
#include <QDebug>
#include "error.h"
using namespace MOBase;
namespace bpy = boost::python;
ErrWrapper & ErrWrapper::instance()
{
static ErrWrapper err;
return err;
}
void ErrWrapper::write(const char * message)
{
buffer << message;
if (buffer.tellp() != 0 && buffer.str().back() == '\n')
{
// actually put the string in a variable so it doesn't get destroyed as soon as we get a pointer to its data
std::string string = buffer.str().substr(0, buffer.str().length() - 1);
qCritical().nospace().noquote() << string.c_str();
buffer = std::stringstream();
}
if (recordingExceptionMessage)
{
lastException << message;
}
}
void ErrWrapper::startRecordingExceptionMessage()
{
recordingExceptionMessage = true;
lastException = std::stringstream();
}
void ErrWrapper::stopRecordingExceptionMessage()
{
recordingExceptionMessage = false;
}
QString ErrWrapper::getLastExceptionMessage()
{
return QString::fromStdString(lastException.str());
}
+123 -123
View File
@@ -1,123 +1,123 @@
#ifndef ERROR_H
#define ERROR_H
#include <QString>
#include <fmt/format.h>
#include <sstream>
#include <utility.h>
struct ErrWrapper
{
static ErrWrapper& instance();
void write(const char* message);
void startRecordingExceptionMessage();
void stopRecordingExceptionMessage();
QString getLastExceptionMessage();
std::stringstream buffer;
bool recordingExceptionMessage;
std::stringstream lastException;
};
namespace pyexcept {
/**
* @brief Exception to throw when a python implementation does not implement
* a pure virtual function.
*/
class MissingImplementation : public MOBase::Exception {
public:
MissingImplementation(std::string const& className, std::string const& methodName) :
Exception(QString::fromStdString(
fmt::format("Python class implementing \"{}\" has no implementation of method \"{}\".",
className, methodName))) { }
};
/**
* @brief Exception to throw when a python error occurs.
*/
class PythonError : public MOBase::Exception {
public:
/**
* @brief Create a new PythonError, fetching the error message from python. If the message
* cannot be retrieved, `defaultErrorMessage()` is used instead.
*/
PythonError() : Exception(getPythonErrorMessage()) { }
/**
* @brief Create a new PythonError with the given message.
*
* @param message Message for the exception.
*/
PythonError(QString message) : Exception(message) { }
protected:
/**
*
*/
static QString defaultErrorMessage() {
return QObject::tr("An unexpected C++ exception was thrown in python code.");
}
/**
*
*/
static QString getPythonErrorMessage() {
if (PyErr_Occurred()) {
ErrWrapper& errWrapper = ErrWrapper::instance();
errWrapper.startRecordingExceptionMessage();
PyErr_Print();
errWrapper.stopRecordingExceptionMessage();
return errWrapper.getLastExceptionMessage();
}
else {
return defaultErrorMessage();
}
}
};
/**
* @brief Exception to throw when an unknown error occured. This is typically thrown
* from a catch(...) block.
*/
class UnknownException : public MOBase::Exception {
public:
/**
* @brief Create a new UnknownException with the default message.
*
* @see defaultErrorMessage
*/
UnknownException() : Exception(defaultErrorMessage()) { }
/**
* @brief Create a new UnknownException with the given message.
*
* @param message Message for the exception.
*/
UnknownException(QString message) : Exception(message) { }
protected:
/**
*
*/
static QString defaultErrorMessage() {
return QObject::tr("An unknown exception was thrown in python code.");
}
};
}
#endif // ERROR_H
#ifndef ERROR_H
#define ERROR_H
#include <QString>
#include <fmt/format.h>
#include <sstream>
#include <utility.h>
struct ErrWrapper
{
static ErrWrapper& instance();
void write(const char* message);
void startRecordingExceptionMessage();
void stopRecordingExceptionMessage();
QString getLastExceptionMessage();
std::stringstream buffer;
bool recordingExceptionMessage;
std::stringstream lastException;
};
namespace pyexcept {
/**
* @brief Exception to throw when a python implementation does not implement
* a pure virtual function.
*/
class MissingImplementation : public MOBase::Exception {
public:
MissingImplementation(std::string const& className, std::string const& methodName) :
Exception(QString::fromStdString(
fmt::format("Python class implementing \"{}\" has no implementation of method \"{}\".",
className, methodName))) { }
};
/**
* @brief Exception to throw when a python error occurs.
*/
class PythonError : public MOBase::Exception {
public:
/**
* @brief Create a new PythonError, fetching the error message from python. If the message
* cannot be retrieved, `defaultErrorMessage()` is used instead.
*/
PythonError() : Exception(getPythonErrorMessage()) { }
/**
* @brief Create a new PythonError with the given message.
*
* @param message Message for the exception.
*/
PythonError(QString message) : Exception(message) { }
protected:
/**
*
*/
static QString defaultErrorMessage() {
return QObject::tr("An unexpected C++ exception was thrown in python code.");
}
/**
*
*/
static QString getPythonErrorMessage() {
if (PyErr_Occurred()) {
ErrWrapper& errWrapper = ErrWrapper::instance();
errWrapper.startRecordingExceptionMessage();
PyErr_Print();
errWrapper.stopRecordingExceptionMessage();
return errWrapper.getLastExceptionMessage();
}
else {
return defaultErrorMessage();
}
}
};
/**
* @brief Exception to throw when an unknown error occured. This is typically thrown
* from a catch(...) block.
*/
class UnknownException : public MOBase::Exception {
public:
/**
* @brief Create a new UnknownException with the default message.
*
* @see defaultErrorMessage
*/
UnknownException() : Exception(defaultErrorMessage()) { }
/**
* @brief Create a new UnknownException with the given message.
*
* @param message Message for the exception.
*/
UnknownException(QString message) : Exception(message) { }
protected:
/**
*
*/
static QString defaultErrorMessage() {
return QObject::tr("An unknown exception was thrown in python code.");
}
};
}
#endif // ERROR_H
@@ -1,12 +1,12 @@
#include "gilock.h"
GILock::GILock()
{
m_State = PyGILState_Ensure();
}
GILock::~GILock()
{
PyErr_Clear();
PyGILState_Release(m_State);
}
#include "gilock.h"
GILock::GILock()
{
m_State = PyGILState_Ensure();
}
GILock::~GILock()
{
PyErr_Clear();
PyGILState_Release(m_State);
}
@@ -1,18 +1,18 @@
#ifndef GILOCK_H
#define GILOCK_H
#ifndef Q_MOC_RUN
#include <boost/python.hpp>
#endif // Q_MOC_RUN
class GILock {
public:
GILock();
~GILock();
private:
PyGILState_STATE m_State;
};
#endif // GILOCK_H
#ifndef GILOCK_H
#define GILOCK_H
#ifndef Q_MOC_RUN
#include <boost/python.hpp>
#endif // Q_MOC_RUN
class GILock {
public:
GILock();
~GILock();
private:
PyGILState_STATE m_State;
};
#endif // GILOCK_H
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,33 +1,33 @@
#ifndef PYTHONRUNNER_H
#define PYTHONRUNNER_H
#include <QString>
#include <QObject>
#include <map>
#include <dllimport.h>
#include <imoinfo.h>
class IPythonRunner {
public:
virtual QList<QObject*> load(const QString& identifier) = 0;
virtual void unload(const QString& identifier) = 0;
virtual bool isPythonInitialized() const = 0;
virtual ~IPythonRunner() { }
};
#ifdef PYTHONRUNNER_LIBRARY
#define PYDLLEXPORT Q_DECL_EXPORT
#else // PYTHONRUNNER_LIBRARY
#define PYDLLEXPORT Q_DECL_IMPORT
#endif // PYTHONRUNNER_LIBRARY
extern "C" PYDLLEXPORT IPythonRunner *CreatePythonRunner();
#endif // PYTHONRUNNER_H
#ifndef PYTHONRUNNER_H
#define PYTHONRUNNER_H
#include <QString>
#include <QObject>
#include <map>
#include <dllimport.h>
#include <imoinfo.h>
class IPythonRunner {
public:
virtual QList<QObject*> load(const QString& identifier) = 0;
virtual void unload(const QString& identifier) = 0;
virtual bool isPythonInitialized() const = 0;
virtual ~IPythonRunner() { }
};
#ifdef PYTHONRUNNER_LIBRARY
#define PYDLLEXPORT Q_DECL_EXPORT
#else // PYTHONRUNNER_LIBRARY
#define PYDLLEXPORT Q_DECL_IMPORT
#endif // PYTHONRUNNER_LIBRARY
extern "C" PYDLLEXPORT IPythonRunner *CreatePythonRunner();
#endif // PYTHONRUNNER_H

Some files were not shown because too many files have changed in this diff Show More