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 #include <string>
10 
11 namespace pinocchio
12 {
13  namespace python
14  {
15 
19  inline std::string getCurrentScopeName()
20  {
21  namespace bp = boost::python;
22  bp::scope current_scope;
23 
24  return std::string(bp::extract<const char *>(current_scope.attr("__name__")));
25  }
26 
34  inline boost::python::object getOrCreatePythonNamespace(const std::string & submodule_name)
35  {
36  namespace bp = boost::python;
37 
38  const std::string complete_submodule_name = getCurrentScopeName() + "." + submodule_name;
39 
40  bp::object submodule(bp::borrowed(PyImport_AddModule(complete_submodule_name.c_str())));
41  bp::scope current_scope;
42  current_scope.attr(submodule_name.c_str()) = submodule;
43 
44  return submodule;
45  }
46  } // namespace python
47 } // namespace pinocchio
48 
49 #endif // ifndef __pinocchio_python_utils_namespace_hpp__
boost::python
pinocchio::python::getCurrentScopeName
std::string getCurrentScopeName()
Definition: namespace.hpp:19
pinocchio::python::getOrCreatePythonNamespace
boost::python::object getOrCreatePythonNamespace(const std::string &submodule_name)
Helper to create or simply return an existing namespace in Python.
Definition: namespace.hpp:34
python
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:32