1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "../src/settings.h"
namespace py = pybind11;
using namespace pybind11::literals;
class PyKaZoeSettings {
KaZoe::Settings m_settings;
public:
PyKaZoeSettings();
std::string __repr__();
static void add_python_binding(pybind11::module &m);
SettingValue get(std::string key, std::string category, SettingValue def);
SettingValue set(std::string key, SettingValue value, std::string category);
};
PyKaZoeSettings::PyKaZoeSettings() {
py::module sys = py::module::import("sys");
py::list argv = sys.attr("argv");
m_settings.setId(argv[0].cast<std::string>());
}
SettingValue PyKaZoeSettings::get(std::string key, std::string category, SettingValue def) {
return m_settings.get(key, category, def);
}
SettingValue PyKaZoeSettings::set(std::string key, SettingValue value, std::string category) {
return m_settings.set(key, value, category);
}
std::string PyKaZoeSettings::__repr__() {
std::string result = "KaZoeSettings";
return result;
}
void PyKaZoeSettings::add_python_binding(pybind11::module &m)
{
py::class_<PyKaZoeSettings>(m, "KaZoeSettings")
.def(py::init<>())
.def("get", [] (PyKaZoeSettings &m, std::string key, std::string category = "", SettingValue def = SettingValue()) {
return m.get(key, category, def);
},
py::arg("key"),
py::arg("category") = "",
py::arg("default") = SettingValue())
.def("set", [] (PyKaZoeSettings &m, std::string key, SettingValue value, std::string category = "") {
return m.set(key, value, category);
},
py::arg("key"),
py::arg("value"),
py::arg("category") = "")
.def("__repr__", &PyKaZoeSettings::__repr__);
}
PYBIND11_MODULE(KaZoeSettings, m) {
m.doc() = R"pbdoc(
Python bindings for KaZoeSettings
)pbdoc";
PyKaZoeSettings::add_python_binding(m);
}
|