aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <eigenpy/registration.hpp>
6#include <boost/python.hpp>
7
8namespace aligator {
9namespace python {
10namespace bp = boost::python;
11
12inline std::string get_scope_name(bp::scope scope) {
13 return std::string(bp::extract<const char *>(scope.attr("__name__")));
14}
15
22inline bp::object get_namespace(const std::string &name) {
23 bp::scope cur_scope; // current scope
24 const std::string complete_name = get_scope_name(cur_scope) + "." + name;
25 bp::object submodule(bp::borrowed(PyImport_AddModule(complete_name.c_str())));
26 cur_scope.attr(name.c_str()) = submodule;
27 return submodule;
28}
29
30template <typename T> bool register_enum_symlink(bool export_values) {
31 namespace bp = boost::python;
32 namespace converter = bp::converter;
33 if (eigenpy::register_symbolic_link_to_registered_type<T>()) {
34 const bp::type_info info = bp::type_id<T>();
35 const converter::registration *reg = converter::registry::query(info);
36 bp::object class_obj(bp::handle<>(reg->get_class_object()));
37 bp::enum_<T> &as_enum = static_cast<bp::enum_<T> &>(class_obj);
38 if (export_values)
39 as_enum.export_values();
40 return true;
41 }
42 return false;
43}
44
45} // namespace python
46} // namespace aligator
The Python bindings.
Definition blk-matrix.hpp:5
bp::object get_namespace(const std::string &name)
Create or retrieve a Python scope (that is, a class or module namespace).
Definition utils.hpp:22
std::string get_scope_name(bp::scope scope)
Definition utils.hpp:12
bool register_enum_symlink(bool export_values)
Definition utils.hpp:30
Main package namespace.