aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
visitors.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <eigenpy/fwd.hpp>
6#include <fmt/format.h>
7
8namespace aligator {
9namespace python {
10namespace bp = boost::python;
11
12// fwd-declaration
13bp::arg operator""_a(const char *argname, std::size_t);
14
15template <typename T>
16struct ClonePythonVisitor : bp::def_visitor<ClonePythonVisitor<T>> {
17 template <typename PyT> void visit(PyT &obj) const {
18 obj.def("clone", &T::clone, bp::args("self"), "Clone the object.");
19 }
20};
21
22template <typename T>
23struct CreateDataPythonVisitor : bp::def_visitor<CreateDataPythonVisitor<T>> {
24 template <typename Pyclass> void visit(Pyclass &obj) const {
25 obj.def("createData", &T::createData, bp::args("self"),
26 "Create a data object.");
27 }
28};
29
36template <typename T, typename TWrapper>
38 : bp::def_visitor<CreateDataPolymorphicPythonVisitor<T, TWrapper>> {
39 template <typename PyClass> void visit(PyClass &obj) const {
40 obj.def("createData", &T::createData, &TWrapper::default_createData,
41 bp::args("self"), "Create a data object.");
42 }
43};
44
45template <typename T>
46struct CopyableVisitor : bp::def_visitor<CopyableVisitor<T>> {
47 template <typename PyClass> void visit(PyClass &obj) const {
48 obj.def("copy", &copy, bp::arg("self"), "Returns a copy of this.");
49 }
50
51private:
52 static T copy(const T &self) { return T(self); }
53};
54
55template <typename T>
56struct PrintableVisitor : bp::def_visitor<PrintableVisitor<T>> {
57 template <typename PyClass> void visit(PyClass &obj) const {
58 obj.def(bp::self_ns::str(bp::self)).def(bp::self_ns::repr(bp::self));
59 }
60};
61
62template <typename T>
63struct PrintAddressVisitor : bp::def_visitor<PrintAddressVisitor<T>> {
64 template <typename PyClass> void visit(PyClass &obj) const {
65 obj.def("printAddress", printAddress, bp::args("self"));
66 }
67 static void *getAddress(const T &a) { return (void *)&a; }
68 static void printAddress(const T &a) {
69 fmt::print("Address: {:p}\n", getAddress(a));
70 }
71};
72
73// fwd declaration
74template <typename SolverType> struct SolverVisitor;
75
76} // namespace python
77} // namespace aligator
Main package namespace.
void visit(PyClass &obj) const
Definition visitors.hpp:47
void visit(PyClass &obj) const
Definition visitors.hpp:64
static void * getAddress(const T &a)
Definition visitors.hpp:67
static void printAddress(const T &a)
Definition visitors.hpp:68
void visit(PyClass &obj) const
Definition visitors.hpp:57