1 #include <pybind11/pybind11.h>
10 typedef std::function<pybind11::module&(std::string
const&)>
ModuleGetter;
12 void bind_std_exception(std::function<pybind11::module&(std::string
const& namespace_)>& M);
13 void bind_std_stdexcept(std::function<pybind11::module&(std::string
const& namespace_)>& M);
19 root_module.doc() =
"pymvsim_comms module";
21 std::map<std::string, pybind11::module> modules;
22 ModuleGetter M = [&](std::string
const& namespace_) -> pybind11::module&
24 auto it = modules.find(namespace_);
25 if (it == modules.end())
26 throw std::runtime_error(
27 "Attempt to access pybind11::module for namespace " + namespace_ +
28 " before it was created!!!");
32 modules[
""] = root_module;
34 static std::vector<std::string>
const reserved_python_words{
39 auto mangle_namespace_name(
40 [](std::string
const& ns) -> std::string
42 if (std::find(reserved_python_words.begin(), reserved_python_words.end(), ns) ==
43 reserved_python_words.end())
49 std::vector<std::pair<std::string, std::string>> sub_modules{
53 for (
auto& p : sub_modules)
54 modules[p.first.size() ? p.first +
"::" + p.second : p.second] =
55 modules[p.first].def_submodule(
56 mangle_namespace_name(p.second).c_str(),
57 (
"Bindings for " + p.first +
"::" + p.second +
" namespace").c_str());