Debian Codegraph @

plugins/script/interfaces/RegistryInterface.h

raw
1 #pragma once
2
3 #include "iregistry.h"
4 #include "iscript.h"
5 #include "iscriptinterface.h"
6 #include <pybind11/pybind11.h>
7
8 namespace script
9 {
10
11 /**
12 * greebo: This class provides the script interface for the GlobalRegistry module.
13 */
14 class RegistryInterface :
15 public IScriptInterface
16 {
17 public:
18 std::string get(const std::string& key)
19 {
20 return GlobalRegistry().get(key);
21 }
22
23 void set(const std::string& key, const std::string& value)
24 {
25 GlobalRegistry().set(key, value);
26 }
27
28 // IScriptInterface implementation
29 void registerInterface(py::module& scope, py::dict& globals) override
30 {
31 // Add the module declaration to the given python namespace
32 py::class_<RegistryInterface> registry(scope, "Registry");
33 registry.def("get", &RegistryInterface::get);
34 registry.def("set", &RegistryInterface::set);
35
36 // Now point the Python variable "GlobalRegistry" to this instance
37 globals["GlobalRegistry"] = this;
38 }
39 };
40
41 } // namespace script