pymvsim_comms.cpp
Go to the documentation of this file.
1 #include <pybind11/pybind11.h>
2 
3 #include <algorithm>
4 #include <functional>
5 #include <map>
6 #include <memory>
7 #include <stdexcept>
8 #include <string>
9 
10 typedef std::function<pybind11::module&(std::string const&)> ModuleGetter;
11 
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);
20 
21 PYBIND11_MODULE(pymvsim_comms, root_module)
22 {
23  root_module.doc() = "pymvsim_comms module";
24 
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!!!");
32  return it->second;
33  };
34 
35  modules[""] = root_module;
36 
37  static std::vector<std::string> const reserved_python_words{
38  "nonlocal",
39  "global",
40  };
41 
42  auto mangle_namespace_name([](std::string const& ns) -> std::string {
43  if (std::find(
44  reserved_python_words.begin(), reserved_python_words.end(),
45  ns) == reserved_python_words.end())
46  return ns;
47  else
48  return ns + '_';
49  });
50 
51  std::vector<std::pair<std::string, std::string>> sub_modules{
52  {"", "mvsim"},
53  {"", "std"},
54  };
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")
60  .c_str());
61 
62  // pybind11::class_<std::shared_ptr<void>>(M(""), "_encapsulated_data_");
63 
68 }
void bind_std_stdexcept(std::function< pybind11::module &(std::string const &namespace_)> &M)
Definition: stdexcept.cpp:51
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)
Definition: exception.cpp:49


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21