namespace.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2021 INRIA
3 //
4 
5 #ifndef __pinocchio_python_utils_namespace_hpp__
6 #define __pinocchio_python_utils_namespace_hpp__
7 
8 #include <boost/python.hpp>
9 
10 namespace pinocchio
11 {
12  namespace python
13  {
14 
22  inline boost::python::object getOrCreatePythonNamespace(const std::string & submodule_name)
23  {
24  namespace bp = boost::python;
25 
26  bp::scope current_scope;
27  std::string current_scope_name(bp::extract<const char*>(current_scope.attr("__name__")));
28  std::string complete_submodule_name = current_scope_name + "." + submodule_name;
29 
30  bp::object submodule(bp::borrowed(PyImport_AddModule(complete_submodule_name.c_str())));
31  current_scope.attr(submodule_name.c_str()) = submodule;
32 
33  return submodule;
34  }
35  } // namespace python
36 } // namespace pinocchio
37 
38 #endif // ifndef __pinocchio_python_utils_namespace_hpp__
boost::python::object getOrCreatePythonNamespace(const std::string &submodule_name)
Helper to create or simply return an existing namespace in Python.
Definition: namespace.hpp:22
Main pinocchio namespace.
Definition: timings.cpp:28


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:32