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