From da679b1d6da889a5a7ba1b0860c5b9631fdbda0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Thu, 21 May 2020 23:11:56 +0200 Subject: [PATCH] Common code for basicWrapperFunction functions. --- src/runner/gamefeatureswrappers.cpp | 62 ++++++------- src/runner/proxypluginwrappers.cpp | 130 ++++++++++++++-------------- src/runner/pythonrunner.cpp | 1 + src/runner/pythonwrapperutilities.h | 116 +++++++++---------------- src/runner/uibasewrappers.h | 12 +-- 5 files changed, 146 insertions(+), 175 deletions(-) diff --git a/src/runner/gamefeatureswrappers.cpp b/src/runner/gamefeatureswrappers.cpp index 462ce91..dd70821 100644 --- a/src/runner/gamefeatureswrappers.cpp +++ b/src/runner/gamefeatureswrappers.cpp @@ -17,22 +17,22 @@ bool BSAInvalidationWrapper::isInvalidationBSA(const QString &bsaName) { - return basicWrapperFunctionImplementation(this, "isInvalidationBSA", bsaName); + return basicWrapperFunctionImplementation(this, "isInvalidationBSA", bsaName); } void BSAInvalidationWrapper::deactivate(MOBase::IProfile *profile) { - return basicWrapperFunctionImplementation(this, "deactivate", boost::python::ptr(profile)); + return basicWrapperFunctionImplementation(this, "deactivate", boost::python::ptr(profile)); } void BSAInvalidationWrapper::activate(MOBase::IProfile *profile) { - return basicWrapperFunctionImplementation(this, "activate", boost::python::ptr(profile)); + return basicWrapperFunctionImplementation(this, "activate", boost::python::ptr(profile)); } bool BSAInvalidationWrapper::prepareProfile(MOBase::IProfile *profile) { - return basicWrapperFunctionImplementation(this, "prepareProfile", boost::python::ptr(profile)); + return basicWrapperFunctionImplementation(this, "prepareProfile", boost::python::ptr(profile)); } /// end BSAInvalidation Wrapper ///////////////////////////// @@ -41,22 +41,22 @@ bool BSAInvalidationWrapper::prepareProfile(MOBase::IProfile *profile) QStringList DataArchivesWrapper::vanillaArchives() const { - return basicWrapperFunctionImplementation(this, "vanillaArchives"); + return basicWrapperFunctionImplementation(this, "vanillaArchives"); } QStringList DataArchivesWrapper::archives(const MOBase::IProfile *profile) const { - return basicWrapperFunctionImplementation(this, "archives", boost::python::ptr(profile)); + return basicWrapperFunctionImplementation(this, "archives", boost::python::ptr(profile)); } void DataArchivesWrapper::addArchive(MOBase::IProfile *profile, int index, const QString &archiveName) { - return basicWrapperFunctionImplementation(this, "addArchive", boost::python::ptr(profile), index, archiveName); + return basicWrapperFunctionImplementation(this, "addArchive", boost::python::ptr(profile), index, archiveName); } void DataArchivesWrapper::removeArchive(MOBase::IProfile *profile, const QString &archiveName) { - return basicWrapperFunctionImplementation(this, "removeArchive", boost::python::ptr(profile), archiveName); + return basicWrapperFunctionImplementation(this, "removeArchive", boost::python::ptr(profile), archiveName); } /// end DataArchives Wrapper ///////////////////////////// @@ -65,22 +65,22 @@ void DataArchivesWrapper::removeArchive(MOBase::IProfile *profile, const QString void GamePluginsWrapper::writePluginLists(const MOBase::IPluginList * pluginList) { - return basicWrapperFunctionImplementation(this, "writePluginLists", boost::python::ptr(pluginList)); + return basicWrapperFunctionImplementation(this, "writePluginLists", boost::python::ptr(pluginList)); } void GamePluginsWrapper::readPluginLists(MOBase::IPluginList * pluginList) { - return basicWrapperFunctionImplementation(this, "readPluginLists", boost::python::ptr(pluginList)); + return basicWrapperFunctionImplementation(this, "readPluginLists", boost::python::ptr(pluginList)); } void GamePluginsWrapper::getLoadOrder(QStringList &loadOrder) { - return basicWrapperFunctionImplementation(this, "getLoadOrder", loadOrder); + return basicWrapperFunctionImplementation(this, "getLoadOrder", loadOrder); } bool GamePluginsWrapper::lightPluginsAreSupported() { - return basicWrapperFunctionImplementation(this, "lightPluginsAreSupported"); + return basicWrapperFunctionImplementation(this, "lightPluginsAreSupported"); } /// end GamePlugins Wrapper @@ -90,12 +90,12 @@ bool GamePluginsWrapper::lightPluginsAreSupported() MappingType LocalSavegamesWrapper::mappings(const QDir & profileSaveDir) const { - return basicWrapperFunctionImplementation(this, "mappings", profileSaveDir); + return basicWrapperFunctionImplementation(this, "mappings", profileSaveDir); } bool LocalSavegamesWrapper::prepareProfile(MOBase::IProfile * profile) { - return basicWrapperFunctionImplementation(this, "prepareProfile", boost::python::ptr(profile)); + return basicWrapperFunctionImplementation(this, "prepareProfile", boost::python::ptr(profile)); } /// end LocalSavegames Wrapper @@ -103,7 +103,7 @@ bool LocalSavegamesWrapper::prepareProfile(MOBase::IProfile * profile) /// ModDataChecker Wrapper bool ModDataCheckerWrapper::dataLooksValid(std::shared_ptr fileTree) const { - return basicWrapperFunctionImplementation(this, "dataLooksValid", fileTree); + return basicWrapperFunctionImplementation(this, "dataLooksValid", fileTree); } /// end ModDataChecker Wrapper @@ -113,22 +113,22 @@ bool ModDataCheckerWrapper::dataLooksValid(std::shared_ptr(this, m_SaveGames[file], "getSaveGameInfo", file); + return basicWrapperFunctionImplementation(this, m_SaveGames[file], "getSaveGameInfo", file); } SaveGameInfoWrapper::MissingAssets SaveGameInfoWrapper::getMissingAssets(QString const & file) const { - return basicWrapperFunctionImplementation(this, "getMissingAssets", file); + return basicWrapperFunctionImplementation(this, "getMissingAssets", file); } MOBase::ISaveGameInfoWidget* SaveGameInfoWrapper::getSaveGameWidget(QWidget* parent) const { - return basicWrapperFunctionImplementation(this, m_SaveGameWidget, "getSaveGameWidget", parent); + return basicWrapperFunctionImplementation(this, m_SaveGameWidget, "getSaveGameWidget", parent); } bool SaveGameInfoWrapper::hasScriptExtenderSave(QString const & file) const { - return basicWrapperFunctionImplementation(this, "hasScriptExtenderSave", file); + return basicWrapperFunctionImplementation(this, "hasScriptExtenderSave", file); } /// end SaveGameInfo Wrapper ///////////////////////////// @@ -136,42 +136,42 @@ bool SaveGameInfoWrapper::hasScriptExtenderSave(QString const & file) const QString ScriptExtenderWrapper::BinaryName() const { - return basicWrapperFunctionImplementation(this, "BinaryName"); + return basicWrapperFunctionImplementation(this, "BinaryName"); } QString ScriptExtenderWrapper::PluginPath() const { - return basicWrapperFunctionImplementation(this, "PluginPath"); + return basicWrapperFunctionImplementation(this, "PluginPath"); } QString ScriptExtenderWrapper::loaderName() const { - return basicWrapperFunctionImplementation(this, "loaderName"); + return basicWrapperFunctionImplementation(this, "loaderName"); } QString ScriptExtenderWrapper::loaderPath() const { - return basicWrapperFunctionImplementation(this, "loaderPath"); + return basicWrapperFunctionImplementation(this, "loaderPath"); } QStringList ScriptExtenderWrapper::saveGameAttachmentExtensions() const { - return basicWrapperFunctionImplementation(this, "saveGameAttachmentExtensions"); + return basicWrapperFunctionImplementation(this, "saveGameAttachmentExtensions"); } bool ScriptExtenderWrapper::isInstalled() const { - return basicWrapperFunctionImplementation(this, "isInstalled"); + return basicWrapperFunctionImplementation(this, "isInstalled"); } QString ScriptExtenderWrapper::getExtenderVersion() const { - return basicWrapperFunctionImplementation(this, "getExtenderVersion"); + return basicWrapperFunctionImplementation(this, "getExtenderVersion"); } WORD ScriptExtenderWrapper::getArch() const { - return basicWrapperFunctionImplementation(this, "getArch"); + return basicWrapperFunctionImplementation(this, "getArch"); } /// end ScriptExtender Wrapper @@ -181,22 +181,22 @@ WORD ScriptExtenderWrapper::getArch() const QStringList UnmanagedModsWrapper::mods(bool onlyOfficial) const { - return basicWrapperFunctionImplementation(this, "mods", onlyOfficial); + return basicWrapperFunctionImplementation(this, "mods", onlyOfficial); } QString UnmanagedModsWrapper::displayName(const QString & modName) const { - return basicWrapperFunctionImplementation(this, "displayName", modName); + return basicWrapperFunctionImplementation(this, "displayName", modName); } QFileInfo UnmanagedModsWrapper::referenceFile(const QString & modName) const { - return basicWrapperFunctionImplementation(this, "referenceFile", modName); + return basicWrapperFunctionImplementation(this, "referenceFile", modName); } QStringList UnmanagedModsWrapper::secondaryFiles(const QString & modName) const { - return basicWrapperFunctionImplementation(this, "secondaryFiles", modName); + return basicWrapperFunctionImplementation(this, "secondaryFiles", modName); } /// end UnmanagedMods Wrapper ///////////////////////////// diff --git a/src/runner/proxypluginwrappers.cpp b/src/runner/proxypluginwrappers.cpp index 6c2b849..32695eb 100644 --- a/src/runner/proxypluginwrappers.cpp +++ b/src/runner/proxypluginwrappers.cpp @@ -31,37 +31,37 @@ 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 \ { \ - return basicWrapperFunctionImplementation(this, "name"); \ + return basicWrapperFunctionImplementation(this, "name"); \ } \ \ QString class_name::author() const \ { \ - return basicWrapperFunctionImplementation(this, "author"); \ + return basicWrapperFunctionImplementation(this, "author"); \ } \ \ QString class_name::description() const \ { \ - return basicWrapperFunctionImplementation(this, "description"); \ + return basicWrapperFunctionImplementation(this, "description"); \ } \ \ MOBase::VersionInfo class_name::version() const \ { \ - return basicWrapperFunctionImplementation(this, "version"); \ + return basicWrapperFunctionImplementation(this, "version"); \ } \ \ bool class_name::isActive() const \ { \ - return basicWrapperFunctionImplementation(this, "isActive"); \ + return basicWrapperFunctionImplementation(this, "isActive"); \ } \ \ QList class_name::settings() const \ { \ - return basicWrapperFunctionImplementation>(this, "settings"); \ + return basicWrapperFunctionImplementation>(this, "settings"); \ } /// end COMMON_I_PLUGIN_WRAPPER_DEFINITIONS @@ -79,27 +79,27 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginDiagnoseWrapper) std::vector IPluginDiagnoseWrapper::activeProblems() const { - return basicWrapperFunctionImplementation>(this, "activeProblems"); + return basicWrapperFunctionImplementation>(this, "activeProblems"); } 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); } /// end IPluginDiagnose Wrapper @@ -111,7 +111,7 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginFileMapperWrapper) MappingType IPluginFileMapperWrapper::mappings() const { - return basicWrapperFunctionImplementation(this, "mappings"); + return basicWrapperFunctionImplementation(this, "mappings"); } /// end IPluginFileMapper Wrapper ///////////////////////////////////// @@ -120,178 +120,178 @@ MappingType IPluginFileMapperWrapper::mappings() const QString IPluginGameWrapper::gameName() const { - return basicWrapperFunctionImplementation(this, "gameName"); + return basicWrapperFunctionImplementation(this, "gameName"); } void IPluginGameWrapper::initializeProfile(const QDir & directory, ProfileSettings settings) const { - basicWrapperFunctionImplementation(this, "initializeProfile", directory, settings); + basicWrapperFunctionImplementation(this, "initializeProfile", directory, settings); } QString IPluginGameWrapper::savegameExtension() const { - return basicWrapperFunctionImplementation(this, "savegameExtension"); + return basicWrapperFunctionImplementation(this, "savegameExtension"); } QString IPluginGameWrapper::savegameSEExtension() const { - return basicWrapperFunctionImplementation(this, "savegameSEExtension"); + return basicWrapperFunctionImplementation(this, "savegameSEExtension"); } bool IPluginGameWrapper::isInstalled() const { - return basicWrapperFunctionImplementation(this, "isInstalled"); + return basicWrapperFunctionImplementation(this, "isInstalled"); } QIcon IPluginGameWrapper::gameIcon() const { - return basicWrapperFunctionImplementation(this, "gameIcon"); + return basicWrapperFunctionImplementation(this, "gameIcon"); } QDir IPluginGameWrapper::gameDirectory() const { - return basicWrapperFunctionImplementation(this, "gameDirectory"); + return basicWrapperFunctionImplementation(this, "gameDirectory"); } QDir IPluginGameWrapper::dataDirectory() const { - return basicWrapperFunctionImplementation(this, "dataDirectory"); + return basicWrapperFunctionImplementation(this, "dataDirectory"); } void IPluginGameWrapper::setGamePath(const QString & path) { - basicWrapperFunctionImplementation(this, "setGamePath", path); + basicWrapperFunctionImplementation(this, "setGamePath", path); } QDir IPluginGameWrapper::documentsDirectory() const { - return basicWrapperFunctionImplementation(this, "documentsDirectory"); + return basicWrapperFunctionImplementation(this, "documentsDirectory"); } QDir IPluginGameWrapper::savesDirectory() const { - return basicWrapperFunctionImplementation(this, "savesDirectory"); + return basicWrapperFunctionImplementation(this, "savesDirectory"); } QList IPluginGameWrapper::executables() const { - return basicWrapperFunctionImplementation>(this, "executables"); + return basicWrapperFunctionImplementation>(this, "executables"); } QList IPluginGameWrapper::executableForcedLoads() const { - return basicWrapperFunctionImplementation>(this, "executableForcedLoads"); + return basicWrapperFunctionImplementation>(this, "executableForcedLoads"); } QString IPluginGameWrapper::steamAPPId() const { - return basicWrapperFunctionImplementation(this, "steamAPPId"); + return basicWrapperFunctionImplementation(this, "steamAPPId"); } QStringList IPluginGameWrapper::primaryPlugins() const { - return basicWrapperFunctionImplementation(this, "primaryPlugins"); + return basicWrapperFunctionImplementation(this, "primaryPlugins"); } QStringList IPluginGameWrapper::gameVariants() const { - return basicWrapperFunctionImplementation(this, "gameVariants"); + return basicWrapperFunctionImplementation(this, "gameVariants"); } void IPluginGameWrapper::setGameVariant(const QString & variant) { - basicWrapperFunctionImplementation(this, "setGameVariant", variant); + basicWrapperFunctionImplementation(this, "setGameVariant", variant); } QString IPluginGameWrapper::binaryName() const { - return basicWrapperFunctionImplementation(this, "binaryName"); + return basicWrapperFunctionImplementation(this, "binaryName"); } QString IPluginGameWrapper::gameShortName() const { - return basicWrapperFunctionImplementation(this, "gameShortName"); + return basicWrapperFunctionImplementation(this, "gameShortName"); } QStringList IPluginGameWrapper::primarySources() const { - return basicWrapperFunctionImplementation(this, "primarySources"); + return basicWrapperFunctionImplementation(this, "primarySources"); } QStringList IPluginGameWrapper::validShortNames() const { - return basicWrapperFunctionImplementation(this, "validShortNames"); + return basicWrapperFunctionImplementation(this, "validShortNames"); } QString IPluginGameWrapper::gameNexusName() const { - return basicWrapperFunctionImplementation(this, "gameNexusName"); + return basicWrapperFunctionImplementation(this, "gameNexusName"); } QStringList IPluginGameWrapper::iniFiles() const { - return basicWrapperFunctionImplementation(this, "iniFiles"); + return basicWrapperFunctionImplementation(this, "iniFiles"); } QStringList IPluginGameWrapper::DLCPlugins() const { - return basicWrapperFunctionImplementation(this, "DLCPlugins"); + return basicWrapperFunctionImplementation(this, "DLCPlugins"); } QStringList IPluginGameWrapper::CCPlugins() const { - return basicWrapperFunctionImplementation(this, "CCPlugins"); + return basicWrapperFunctionImplementation(this, "CCPlugins"); } IPluginGame::LoadOrderMechanism IPluginGameWrapper::loadOrderMechanism() const { - return basicWrapperFunctionImplementation(this, "loadOrderMechanism"); + return basicWrapperFunctionImplementation(this, "loadOrderMechanism"); } IPluginGame::SortMechanism IPluginGameWrapper::sortMechanism() const { - return basicWrapperFunctionImplementation(this, "sortMechanism"); + return basicWrapperFunctionImplementation(this, "sortMechanism"); } int IPluginGameWrapper::nexusModOrganizerID() const { - return basicWrapperFunctionImplementation(this, "nexusModOrganizerID"); + return basicWrapperFunctionImplementation(this, "nexusModOrganizerID"); } int IPluginGameWrapper::nexusGameID() const { - return basicWrapperFunctionImplementation(this, "nexusGameID"); + return basicWrapperFunctionImplementation(this, "nexusGameID"); } bool IPluginGameWrapper::looksValid(QDir const & dir) const { - return basicWrapperFunctionImplementation(this, "looksValid", dir); + return basicWrapperFunctionImplementation(this, "looksValid", dir); } QString IPluginGameWrapper::gameVersion() const { - return basicWrapperFunctionImplementation(this, "gameVersion"); + return basicWrapperFunctionImplementation(this, "gameVersion"); } QString IPluginGameWrapper::getLauncherName() const { - return basicWrapperFunctionImplementation(this, "getLauncherName"); + return basicWrapperFunctionImplementation(this, "getLauncherName"); } COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginGameWrapper) std::map IPluginGameWrapper::featureList() const { - return basicWrapperFunctionImplementation>(this, "_featureList"); + return basicWrapperFunctionImplementation>(this, "_featureList"); } /// end IPluginGame Wrapper ///////////////////////////////////// /// IPluginInstaller macro #define COMMON_I_PLUGIN_INSTALLER_WRAPPER_DEFINITIONS(class_name) \ -unsigned int class_name::priority() const { return basicWrapperFunctionImplementation(this, "priority"); } \ -bool class_name::isManualInstaller() const { return basicWrapperFunctionImplementation(this, "isManualInstaller"); } \ -bool class_name::isArchiveSupported(std::shared_ptr tree) const { return basicWrapperFunctionImplementation(this, "isArchiveSupported", tree); } +unsigned int class_name::priority() const { return basicWrapperFunctionImplementation(this, "priority"); } \ +bool class_name::isManualInstaller() const { return basicWrapperFunctionImplementation(this, "isManualInstaller"); } \ +bool class_name::isArchiveSupported(std::shared_ptr tree) const { return basicWrapperFunctionImplementation(this, "isArchiveSupported", tree); } /// end IPluginInstaller macro ///////////////////////////////////// @@ -310,7 +310,7 @@ IPluginInstaller::EInstallResult IPluginInstallerSimpleWrapper::install( IPluginInstaller::EInstallResult, std::shared_ptr, std::tuple, QString, int>> ; - auto ret = basicWrapperFunctionImplementation(this, "install", boost::ref(modName), tree, version, nexusID); + auto ret = basicWrapperFunctionImplementation(this, "install", boost::ref(modName), tree, version, nexusID); return std::visit([&](auto const& t) { using type = std::decay_t; @@ -338,12 +338,12 @@ COMMON_I_PLUGIN_INSTALLER_WRAPPER_DEFINITIONS(IPluginInstallerCustomWrapper) bool IPluginInstallerCustomWrapper::isArchiveSupported(const QString &archiveName) const { - return basicWrapperFunctionImplementation(this, "isArchiveSupported", archiveName); + return basicWrapperFunctionImplementation(this, "isArchiveSupported", archiveName); } std::set IPluginInstallerCustomWrapper::supportedExtensions() const { - return basicWrapperFunctionImplementation>(this, "supportedExtensions"); + return basicWrapperFunctionImplementation>(this, "supportedExtensions"); } IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install( @@ -351,7 +351,7 @@ IPluginInstaller::EInstallResult IPluginInstallerCustomWrapper::install( { // Note: This requires far more less trouble than the "Simple" installer version since 1) there is no tree // and 2) there version and modId cannot be modified: - return basicWrapperFunctionImplementation( + return basicWrapperFunctionImplementation( this, "install", boost::ref(modName), gameName, archiveName, version, modID); } @@ -364,32 +364,32 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginModPageWrapper) QString IPluginModPageWrapper::displayName() const { - return basicWrapperFunctionImplementation(this, "displayName"); + return basicWrapperFunctionImplementation(this, "displayName"); } QIcon IPluginModPageWrapper::icon() const { - return basicWrapperFunctionImplementation(this, "icon"); + return basicWrapperFunctionImplementation(this, "icon"); } QUrl IPluginModPageWrapper::pageURL() const { - return basicWrapperFunctionImplementation(this, "pageURL"); + return basicWrapperFunctionImplementation(this, "pageURL"); } bool IPluginModPageWrapper::useIntegratedBrowser() const { - return basicWrapperFunctionImplementation(this, "useIntegratedBrowser"); + return basicWrapperFunctionImplementation(this, "useIntegratedBrowser"); } bool IPluginModPageWrapper::handlesDownload(const QUrl & pageURL, const QUrl & downloadURL, MOBase::ModRepositoryFileInfo & fileInfo) const { - return basicWrapperFunctionImplementation(this, "handlesDownload", pageURL, downloadURL, fileInfo); + return basicWrapperFunctionImplementation(this, "handlesDownload", pageURL, downloadURL, fileInfo); } void IPluginModPageWrapper::setParentWidget(QWidget * widget) { - basicWrapperFunctionImplementationWithDefault(this, &IPluginModPageWrapper::setParentWidget_Default, "setParentWidget", widget); + basicWrapperFunctionImplementationWithDefault(this, &IPluginModPageWrapper::setParentWidget_Default, "setParentWidget", widget); } /// end IPluginModPage Wrapper ///////////////////////////// @@ -400,7 +400,7 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginPreviewWrapper) std::set IPluginPreviewWrapper::supportedExtensions() const { - return basicWrapperFunctionImplementation>(this, "supportedExtensions"); + return basicWrapperFunctionImplementation>(this, "supportedExtensions"); } QWidget *IPluginPreviewWrapper::genFilePreview(const QString &fileName, const QSize &maxSize) const @@ -435,27 +435,27 @@ COMMON_I_PLUGIN_WRAPPER_DEFINITIONS(IPluginToolWrapper) QString IPluginToolWrapper::displayName() const { - return basicWrapperFunctionImplementation(this, "displayName"); + return basicWrapperFunctionImplementation(this, "displayName"); } QString IPluginToolWrapper::tooltip() const { - return basicWrapperFunctionImplementation(this, "tooltip"); + return basicWrapperFunctionImplementation(this, "tooltip"); } QIcon IPluginToolWrapper::icon() const { - return basicWrapperFunctionImplementation(this, "icon"); + return basicWrapperFunctionImplementation(this, "icon"); } void IPluginToolWrapper::setParentWidget(QWidget *parent) { - basicWrapperFunctionImplementationWithDefault(this, &IPluginToolWrapper::setParentWidget_Default, "setParentWidget", parent); + basicWrapperFunctionImplementationWithDefault(this, &IPluginToolWrapper::setParentWidget_Default, "setParentWidget", parent); } void IPluginToolWrapper::display() const { - basicWrapperFunctionImplementation(this, "display"); + basicWrapperFunctionImplementation(this, "display"); } /// end IPluginTool Wrapper diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 87d3656..b562f06 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -776,6 +776,7 @@ BOOST_PYTHON_MODULE(mobase) .def("displayName", bpy::pure_virtual(&IPluginTool::displayName)) .def("tooltip", bpy::pure_virtual(&IPluginTool::tooltip)) .def("icon", bpy::pure_virtual(&IPluginTool::icon)) + .def("display", bpy::pure_virtual(&IPluginTool::display)) .def("setParentWidget", &IPluginTool::setParentWidget, &IPluginToolWrapper::setParentWidget_Default) .def("_parentWidget", &IPluginToolWrapper::parentWidget, bpy::return_value_policy()) ; diff --git a/src/runner/pythonwrapperutilities.h b/src/runner/pythonwrapperutilities.h index ab44ddc..6e80dbf 100644 --- a/src/runner/pythonwrapperutilities.h +++ b/src/runner/pythonwrapperutilities.h @@ -11,95 +11,65 @@ #include "error.h" #include "gilock.h" +namespace details { + + /** + * @brief Common stuffs for all basicWrapperFunction methods. + */ + template + ReturnType wrapperFunctionImplementation(WrapperTypePtr wrapper, Fn fn, boost::python::object* objPtr, const char *methodName, Args... args) { + GILock lock; + boost::python::override implementation = wrapper->get_override(methodName); + if (!implementation) { + if constexpr (std::is_same_v) { + throw pyexcept::MissingImplementation(wrapper->className, methodName); + } + else { + return std::invoke(fn, wrapper, args...); + } + } + try { + boost::python::object result = implementation(args...); + if (objPtr) { + *objPtr = result; + } + if constexpr (!std::is_same_v) { + return boost::python::extract(result)(); + } + } + catch (const boost::python::error_already_set&) { + throw pyexcept::PythonError(); + } + catch (...) { + throw pyexcept::UnknownException(); + } + } + +} + /** * @brief Call the given method on the wrapper with the given arguments, with proper * exception handling. */ -template +template ReturnType basicWrapperFunctionImplementation(const WrapperType *wrapper, const char *methodName, Args... args) { - GILock lock; - boost::python::override implementation = wrapper->get_override(methodName); - if (!implementation) { - throw pyexcept::MissingImplementation(wrapper->className, methodName); - } - try { - return implementation(args...).as(); - } - catch (const boost::python::error_already_set&) { - throw pyexcept::PythonError(); - } - catch (...) { - throw pyexcept::UnknownException(); - } + return details::wrapperFunctionImplementation(wrapper, nullptr, nullptr, methodName, args...); } /** * @brief Similar to the first-overload but also stores the python object in the given reference. */ -template +template ReturnType basicWrapperFunctionImplementation(const WrapperType* wrapper, boost::python::object &ref, const char* methodName, Args... args) { - GILock lock; - boost::python::override implementation = wrapper->get_override(methodName); - if (!implementation) { - throw pyexcept::MissingImplementation(wrapper->className, methodName); - } - try { - ref = implementation(args...); - return boost::python::extract(ref)(); - } - catch (const boost::python::error_already_set&) { - throw pyexcept::PythonError(); - } - catch (pyexcept::MissingImplementation const& missingImplementation) { - throw missingImplementation; - } - catch (...) { - throw pyexcept::UnknownException(); - } + return details::wrapperFunctionImplementation(wrapper, nullptr, &ref, methodName, args...); } -template -ReturnType basicWrapperFunctionImplementationWithDefault(WrapperType* wrapper, Fn fn, const char* methodName, Args... args) +template +ReturnType basicWrapperFunctionImplementationWithDefault(WrapperTypePtr wrapper, Fn fn, const char* methodName, Args... args) { - GILock lock; - boost::python::override implementation = wrapper->get_override(methodName); - - if (!implementation) { - return std::invoke(fn, wrapper, args...); - } - - try { - return implementation(args...).as(); - } - catch (const boost::python::error_already_set&) { - throw pyexcept::PythonError(); - } - catch (...) { - throw pyexcept::UnknownException(); - } -} - -template -ReturnType basicWrapperFunctionImplementationWithDefault(const WrapperType* wrapper, Fn fn, const char* methodName, Args... args) -{ - GILock lock; - boost::python::override implementation = wrapper->get_override(methodName); - - if (!implementation) { - return std::invoke(fn, wrapper, args...); - } - - try { - return implementation(args...).as(); - } - catch (const boost::python::error_already_set&) { - throw pyexcept::PythonError(); - } - catch (...) { - throw pyexcept::UnknownException(); - } + return details::wrapperFunctionImplementation(wrapper, fn, nullptr, methodName, args...); } #endif // PYTHONWRAPPERUTILITIES_H diff --git a/src/runner/uibasewrappers.h b/src/runner/uibasewrappers.h index c06c1e5..a032853 100644 --- a/src/runner/uibasewrappers.h +++ b/src/runner/uibasewrappers.h @@ -28,11 +28,11 @@ public: 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"); }; + 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"); }; }; // This needs a wrapper but currently I have no idea how to expose this properly to python: @@ -45,7 +45,7 @@ public: // Bring the constructor: using ISaveGameInfoWidget::ISaveGameInfoWidget; - virtual void setSave(QString const& save) override { basicWrapperFunctionImplementation(this, "setSave", save); }; + virtual void setSave(QString const& save) override { basicWrapperFunctionImplementation(this, "setSave", save); }; }; #endif // UIBASEWRAPPERS_H