summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/bindings.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/python/bindings.cpp b/python/bindings.cpp
new file mode 100644
index 0000000..5c816f6
--- /dev/null
+++ b/python/bindings.cpp
@@ -0,0 +1,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);
+}