Skip to content
Snippets Groups Projects
Unverified Commit 257e0afe authored by Wilson Jallet's avatar Wilson Jallet :clapper: Committed by GitHub
Browse files

WIP: Expose boost::none_t type (and std::nullopt_t when available) (#367)

* optional: expose to-value converter for boost::none_t (and std::nullopt_t if possible)

+ add src/optional.cpp to expose none types
+ this allows to have None as a default arg value for functions (also, shows up in stubs)
+ also allows to have none_t return/argument type

* Run pre-commit
parent d971a849
No related branches found
No related tags found
No related merge requests found
Pipeline #28111 passed with warnings
......@@ -207,6 +207,7 @@ set(${PROJECT_NAME}_SOURCES
src/quaternion.cpp
src/geometry-conversion.cpp
src/std-vector.cpp
src/optional.cpp
src/version.cpp)
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES}
......
......@@ -56,6 +56,15 @@ struct nullopt_helper<std::optional> {
};
#endif
template <typename NoneType>
struct NoneToPython {
static PyObject *convert(const NoneType &) { Py_RETURN_NONE; }
static void registration() {
bp::to_python_converter<NoneType, NoneToPython, false>();
}
};
template <typename T,
template <typename> class OptionalTpl = EIGENPY_DEFAULT_OPTIONAL>
struct OptionalToPython {
......
......@@ -22,6 +22,8 @@ void exposeMatrixComplexFloat();
void exposeMatrixComplexDouble();
void exposeMatrixComplexLongDouble();
void exposeNoneType();
/* Enable Eigen-Numpy serialization for a set of standard MatrixBase instances.
*/
void enableEigenPy() {
......@@ -54,6 +56,8 @@ void enableEigenPy() {
exposeMatrixComplexFloat();
exposeMatrixComplexDouble();
exposeMatrixComplexLongDouble();
exposeNoneType();
}
} // namespace eigenpy
/// Copyright 2023 CNRS, INRIA
#include "eigenpy/optional.hpp"
namespace eigenpy {
void exposeNoneType() {
detail::NoneToPython<boost::none_t>::registration();
#ifdef EIGENPY_WITH_CXX17_SUPPORT
detail::NoneToPython<std::nullopt_t>::registration();
#endif
}
} // namespace eigenpy
......@@ -74,6 +74,6 @@ BOOST_PYTHON_MODULE(@MODNAME@) {
bp::make_setter(&mystruct::msg));
bp::def("none_if_zero", none_if_zero, bp::args("i"));
bp::def("create_if_true", create_if_true, bp::args("flag", "b"));
bp::def("create_if_true", create_if_true, (bp::arg("flag"), bp::arg("b") = OPT_NONE));
bp::def("random_mat_if_true", random_mat_if_true, bp::args("flag"));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment