1 #include <pybind11/pybind11.h> 10 typedef std::function<pybind11::module&(std::string const&)>
ModuleGetter;
13 std::function<pybind11::module&(std::string
const& namespace_)>& M);
15 std::function<pybind11::module&(std::string
const& namespace_)>& M);
17 std::function<pybind11::module&(std::string
const& namespace_)>& M);
19 std::function<pybind11::module&(std::string
const& namespace_)>& M);
23 root_module.doc() =
"pymvsim_comms module";
25 std::map<std::string, pybind11::module> modules;
26 ModuleGetter M = [&](std::string
const& namespace_) -> pybind11::module& {
27 auto it = modules.find(namespace_);
28 if (it == modules.end())
29 throw std::runtime_error(
30 "Attempt to access pybind11::module for namespace " +
31 namespace_ +
" before it was created!!!");
35 modules[
""] = root_module;
37 static std::vector<std::string>
const reserved_python_words{
42 auto mangle_namespace_name([](std::string
const& ns) -> std::string {
44 reserved_python_words.begin(), reserved_python_words.end(),
45 ns) == reserved_python_words.end())
51 std::vector<std::pair<std::string, std::string>> sub_modules{
55 for (
auto& p : sub_modules)
56 modules[p.first.size() ? p.first +
"::" + p.second : p.second] =
57 modules[p.first].def_submodule(
58 mangle_namespace_name(p.second).c_str(),
59 (
"Bindings for " + p.first +
"::" + p.second +
" namespace")
void bind_std_stdexcept(std::function< pybind11::module &(std::string const &namespace_)> &M)
std::function< pybind11::module &(std::string const &)> ModuleGetter
PYBIND11_MODULE(pymvsim_comms, root_module)
void bind_mvsim_Comms_Client(std::function< pybind11::module &(std::string const &namespace_)> &M)
void bind_mvsim_Comms_common(std::function< pybind11::module &(std::string const &namespace_)> &M)
void bind_std_exception(std::function< pybind11::module &(std::string const &namespace_)> &M)