Skip to content

Commit 913cb79

Browse files
Change IOrganizer::profile return type to a shared_ptr and remove IProfile wrapper
1 parent 63afb03 commit 913cb79

5 files changed

Lines changed: 20 additions & 57 deletions

File tree

src/mobase/mobase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ PYBIND11_MODULE(mobase, m)
2626

2727
// bindings
2828
//
29-
mo2::python::add_wrapper_bindings(m);
3029
mo2::python::add_basic_bindings(m);
30+
mo2::python::add_wrapper_bindings(m);
3131

3232
// game features must be added before plugins
3333
mo2::python::add_game_feature_bindings(m);

src/mobase/pybind11_all.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "pybind11_utils/smart_variant_wrapper.h"
1919

2020
#include <uibase/game_features/game_feature.h>
21+
#include <uibase/iprofile.h>
2122
#include <uibase/isavegame.h>
2223
#include <uibase/pluginrequirements.h>
2324

@@ -140,6 +141,7 @@ namespace mo2::python {
140141
} // namespace mo2::python
141142

142143
MO2_PYBIND11_SHARED_CPP_HOLDER(MOBase::IPluginRequirement)
144+
MO2_PYBIND11_SHARED_CPP_HOLDER(MOBase::IProfile)
143145
MO2_PYBIND11_SHARED_CPP_HOLDER(MOBase::ISaveGame)
144146
MO2_PYBIND11_SHARED_CPP_HOLDER(MOBase::GameFeature)
145147

src/mobase/wrappers/basic_classes.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ namespace mo2::python {
627627
.def("modList", &IOrganizer::modList, py::return_value_policy::reference)
628628
.def("gameFeatures", &IOrganizer::gameFeatures,
629629
py::return_value_policy::reference)
630-
.def("profile", &IOrganizer::profile, py::return_value_policy::reference)
630+
.def("profile", &IOrganizer::profile)
631631
.def("profileNames", &IOrganizer::profileNames)
632632
.def("getProfile", &IOrganizer::getProfile, "name"_a)
633633

@@ -882,6 +882,21 @@ namespace mo2::python {
882882
m.createTarget);
883883
});
884884

885+
// must be done BEFORE imodlist because there is a default argument to a
886+
// IProfile* in the modlist class
887+
py::class_<IProfile, std::shared_ptr<IProfile>>(m, "IProfile")
888+
.def("name", &IProfile::name)
889+
.def("absolutePath", &IProfile::absolutePath)
890+
.def("localSavesEnabled", &IProfile::localSavesEnabled)
891+
.def("localSettingsEnabled", &IProfile::localSettingsEnabled)
892+
.def("invalidationActive",
893+
[](const IProfile* p) {
894+
bool supported;
895+
bool active = p->invalidationActive(&supported);
896+
return std::make_tuple(active, supported);
897+
})
898+
.def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a);
899+
885900
add_ipluginlist_classes(m);
886901
add_imodlist_classes(m);
887902
add_idownload_manager_classes(m);

src/mobase/wrappers/wrappers.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// IOrganizer must be bring here to properly compile the Python bindings of
1212
// plugin requirements
1313
#include <uibase/imoinfo.h>
14-
#include <uibase/iprofile.h>
1514
#include <uibase/isavegame.h>
1615
#include <uibase/isavegameinfowidget.h>
1716
#include <uibase/pluginrequirements.h>
@@ -76,41 +75,6 @@ namespace mo2::python {
7675
~PySaveGameInfoWidget() { std::cout << "~PySaveGameInfoWidget()" << std::endl; }
7776
};
7877

79-
class PyProfile : public IProfile {
80-
public:
81-
QString name() const override
82-
{
83-
PYBIND11_OVERRIDE_PURE(QString, IProfile, name, );
84-
}
85-
86-
QString absolutePath() const override
87-
{
88-
PYBIND11_OVERRIDE_PURE(QString, IProfile, absolutePath, );
89-
}
90-
91-
bool localSavesEnabled() const override
92-
{
93-
PYBIND11_OVERRIDE_PURE(bool, IProfile, localSavesEnabled, );
94-
}
95-
96-
bool localSettingsEnabled() const override
97-
{
98-
PYBIND11_OVERRIDE_PURE(bool, IProfile, localSettingsEnabled, );
99-
}
100-
101-
bool invalidationActive(bool* supported) const override
102-
{
103-
PYBIND11_OVERRIDE_PURE(bool, IProfile, invalidationActive, supported);
104-
}
105-
106-
QString absoluteIniFilePath(QString iniFile) const override
107-
{
108-
PYBIND11_OVERRIDE_PURE(QString, IProfile, absoluteIniFilePath, iniFile);
109-
}
110-
111-
~PyProfile() { std::cout << "~PyProfile()" << std::endl; }
112-
};
113-
11478
void add_wrapper_bindings(pybind11::module_ m)
11579
{
11680
// ISaveGame - custom type_caster<> for shared_ptr<> to keep the Python object
@@ -151,24 +115,6 @@ namespace mo2::python {
151115
.def("longDescription", &IPluginRequirement::Problem::longDescription);
152116

153117
iPluginRequirementClass.def("check", &IPluginRequirement::check, "organizer"_a);
154-
155-
// IProfile - custom type_caster<> for shared_ptr<> to keep the Python object
156-
// alive when returned from Python (see shared_cpp_owner.h)
157-
158-
// must be done BEFORE imodlist because there is a default argument to a
159-
// IProfile* in the modlist class
160-
py::class_<IProfile, PyProfile, std::shared_ptr<IProfile>>(m, "IProfile")
161-
.def("name", &IProfile::name)
162-
.def("absolutePath", &IProfile::absolutePath)
163-
.def("localSavesEnabled", &IProfile::localSavesEnabled)
164-
.def("localSettingsEnabled", &IProfile::localSettingsEnabled)
165-
.def("invalidationActive",
166-
[](const IProfile* p) {
167-
bool supported;
168-
bool active = p->invalidationActive(&supported);
169-
return std::make_tuple(active, supported);
170-
})
171-
.def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a);
172118
}
173119

174120
} // namespace mo2::python

tests/mocks/MockOrganizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MockOrganizer : public IOrganizer {
3737
MOCK_METHOD(MOBase::IDownloadManager*, downloadManager, (), (const, override));
3838
MOCK_METHOD(MOBase::IPluginList*, pluginList, (), (const, override));
3939
MOCK_METHOD(MOBase::IModList*, modList, (), (const, override));
40-
MOCK_METHOD(MOBase::IProfile*, profile, (), (const, override));
40+
MOCK_METHOD(std::shared_ptr<IProfile>, profile, (), (const, override));
4141
MOCK_METHOD(QStringList, profileNames, (), (const, override));
4242
MOCK_METHOD(std::shared_ptr<const IProfile>, getProfile, (const QString& name), (const, override));
4343
MOCK_METHOD(MOBase::IGameFeatures*, gameFeatures, (), (const, override));

0 commit comments

Comments
 (0)