Skip to content

Commit 4541039

Browse files
committed
[python] remove redundant includes, delete macros.hpp (move contents out)
[python] `StdVectorPythonVisitor` had been using-decl in fwd header
1 parent 78bc8e8 commit 4541039

File tree

8 files changed

+43
-62
lines changed

8 files changed

+43
-62
lines changed

bindings/python/include/aligator/python/fwd.hpp

+41-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#pragma once
22

33
#include "aligator/context.hpp"
4-
#include "aligator/python/macros.hpp"
4+
#include "aligator/utils/exceptions.hpp"
55

66
#include <eigenpy/eigenpy.hpp>
77
#include <eigenpy/std-vector.hpp>
88

9+
#include <type_traits>
10+
911
#include <proxsuite-nlp/python/polymorphic.hpp>
1012

11-
namespace aligator {
1213
/// @brief The Python bindings.
13-
namespace python {
14+
namespace aligator::python {
1415
namespace bp = boost::python;
1516
using eigenpy::StdVectorPythonVisitor;
1617

@@ -19,6 +20,16 @@ inline bp::arg operator""_a(const char *argname, std::size_t) {
1920
return bp::arg(argname);
2021
}
2122

23+
namespace internal {
24+
25+
template <typename ret_type>
26+
ret_type suppress_if_void(bp::detail::method_result &&o) {
27+
if constexpr (!std::is_void_v<ret_type>)
28+
return o.operator ret_type();
29+
}
30+
31+
} // namespace internal
32+
2233
/// Expose GAR module
2334
void exposeGAR();
2435
/// Expose stagewise function classes
@@ -53,5 +64,30 @@ void exposeFilter();
5364
void exposePinocchioFeatures();
5465
#endif
5566

56-
} // namespace python
57-
} // namespace aligator
67+
} // namespace aligator::python
68+
69+
#define ALIGATOR_PYTHON_OVERRIDE_IMPL(ret_type, pyname, ...) \
70+
do { \
71+
if (bp::override fo = this->get_override(pyname)) { \
72+
decltype(auto) o = fo(__VA_ARGS__); \
73+
return ::aligator::python::internal::suppress_if_void<ret_type>( \
74+
std::move(o)); \
75+
} \
76+
} while (false)
77+
78+
/**
79+
* @def ALIGATOR_PYTHON_OVERRIDE_PURE(ret_type, pyname, ...)
80+
* @brief Define the body of a virtual function override. This is meant
81+
* to reduce boilerplate code when exposing virtual member functions.
82+
*/
83+
#define ALIGATOR_PYTHON_OVERRIDE_PURE(ret_type, pyname, ...) \
84+
ALIGATOR_PYTHON_OVERRIDE_IMPL(ret_type, pyname, __VA_ARGS__); \
85+
ALIGATOR_RUNTIME_ERROR("Tried to call pure virtual function {:s}.", pyname)
86+
87+
/**
88+
* @def ALIGATOR_PYTHON_OVERRIDE(ret_type, cname, fname, ...)
89+
* @copybrief ALIGATOR_PYTHON_OVERRIDE_PURE()
90+
*/
91+
#define ALIGATOR_PYTHON_OVERRIDE(ret_type, cname, fname, ...) \
92+
ALIGATOR_PYTHON_OVERRIDE_IMPL(ret_type, #fname, __VA_ARGS__); \
93+
return cname::fname(__VA_ARGS__)

bindings/python/include/aligator/python/macros.hpp

-47
This file was deleted.

bindings/python/include/aligator/python/polymorphic-convertible.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "aligator/python/fwd.hpp"
4-
#include <proxsuite-nlp/python/polymorphic.hpp>
54

65
#include <boost/mpl/vector.hpp>
76

bindings/python/include/aligator/python/solvers.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/// @file
2-
/// @copyright Copyright (C) 2024 LAAS-CNRS, INRIA
2+
/// @copyright Copyright (C) 2024 LAAS-CNRS, 2024-2025 INRIA
33
#pragma once
44

55
#include <eigenpy/fwd.hpp>
6-
#include <proxsuite-nlp/python/deprecation-policy.hpp>
76
#include <fmt/format.h>
87

98
namespace aligator::python {

bindings/python/src/expose-cartesian-product.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "aligator/python/fwd.hpp"
22
#include "aligator/modelling/spaces/cartesian-product.hpp"
33

4-
#include <proxsuite-nlp/python/polymorphic.hpp>
5-
64
namespace aligator::python {
75

86
using context::Manifold;

bindings/python/src/expose-constraint.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "aligator/python/fwd.hpp"
22

33
#include "aligator/core/constraint.hpp"
4-
#include <proxsuite-nlp/python/polymorphic.hpp>
54
#include <proxsuite-nlp/constraint-base.hpp>
65
#include <eigenpy/deprecation-policy.hpp>
76

bindings/python/src/expose-manifold.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "aligator/modelling/spaces/cartesian-product.hpp"
66
#include "aligator/modelling/spaces/tangent-bundle.hpp"
77

8-
#include <proxsuite-nlp/python/polymorphic.hpp>
98
#include <eigenpy/std-vector.hpp>
109

1110
namespace aligator::python {
@@ -122,7 +121,7 @@ void exposeManifoldBase() {
122121
return a * b;
123122
});
124123

125-
eigenpy::StdVectorPythonVisitor<std::vector<PolyManifold>>::expose(
124+
StdVectorPythonVisitor<std::vector<PolyManifold>>::expose(
126125
"StdVec_Manifold",
127126
eigenpy::details::overload_base_get_item_for_std_vector<
128127
std::vector<PolyManifold>>());

bindings/python/src/modelling/expose-pinocchio-manifolds.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "aligator/modelling/spaces/multibody.hpp"
55
#include "aligator/modelling/spaces/pinocchio-groups.hpp"
66

7-
#include <proxsuite-nlp/python/polymorphic.hpp>
8-
97
namespace aligator::python {
108
using context::Manifold;
119
using context::Scalar;

0 commit comments

Comments
 (0)