From 9f975b92b2147da96b89ee8b3caddc01215c3a6a Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 3 May 2018 21:56:23 +0100 Subject: [PATCH 1/4] Create template for wrapper functions and add helpful error message. Use this for plugin wrappers. --- src/runner/gamefeatureswrappers.cpp | 2 +- src/runner/proxypluginwrappers.cpp | 303 +++++++--------------------- src/runner/proxypluginwrappers.h | 24 +++ src/runner/pycatch.h | 11 - src/runner/pythonwrapperutilities.h | 32 +++ src/runner/uibasewrappers.h | 2 +- 6 files changed, 130 insertions(+), 244 deletions(-) delete mode 100644 src/runner/pycatch.h create mode 100644 src/runner/pythonwrapperutilities.h diff --git a/src/runner/gamefeatureswrappers.cpp b/src/runner/gamefeatureswrappers.cpp index b887e02..0e5cdb5 100644 --- a/src/runner/gamefeatureswrappers.cpp +++ b/src/runner/gamefeatureswrappers.cpp @@ -10,7 +10,7 @@ #include #include "gilock.h" -#include "pycatch.h" +#include "pythonwrapperutilities.h" ///////////////////////////// /// BSAInvalidation Wrapper diff --git a/src/runner/proxypluginwrappers.cpp b/src/runner/proxypluginwrappers.cpp index da807aa..6c69f74 100644 --- a/src/runner/proxypluginwrappers.cpp +++ b/src/runner/proxypluginwrappers.cpp @@ -3,7 +3,7 @@ #include "gilock.h" #include #include -#include "pycatch.h" +#include "pythonwrapperutilities.h" #include "sipApiAccess.h" namespace boost @@ -27,51 +27,37 @@ using namespace MOBase; #define COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(class_name) \ bool class_name::init(MOBase::IOrganizer *moInfo) \ { \ - try { \ - return this->get_override("init")(boost::python::ptr(moInfo)); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation>(this, "init", boost::python::ptr(moInfo)); \ } \ \ QString class_name::name() const \ { \ - try { \ - return this->get_override("name")().as(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation(this, "name"); \ } \ \ QString class_name::author() const \ { \ - try { \ - return this->get_override("author")().as(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation(this, "author"); \ } \ \ QString class_name::description() const \ { \ - try { \ - return this->get_override("description")().as(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation(this, "description"); \ } \ \ MOBase::VersionInfo class_name::version() const \ { \ - try { \ - return this->get_override("version")().as(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation(this, "version"); \ } \ \ bool class_name::isActive() const \ { \ - try { \ - return this->get_override("isActive")().as(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation(this, "isActive"); \ } \ \ QList class_name::settings() const \ { \ - try { \ - return this->get_override("settings")().as>(); \ - } PYCATCH; \ + return basicWrapperFunctionImplementation>(this, "settings"); \ } /// end COMMON_I_PLUGIN_WRAPPER_DEFINITIONS @@ -89,41 +75,27 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginDiagnoseWrapper) std::vector IPluginDiagnoseWrapper::activeProblems() const { - try { - GILock lock; - - return this->get_override("activeProblems")(); - } PYCATCH; + return basicWrapperFunctionImplementation>(this, "activeProblems"); } QString IPluginDiagnoseWrapper::shortDescription(unsigned int key) const { - try { - return this->get_override("shortDescription")(key); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "shortDescription", key); } QString IPluginDiagnoseWrapper::fullDescription(unsigned int key) const { - try { - return this->get_override("fullDescription")(key); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "fullDescription", key); } bool IPluginDiagnoseWrapper::hasGuidedFix(unsigned int key) const { - try { - return this->get_override("hasGuidedFix")(key); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "hasGuidedFix", key); } void IPluginDiagnoseWrapper::startGuidedFix(unsigned int key) const { - try { - GILock lock; - - this->get_override("startGuidedFix")(key); - } PYCATCH; + basicWrapperFunctionImplementation(this, "startGuidedFix", key); } void IPluginDiagnoseWrapper::invalidate() @@ -139,9 +111,7 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginFileMapperWrapper) MappingType IPluginFileMapperWrapper::mappings() const { - try { - return this->get_override("mappings")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "mappings"); } /// end IPluginFileMapper Wrapper ///////////////////////////////////// @@ -150,252 +120,159 @@ MappingType IPluginFileMapperWrapper::mappings() const QString IPluginGameWrapper::gameName() const { - GILock lock; - try { - return this->get_override("gameName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameName"); } void IPluginGameWrapper::initializeProfile(const QDir & directory, ProfileSettings settings) const { - GILock lock; - try { - this->get_override("initializeProfile")(directory, settings); - } PYCATCH; + basicWrapperFunctionImplementation(this, "initializeProfile", directory, settings); } QString IPluginGameWrapper::savegameExtension() const { - GILock lock; - try { - return this->get_override("savegameExtension")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "savegameExtension"); } QString IPluginGameWrapper::savegameSEExtension() const { - GILock lock; - try { - return this->get_override("savegameSEExtension")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "savegameSEExtension"); } bool IPluginGameWrapper::isInstalled() const { - GILock lock; - try { - return this->get_override("isInstalled")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "isInstalled"); } QIcon IPluginGameWrapper::gameIcon() const { - GILock lock; - try { - return this->get_override("gameIcon")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameIcon"); } QDir IPluginGameWrapper::gameDirectory() const { - GILock lock; - try { - return this->get_override("gameDirectory")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameDirectory"); } QDir IPluginGameWrapper::dataDirectory() const { - GILock lock; - try { - return this->get_override("dataDirectory")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "dataDirectory"); } void IPluginGameWrapper::setGamePath(const QString & path) { - GILock lock; - try { - this->get_override("setGamePath")(path); - } PYCATCH; + basicWrapperFunctionImplementation(this, "setGamePath", path); } QDir IPluginGameWrapper::documentsDirectory() const { - GILock lock; - try { - return this->get_override("documentsDirectory")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "documentsDirectory"); } QDir IPluginGameWrapper::savesDirectory() const { - GILock lock; - try { - return this->get_override("savesDirectory")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "savesDirectory"); } QList IPluginGameWrapper::executables() const { - GILock lock; - try { - return this->get_override("executables")(); - } PYCATCH; + return basicWrapperFunctionImplementation>(this, "executables"); } QString IPluginGameWrapper::steamAPPId() const { - GILock lock; - try { - return this->get_override("steamAPPId")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "steamAPPId"); } QStringList IPluginGameWrapper::primaryPlugins() const { - GILock lock; - try { - return this->get_override("primaryPlugins")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "primaryPlugins"); } QStringList IPluginGameWrapper::gameVariants() const { - GILock lock; - try { - return this->get_override("gameVariants")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameVariants"); } void IPluginGameWrapper::setGameVariant(const QString & variant) { - GILock lock; - try { - this->get_override("setGameVariant")(variant); - } PYCATCH; + basicWrapperFunctionImplementation(this, "setGameVariant", variant); } QString IPluginGameWrapper::binaryName() const { - GILock lock; - try { - return this->get_override("binaryName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "binaryName"); } QString IPluginGameWrapper::gameShortName() const { - GILock lock; - try { - return this->get_override("gameShortName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameShortName"); } QStringList IPluginGameWrapper::validShortNames() const { - GILock lock; - try { - return this->get_override("validShortNames")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "validShortNames"); } QString IPluginGameWrapper::gameNexusName() const { - GILock lock; - try { - return this->get_override("gameNexusName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameNexusName"); } QStringList IPluginGameWrapper::iniFiles() const { - GILock lock; - try { - return this->get_override("iniFiles")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "iniFiles"); } QStringList IPluginGameWrapper::DLCPlugins() const { - GILock lock; - try { - return this->get_override("DLCPlugins")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "DLCPlugins"); } QStringList IPluginGameWrapper::CCPlugins() const { - GILock lock; - try { - return this->get_override("CCPlugins")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "CCPlugins"); } IPluginGame::LoadOrderMechanism IPluginGameWrapper::loadOrderMechanism() const { - GILock lock; - try { - return this->get_override("loadOrderMechanism")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "loadOrderMechanism"); } IPluginGame::SortMechanism IPluginGameWrapper::sortMechanism() const { - GILock lock; - try { - return this->get_override("sortMechanism")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "sortMechanism"); } int IPluginGameWrapper::nexusModOrganizerID() const { - GILock lock; - try { - return this->get_override("nexusModOrganizerID")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "nexusModOrganizerID"); } int IPluginGameWrapper::nexusGameID() const { - GILock lock; - try { - return this->get_override("nexusGameID")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "nexusGameID"); } bool IPluginGameWrapper::looksValid(QDir const & dir) const { - GILock lock; - try { - return this->get_override("looksValid")(dir); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "looksValid", dir); } QString IPluginGameWrapper::gameVersion() const { - GILock lock; - try { - return this->get_override("gameVersion")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "gameVersion"); } QString IPluginGameWrapper::getLauncherName() const { - GILock lock; - try { - return this->get_override("getLauncherName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getLauncherName"); } COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginGameWrapper) std::map IPluginGameWrapper::featureList() const { - GILock lock; - try { - return this->get_override("_featureList")(); - } PYCATCH; + return basicWrapperFunctionImplementation>(this, "_featureList"); } /// end IPluginGame Wrapper ///////////////////////////////////// @@ -406,55 +283,41 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginInstallerCustomWrapper) unsigned int IPluginInstallerCustomWrapper::priority() const { - try { - return this->get_override("priority")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "priority"); } bool IPluginInstallerCustomWrapper::isManualInstaller() const { - try { - return this->get_override("isManualInstaller")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "isManualInstaller"); } -bool IPluginInstallerCustomWrapper::isArchiveSupported(const DirectoryTree &) const +bool IPluginInstallerCustomWrapper::isArchiveSupported(const DirectoryTree &archiveTree) const { - try { - //return this->get_override("isArchiveSupported")(tree); - return false; - } PYCATCH; + //return basicWrapperFunctionImplementation(this, "isArchiveSupported", archiveTree); + // This was a stub implementation when I got here, and a real one won't compile. + return false; } bool IPluginInstallerCustomWrapper::isArchiveSupported(const QString &archiveName) const { - try { - return this->get_override("isArchiveSupported")(archiveName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "isArchiveSupported", archiveName); } std::set IPluginInstallerCustomWrapper::supportedExtensions() const { - try { - return this->get_override("supportedExtensions")().as>(); - } PYCATCH; + return basicWrapperFunctionImplementation>(this, "supportedExtensions"); } - IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install(GuessedValue &modName, const QString &archiveName, const QString &version, int modID) { - try { - return this->get_override("install")(modName, archiveName, version, modID); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "install", modName, archiveName, version, modID); } void IPluginInstallerCustomWrapper::setParentWidget(QWidget *parent) { - try { - this->get_override("setParentWidget")(parent); - } PYCATCH; + basicWrapperFunctionImplementation(this, "setParentWidget", parent); } /// end IPluginInstallerCustom Wrapper ///////////////////////////// @@ -465,44 +328,32 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginModPageWrapper) QString IPluginModPageWrapper::displayName() const { - try { - return this->get_override("displayName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "displayName"); } QIcon IPluginModPageWrapper::icon() const { - try { - return this->get_override("icon")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "icon"); } QUrl IPluginModPageWrapper::pageURL() const { - try { - return this->get_override("pageURL")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "pageURL"); } bool IPluginModPageWrapper::useIntegratedBrowser() const { - try { - return this->get_override("useIntegratedBrowser")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "useIntegratedBrowser"); } bool IPluginModPageWrapper::handlesDownload(const QUrl & pageURL, const QUrl & downloadURL, MOBase::ModRepositoryFileInfo & fileInfo) const { - try { - return this->get_override("handlesDownload")(pageURL, downloadURL, fileInfo); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "handlesDownload", pageURL, downloadURL, fileInfo); } void IPluginModPageWrapper::setParentWidget(QWidget * widget) { - try { - this->get_override("setParentWidget")(widget); - } PYCATCH; + basicWrapperFunctionImplementation(this, "setParentWidget", widget); } /// end IPluginModPage Wrapper ///////////////////////////// @@ -513,15 +364,17 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginPreviewWrapper) std::set IPluginPreviewWrapper::supportedExtensions() const { - try { - return this->get_override("supportedExtensions")(); - } PYCATCH; + return basicWrapperFunctionImplementation>(this, "supportedExtensions"); } QWidget *IPluginPreviewWrapper::genFilePreview(const QString &fileName, const QSize &maxSize) const { + // This is complicated, so we can't use the basic implementation try { - boost::python::object pyVersion = this->get_override("genFilePreview")(fileName, maxSize); + boost::python::override implementation = this->get_override("genFilePreview"); + if (!implementation) + throw MissingImplementation(this->className, "genFilePreview"); + boost::python::object pyVersion = implementation(fileName, maxSize); // We need responsibility for deleting the QWidget to be transferred to C++ sipAPI()->api_transfer_to(pyVersion.ptr(), 0); return boost::python::extract(pyVersion)(); @@ -536,39 +389,27 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginToolWrapper) QString IPluginToolWrapper::displayName() const { - try { - return this->get_override("displayName")().as(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "displayName"); } QString IPluginToolWrapper::tooltip() const { - try { - return this->get_override("tooltip")().as(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "tooltip"); } QIcon IPluginToolWrapper::icon() const { - try { - return this->get_override("icon")().as(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "icon"); } void IPluginToolWrapper::setParentWidget(QWidget *parent) { - try { - this->get_override("setParentWidget")(parent); - } PYCATCH; + basicWrapperFunctionImplementation(this, "setParentWidget", parent); } void IPluginToolWrapper::display() const { - try { - GILock lock; - - this->get_override("display")(); - } PYCATCH; + basicWrapperFunctionImplementation(this, "display"); } /// end IPluginTool Wrapper diff --git a/src/runner/proxypluginwrappers.h b/src/runner/proxypluginwrappers.h index 12e6829..35bc0b4 100644 --- a/src/runner/proxypluginwrappers.h +++ b/src/runner/proxypluginwrappers.h @@ -31,6 +31,9 @@ class IPluginWrapper : public MOBase::IPlugin, public boost::python::wrapper::get_override; }; @@ -42,6 +45,9 @@ class IPluginDiagnoseWrapper : public QObject, public MOBase::IPluginDiagnose, p Q_INTERFACES(MOBase::IPlugin MOBase::IPluginDiagnose) public: + static constexpr const char* className = "IPluginDiagnoseWrapper"; + using boost::python::wrapper::get_override; + virtual std::vector activeProblems() const override; virtual QString shortDescription(unsigned int key) const override; virtual QString fullDescription(unsigned int key) const override; @@ -63,6 +69,9 @@ class IPluginFileMapperWrapper : public QObject, public MOBase::IPluginFileMappe Q_INTERFACES(MOBase::IPlugin MOBase::IPluginFileMapper) public: + static constexpr const char* className = "IPluginFileMapperWrapper"; + using boost::python::wrapper::get_override; + virtual MappingType mappings() const override; COMMON_I_PLUGIN_WRAPPER_DECLARATIONS @@ -74,6 +83,9 @@ class IPluginGameWrapper : public MOBase::IPluginGame, public boost::python::wra Q_INTERFACES(MOBase::IPlugin MOBase::IPluginGame) public: + static constexpr const char* className = "IPluginGameWrapper"; + using boost::python::wrapper::get_override; + virtual QString gameName() const override; virtual void initializeProfile(const QDir &directory, ProfileSettings settings) const override; virtual QString savegameExtension() const override; @@ -122,6 +134,9 @@ class IPluginInstallerCustomWrapper : public MOBase::IPluginInstallerCustom, pub COMMON_I_PLUGIN_WRAPPER_DECLARATIONS public: + static constexpr const char* className = "IPluginInstallerCustomWrapper"; + using boost::python::wrapper::get_override; + virtual unsigned int priority() const; virtual bool isManualInstaller() const; virtual bool isArchiveSupported(const MOBase::DirectoryTree &tree) const; @@ -141,6 +156,9 @@ class IPluginModPageWrapper : public MOBase::IPluginModPage, public boost::pytho COMMON_I_PLUGIN_WRAPPER_DECLARATIONS public: + static constexpr const char* className = "IPluginModPageWrapper"; + using boost::python::wrapper::get_override; + virtual QString displayName() const override; virtual QIcon icon() const override; virtual QUrl pageURL() const override; @@ -157,6 +175,9 @@ class IPluginPreviewWrapper : public MOBase::IPluginPreview, public boost::pytho COMMON_I_PLUGIN_WRAPPER_DECLARATIONS public: + static constexpr const char* className = "IPluginPreviewWrapper"; + using boost::python::wrapper::get_override; + virtual std::set supportedExtensions() const override; virtual QWidget *genFilePreview(const QString &fileName, const QSize &maxSize) const override; }; @@ -169,6 +190,9 @@ class IPluginToolWrapper: public MOBase::IPluginTool, public boost::python::wrap COMMON_I_PLUGIN_WRAPPER_DECLARATIONS public: + static constexpr const char* className = "IPluginToolWrapper"; + using boost::python::wrapper::get_override; + virtual QString displayName() const; virtual QString tooltip() const; virtual QIcon icon() const; diff --git a/src/runner/pycatch.h b/src/runner/pycatch.h deleted file mode 100644 index e74ce4d..0000000 --- a/src/runner/pycatch.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PYCATCH_H -#define PYCATCH_H - -#include - -#include "error.h" - -#define PYCATCH catch (const boost::python::error_already_set &) { reportPythonError(); throw MOBase::MyException("unhandled exception"); }\ - catch (...) { throw MOBase::MyException("An unknown exception was thrown in python code"); } - -#endif // PYCATCH_H diff --git a/src/runner/pythonwrapperutilities.h b/src/runner/pythonwrapperutilities.h new file mode 100644 index 0000000..86317e0 --- /dev/null +++ b/src/runner/pythonwrapperutilities.h @@ -0,0 +1,32 @@ +#ifndef PYTHONWRAPPERUTILITIES_H +#define PYTHONWRAPPERUTILITIES_H + +#include + +#include "error.h" + +class MissingImplementation : public MOBase::MyException { +public: + MissingImplementation(QString className, QString methodName) : MyException("Python class implementing \"" + + className + + "\" has no implementation of method \"" + + methodName + "\"") {} +}; + +#define PYCATCH catch (const boost::python::error_already_set &) { reportPythonError(); throw MOBase::MyException("unhandled exception"); }\ + catch (const MissingImplementation &missingImplementationException) { throw missingImplementationException; }\ + catch (...) { throw MOBase::MyException("An unknown exception was thrown in python code"); } + +template +ReturnType basicWrapperFunctionImplementation(const WrapperType *wrapper, const char *methodName, Args... args) +{ + try { + GILock lock; + boost::python::override implementation = wrapper->get_override(methodName); + if (!implementation) + throw MissingImplementation(wrapper->className, methodName); + return implementation(args...).as(); + } PYCATCH; +} + +#endif // PYTHONWRAPPERUTILITIES_H diff --git a/src/runner/uibasewrappers.h b/src/runner/uibasewrappers.h index 36f1c0c..91da18e 100644 --- a/src/runner/uibasewrappers.h +++ b/src/runner/uibasewrappers.h @@ -26,7 +26,7 @@ #include "error.h" #include "gilock.h" -#include "pycatch.h" +#include "pythonwrapperutilities.h" extern MOBase::IOrganizer *s_Organizer; From ec4945db3ef7febed6039aa340745e22e26cc12d Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 3 May 2018 22:02:06 +0100 Subject: [PATCH 2/4] Use new template for (non-pointless) uibase wrappers. --- src/runner/uibasewrappers.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/runner/uibasewrappers.h b/src/runner/uibasewrappers.h index 91da18e..024631b 100644 --- a/src/runner/uibasewrappers.h +++ b/src/runner/uibasewrappers.h @@ -443,11 +443,14 @@ struct IModListWrapper: MOBase::IModList, boost::python::wrapper { public: - virtual QString getFilename() const override { try { return this->get_override("getFilename")(); } PYCATCH }; - virtual QDateTime getCreationTime() const override { try { return this->get_override("getCreationTime")(); } PYCATCH }; - virtual QString getSaveGroupIdentifier() const override { try { return this->get_override("getSaveGroupIdentifier")(); } PYCATCH }; - virtual QStringList allFiles() const override { try { return this->get_override("allFiles")(); } PYCATCH }; - virtual bool hasScriptExtenderFile() const override { try { return this->get_override("hasScriptExtenderFile")(); } PYCATCH }; + static constexpr const char* className = "ISaveGameWrapper"; + using boost::python::wrapper::get_override; + + virtual QString getFilename() const override { return basicWrapperFunctionImplementation(this, "getFilename"); }; + virtual QDateTime getCreationTime() const override { return basicWrapperFunctionImplementation(this, "getCreationTime"); }; + virtual QString getSaveGroupIdentifier() const override { return basicWrapperFunctionImplementation(this, "getSaveGroupIdentifier"); }; + virtual QStringList allFiles() const override { return basicWrapperFunctionImplementation(this, "allFiles"); }; + virtual bool hasScriptExtenderFile() const override { return basicWrapperFunctionImplementation(this, "hasScriptExtenderFile"); }; }; From 8919fbd3513d4a216c227e0c684a036910d22580 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 3 May 2018 22:19:55 +0100 Subject: [PATCH 3/4] Use new template for game features wrappers. --- src/runner/gamefeatureswrappers.cpp | 163 +++++----------------------- src/runner/gamefeatureswrappers.h | 28 +++++ 2 files changed, 55 insertions(+), 136 deletions(-) diff --git a/src/runner/gamefeatureswrappers.cpp b/src/runner/gamefeatureswrappers.cpp index 0e5cdb5..380458d 100644 --- a/src/runner/gamefeatureswrappers.cpp +++ b/src/runner/gamefeatureswrappers.cpp @@ -18,29 +18,17 @@ bool BSAInvalidationWrapper::isInvalidationBSA(const QString &bsaName) { - GILock lock; - - try { - return this->get_override("isInvalidationBSA")(bsaName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "isInvalidationBSA", bsaName); } void BSAInvalidationWrapper::deactivate(MOBase::IProfile *profile) { - GILock lock; - - try { - this->get_override("deactivate")(boost::python::ptr(profile)); - } PYCATCH; + basicWrapperFunctionImplementation(this, "deactivate", boost::python::ptr(profile)); } void BSAInvalidationWrapper::activate(MOBase::IProfile *profile) { - GILock lock; - - try { - this->get_override("activate")(boost::python::ptr(profile)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "activate", boost::python::ptr(profile)); } /// end BSAInvalidation Wrapper ///////////////////////////// @@ -49,38 +37,22 @@ void BSAInvalidationWrapper::activate(MOBase::IProfile *profile) QStringList DataArchivesWrapper::vanillaArchives() const { - GILock lock; - - try { - return this->get_override("vanillaArchives")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "vanillaArchives"); } QStringList DataArchivesWrapper::archives(const MOBase::IProfile *profile) const { - GILock lock; - - try { - return this->get_override("archives")(boost::python::ptr(profile)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "archives", boost::python::ptr(profile)); } void DataArchivesWrapper::addArchive(MOBase::IProfile *profile, int index, const QString &archiveName) { - GILock lock; - - try { - this->get_override("addArchive")(boost::python::ptr(profile), index, archiveName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "addArchive", boost::python::ptr(profile), index, archiveName); } void DataArchivesWrapper::removeArchive(MOBase::IProfile * profile, const QString & archiveName) { - GILock lock; - - try { - this->get_override("removeArchive")(boost::python::ptr(profile), archiveName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "removeArchive", boost::python::ptr(profile), archiveName); } /// end DataArchives Wrapper ///////////////////////////// @@ -89,20 +61,12 @@ void DataArchivesWrapper::removeArchive(MOBase::IProfile * profile, const QStrin void GamePluginsWrapper::writePluginLists(const MOBase::IPluginList * pluginList) { - GILock lock; - - try { - this->get_override("writePluginLists")(boost::python::ptr(pluginList)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "writePluginLists", boost::python::ptr(pluginList)); } void GamePluginsWrapper::readPluginLists(MOBase::IPluginList * pluginList) { - GILock lock; - - try { - this->get_override("readPluginLists")(boost::python::ptr(pluginList)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "readPluginLists", boost::python::ptr(pluginList)); } /// end GamePlugins Wrapper ///////////////////////////// @@ -111,20 +75,12 @@ void GamePluginsWrapper::readPluginLists(MOBase::IPluginList * pluginList) MappingType LocalSavegamesWrapper::mappings(const QDir & profileSaveDir) const { - GILock lock; - - try { - return this->get_override("mappings")(profileSaveDir); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "mappings", profileSaveDir); } void LocalSavegamesWrapper::prepareProfile(MOBase::IProfile * profile) { - GILock lock; - - try { - this->get_override("prepareProfile")(boost::python::ptr(profile)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "prepareProfile", boost::python::ptr(profile)); } /// end LocalSavegames Wrapper ///////////////////////////// @@ -133,40 +89,23 @@ void LocalSavegamesWrapper::prepareProfile(MOBase::IProfile * profile) MOBase::ISaveGame const * SaveGameInfoWrapper::getSaveGameInfo(QString const & file) const { - GILock lock; - - try { - return this->get_override("getSaveGameInfo")(file); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getSaveGameInfo", file); } SaveGameInfoWrapper::MissingAssets SaveGameInfoWrapper::getMissingAssets(QString const & file) const { - GILock lock; - - try { - return this->get_override("getMissingAssets")(file); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getMissingAssets", file); } MOBase::ISaveGameInfoWidget * SaveGameInfoWrapper::getSaveGameWidget(QWidget * parent) const { qCritical("Calling method with unimplemented from_python converter."); - - GILock lock; - - try { - return this->get_override("getSaveGameWidget")(boost::python::ptr(parent)); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getSaveGameWidget", boost::python::ptr(parent)); } bool SaveGameInfoWrapper::hasScriptExtenderSave(QString const & file) const { - GILock lock; - - try { - return this->get_override("hasScriptExtenderSave")(file); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "hasScriptExtenderSave", file); } /// end SaveGameInfo Wrapper ///////////////////////////// @@ -174,74 +113,42 @@ bool SaveGameInfoWrapper::hasScriptExtenderSave(QString const & file) const QString ScriptExtenderWrapper::BinaryName() const { - GILock lock; - - try { - return this->get_override("BinaryName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "BinaryName"); } QString ScriptExtenderWrapper::PluginPath() const { - GILock lock; - - try { - return this->get_override("PluginPath")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "PluginPath"); } QString ScriptExtenderWrapper::loaderName() const { - GILock lock; - - try { - return this->get_override("loaderName")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "loaderName"); } QString ScriptExtenderWrapper::loaderPath() const { - GILock lock; - - try { - return this->get_override("loaderPath")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "loaderPath"); } QStringList ScriptExtenderWrapper::saveGameAttachmentExtensions() const { - GILock lock; - - try { - return this->get_override("saveGameAttachmentExtensions")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "saveGameAttachmentExtensions"); } bool ScriptExtenderWrapper::isInstalled() const { - GILock lock; - - try { - return this->get_override("isInstalled")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "isInstalled"); } QString ScriptExtenderWrapper::getExtenderVersion() const { - GILock lock; - - try { - return this->get_override("getExtenderVersion")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getExtenderVersion"); } WORD ScriptExtenderWrapper::getArch() const { - GILock lock; - - try { - return this->get_override("getArch")(); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "getArch"); } /// end ScriptExtender Wrapper @@ -251,38 +158,22 @@ WORD ScriptExtenderWrapper::getArch() const QStringList UnmanagedModsWrapper::mods(bool onlyOfficial) const { - GILock lock; - - try { - return this->get_override("mods")(onlyOfficial); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "mods", onlyOfficial); } QString UnmanagedModsWrapper::displayName(const QString & modName) const { - GILock lock; - - try { - return this->get_override("displayName")(modName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "displayName", modName); } QFileInfo UnmanagedModsWrapper::referenceFile(const QString & modName) const { - GILock lock; - - try { - return this->get_override("referenceFile")(modName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "referenceFile", modName); } QStringList UnmanagedModsWrapper::secondaryFiles(const QString & modName) const { - GILock lock; - - try { - return this->get_override("secondaryFiles")(modName); - } PYCATCH; + return basicWrapperFunctionImplementation(this, "secondaryFiles", modName); } /// end UnmanagedMods Wrapper ///////////////////////////// diff --git a/src/runner/gamefeatureswrappers.h b/src/runner/gamefeatureswrappers.h index 889889a..e62bde0 100644 --- a/src/runner/gamefeatureswrappers.h +++ b/src/runner/gamefeatureswrappers.h @@ -17,6 +17,10 @@ class BSAInvalidationWrapper : public BSAInvalidation, public boost::python::wrapper { +public: + static constexpr const char* className = "BSAInvalidationWrapper"; + using boost::python::wrapper::get_override; + virtual bool isInvalidationBSA(const QString &bsaName) override; virtual void deactivate(MOBase::IProfile *profile) override; virtual void activate(MOBase::IProfile *profile) override; @@ -24,6 +28,10 @@ class BSAInvalidationWrapper : public BSAInvalidation, public boost::python::wra class DataArchivesWrapper : public DataArchives, public boost::python::wrapper { +public: + static constexpr const char* className = "DataArchivesWrapper"; + using boost::python::wrapper::get_override; + virtual QStringList vanillaArchives() const override; virtual QStringList archives(const MOBase::IProfile *profile) const override; virtual void addArchive(MOBase::IProfile *profile, int index, const QString &archiveName) override; @@ -32,18 +40,30 @@ class DataArchivesWrapper : public DataArchives, public boost::python::wrapper { +public: + static constexpr const char* className = "GamePluginsWrapper"; + using boost::python::wrapper::get_override; + virtual void writePluginLists(const MOBase::IPluginList *pluginList) override; virtual void readPluginLists(MOBase::IPluginList *pluginList) override; }; class LocalSavegamesWrapper : public LocalSavegames, public boost::python::wrapper { +public: + static constexpr const char* className = "LocalSavegamesWrapper"; + using boost::python::wrapper::get_override; + virtual MappingType mappings(const QDir &profileSaveDir) const override; virtual void prepareProfile(MOBase::IProfile *profile) override; }; class SaveGameInfoWrapper : public SaveGameInfo, public boost::python::wrapper { +public: + static constexpr const char* className = "SaveGameInfoWrapper"; + using boost::python::wrapper::get_override; + virtual MOBase::ISaveGame const *getSaveGameInfo(QString const &file) const override; virtual MissingAssets getMissingAssets(QString const &file) const override; virtual MOBase::ISaveGameInfoWidget *getSaveGameWidget(QWidget *parent = 0) const override; @@ -52,6 +72,10 @@ class SaveGameInfoWrapper : public SaveGameInfo, public boost::python::wrapper { +public: + static constexpr const char* className = "ScriptExtenderWrapper"; + using boost::python::wrapper::get_override; + virtual QString BinaryName() const override; virtual QString PluginPath() const override; virtual QString loaderName() const override; @@ -64,6 +88,10 @@ class ScriptExtenderWrapper : public ScriptExtender, public boost::python::wrapp class UnmanagedModsWrapper : public UnmanagedMods, public boost::python::wrapper { +public: + static constexpr const char* className = "UnmanagedModsWrapper"; + using boost::python::wrapper::get_override; + virtual QStringList mods(bool onlyOfficial) const override; virtual QString displayName(const QString &modName) const override; virtual QFileInfo referenceFile(const QString &modName) const override; From 00c38f5f03f14b5cf125d7cddfd1dae150b44fa9 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 3 May 2018 22:22:32 +0100 Subject: [PATCH 4/4] Remove superfluous template parameter specification to shrink lines to a more readable length. --- src/runner/proxypluginwrappers.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runner/proxypluginwrappers.cpp b/src/runner/proxypluginwrappers.cpp index 6c69f74..230d680 100644 --- a/src/runner/proxypluginwrappers.cpp +++ b/src/runner/proxypluginwrappers.cpp @@ -27,7 +27,7 @@ using namespace MOBase; #define COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(class_name) \ bool class_name::init(MOBase::IOrganizer *moInfo) \ { \ - return basicWrapperFunctionImplementation>(this, "init", boost::python::ptr(moInfo)); \ + return basicWrapperFunctionImplementation(this, "init", boost::python::ptr(moInfo)); \ } \ \ QString class_name::name() const \ @@ -80,22 +80,22 @@ std::vector IPluginDiagnoseWrapper::activeProblems() const QString IPluginDiagnoseWrapper::shortDescription(unsigned int key) const { - return basicWrapperFunctionImplementation(this, "shortDescription", key); + return basicWrapperFunctionImplementation(this, "shortDescription", key); } QString IPluginDiagnoseWrapper::fullDescription(unsigned int key) const { - return basicWrapperFunctionImplementation(this, "fullDescription", key); + return basicWrapperFunctionImplementation(this, "fullDescription", key); } bool IPluginDiagnoseWrapper::hasGuidedFix(unsigned int key) const { - return basicWrapperFunctionImplementation(this, "hasGuidedFix", key); + return basicWrapperFunctionImplementation(this, "hasGuidedFix", key); } void IPluginDiagnoseWrapper::startGuidedFix(unsigned int key) const { - basicWrapperFunctionImplementation(this, "startGuidedFix", key); + basicWrapperFunctionImplementation(this, "startGuidedFix", key); } void IPluginDiagnoseWrapper::invalidate()