diff --git a/doc/source/doxygen-docs/changelog.md b/doc/source/doxygen-docs/changelog.md index 6f6963d5ee..acf525c987 100644 --- a/doc/source/doxygen-docs/changelog.md +++ b/doc/source/doxygen-docs/changelog.md @@ -1,6 +1,9 @@ \page changelog Change Log # Version 2.9.4: UNRELEASED +- Python: + - maps and multimaps are iterable again (Fixes a regression in v2.9.3) + - timestamps now has a `__str__` operator and `to_double()` method. - BUG FIXES: - Fix fail to build with libftdi1 v1.4 (Ubuntu Focal). diff --git a/python/generate-python.sh b/python/generate-python.sh index 50cd377696..11fe202b20 100755 --- a/python/generate-python.sh +++ b/python/generate-python.sh @@ -66,10 +66,6 @@ $HOME/code/binder/build/source/binder \ -I$HOME/code/mrpt/libs/typemeta/include \ -I$HOME/code/mrpt/libs/vision/include/ \ -# applying manual patches: -echo "Applying manual patches..." -find . -name "*.diff" | xargs -I FIL bash -c "git apply FIL" - # Workarounds to binder limitations: # These are to ensure multiplatform portatbility of generated code # (e.g. avoid build errors in armhf) @@ -96,4 +92,7 @@ sed -i -e 's/unsigned long/size_t/g' $WRAP_OUT_DIR/std/stl_multimap.cpp find $WRAP_OUT_DIR -name "*.cpp" | xargs -I FIL \ sed -i -e 's/(long)/(int64_t)/g' FIL +# applying manual patches: +echo "Applying manual patches..." +find . -name "*.diff" | xargs -I FIL bash -c "git apply FIL" diff --git a/python/patch-007.diff b/python/patch-007.diff new file mode 100644 index 0000000000..a890a43d83 --- /dev/null +++ b/python/patch-007.diff @@ -0,0 +1,93 @@ +diff --git a/python/src/std/stl_deque.cpp b/python/src/std/stl_deque.cpp +index 1638b4d29..4c5984034 100644 +--- a/python/src/std/stl_deque.cpp ++++ b/python/src/std/stl_deque.cpp +@@ -56,6 +56,11 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam + cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); + cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); + cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); ++ ++ cl.def("__iter__", [](const std::deque> &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); ++ + } + { // std::deque file:bits/stl_deque.h line:766 + pybind11::class_>, std::shared_ptr>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_math_TPose2D_mrpt_bayes_particle_storage_mode_VALUE_t", ""); +@@ -90,5 +95,10 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam + cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); + cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); + cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); ++ ++ cl.def("__iter__", [](const std::deque> &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); ++ + } + } +diff --git a/python/src/std/stl_deque_1.cpp b/python/src/std/stl_deque_1.cpp +index b16449336..69668158e 100644 +--- a/python/src/std/stl_deque_1.cpp ++++ b/python/src/std/stl_deque_1.cpp +@@ -64,6 +64,11 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n + cl.def("pop_back", (void (std::deque::*)()) &std::deque::pop_back, "C++: std::deque::pop_back() --> void"); + cl.def("swap", (void (std::deque::*)(class std::deque &)) &std::deque::swap, "C++: std::deque::swap(class std::deque &) --> void", pybind11::arg("__x")); + cl.def("clear", (void (std::deque::*)()) &std::deque::clear, "C++: std::deque::clear() --> void"); ++ ++ cl.def("__iter__", [](const std::deque &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); ++ + } + { // std::deque file:bits/stl_deque.h line:766 + pybind11::class_>, std::shared_ptr>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_maps_CRBPFParticleData_mrpt_bayes_particle_storage_mode_POINTER_t", ""); +@@ -91,5 +96,10 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n + cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); + cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); + cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); ++ ++ cl.def("__iter__", [](const std::deque> &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); ++ + } + } +diff --git a/python/src/std/stl_multimap.cpp b/python/src/std/stl_multimap.cpp +index ccfa54684..2b4e8b2ab 100644 +--- a/python/src/std/stl_multimap.cpp ++++ b/python/src/std/stl_multimap.cpp +@@ -56,6 +56,10 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const & + cl.def("key_comp", (struct std::less (std::multimap > >,std::shared_ptr>::*)() const) &std::multimap>>, std::shared_ptr>::key_comp, "C++: std::multimap>>, std::shared_ptr>::key_comp() const --> struct std::less"); + cl.def("count", (size_t (std::multimap > >,std::shared_ptr>::*)(const mrpt::Clock::time_point &) const) &std::multimap>>, std::shared_ptr>::count, "C++: std::multimap>>, std::shared_ptr>::count(const mrpt::Clock::time_point &) const --> size_t", pybind11::arg("__x")); + cl.def("equal_range", (struct std::pair > >, struct std::_Rb_tree_iterator > > > (std::multimap > >,std::shared_ptr>::*)(const mrpt::Clock::time_point &)) &std::multimap>>, std::shared_ptr>::equal_range, "C++: std::multimap>>, std::shared_ptr>::equal_range(const mrpt::Clock::time_point &) --> struct std::pair > >, struct std::_Rb_tree_iterator > > >", pybind11::arg("__x")); ++ ++ cl.def("__iter__", [](const std::multimap > >,std::shared_ptr> &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); + } + { // std::map file:bits/stl_map.h line:100 + pybind11::class_, std::shared_ptr>> cl(M("std"), "map_mrpt_containers_yaml_node_t_mrpt_containers_yaml_node_t_t", ""); +@@ -82,5 +86,9 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const & + cl.def("key_comp", (struct std::less (std::map::*)() const) &std::map::key_comp, "C++: std::map::key_comp() const --> struct std::less"); + cl.def("count", (size_t (std::map::*)(const struct mrpt::containers::yaml::node_t &) const) &std::map::count, "C++: std::map::count(const struct mrpt::containers::yaml::node_t &) const --> size_t", pybind11::arg("__x")); + cl.def("equal_range", (struct std::pair >, struct std::_Rb_tree_iterator > > (std::map::*)(const struct mrpt::containers::yaml::node_t &)) &std::map::equal_range, "C++: std::map::equal_range(const struct mrpt::containers::yaml::node_t &) --> struct std::pair >, struct std::_Rb_tree_iterator > >", pybind11::arg("__x")); ++ ++ cl.def("__iter__", [](const std::map &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); + } + } +diff --git a/python/src/std/stl_vector.cpp b/python/src/std/stl_vector.cpp +index f4c9f4013..6d067dc27 100644 +--- a/python/src/std/stl_vector.cpp ++++ b/python/src/std/stl_vector.cpp +@@ -62,5 +62,9 @@ void bind_std_stl_vector(std::function< pybind11::module &(std::string const &na + cl.def("erase", (class __gnu_cxx::__normal_iterator > (std::vector::*)(class __gnu_cxx::__normal_iterator >, class __gnu_cxx::__normal_iterator >)) &std::vector::erase, "C++: std::vector::erase(class __gnu_cxx::__normal_iterator >, class __gnu_cxx::__normal_iterator >) --> class __gnu_cxx::__normal_iterator >", pybind11::arg("__first"), pybind11::arg("__last")); + cl.def("swap", (void (std::vector::*)(class std::vector &)) &std::vector::swap, "C++: std::vector::swap(class std::vector &) --> void", pybind11::arg("__x")); + cl.def("clear", (void (std::vector::*)()) &std::vector::clear, "C++: std::vector::clear() --> void"); ++ ++ cl.def("__iter__", [](const std::vector &o) { ++ return pybind11::make_iterator(o.begin(), o.end()); ++ }, pybind11::keep_alive<0, 1>()); + } + } diff --git a/python/patch-008.diff b/python/patch-008.diff new file mode 100644 index 0000000000..7be4ec8b2d --- /dev/null +++ b/python/patch-008.diff @@ -0,0 +1,21 @@ +diff --git a/python/src/std/chrono.cpp b/python/src/std/chrono.cpp +index 17eaa6e50..4c07e8ce6 100644 +--- a/python/src/std/chrono.cpp ++++ b/python/src/std/chrono.cpp +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + + + #ifndef BINDER_PYBIND11_TYPE_CASTER +@@ -50,5 +51,8 @@ void bind_std_chrono(std::function< pybind11::module &(std::string const &namesp + cl.def_static("min", (mrpt::Clock::time_point (*)()) &std::chrono::time_point>>::min, "C++: std::chrono::time_point>>::min() --> mrpt::Clock::time_point"); + cl.def_static("max", (mrpt::Clock::time_point (*)()) &std::chrono::time_point>>::max, "C++: std::chrono::time_point>>::max() --> mrpt::Clock::time_point"); + cl.def("assign", (mrpt::Clock::time_point & (mrpt::Clock::time_point::*)(const mrpt::Clock::time_point &)) &std::chrono::time_point>>::operator=, "C++: std::chrono::time_point>>::operator=(const mrpt::Clock::time_point &) --> mrpt::Clock::time_point &", pybind11::return_value_policy::automatic, pybind11::arg("")); ++ ++ cl.def("to_double", [](const mrpt::Clock::time_point &t) { return mrpt::Clock::toDouble(t); }); ++ cl.def("__str__", [](const mrpt::Clock::time_point &t) { return mrpt::system::dateTimeLocalToString(t); }, "Gets the date and time of the given timestamp in local time."); + } + } diff --git a/python/src/std/chrono.cpp b/python/src/std/chrono.cpp index 17eaa6e504..d3b29fe5a4 100644 --- a/python/src/std/chrono.cpp +++ b/python/src/std/chrono.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #ifndef BINDER_PYBIND11_TYPE_CASTER @@ -50,5 +51,8 @@ void bind_std_chrono(std::function< pybind11::module &(std::string const &namesp cl.def_static("min", (mrpt::Clock::time_point (*)()) &std::chrono::time_point>>::min, "C++: std::chrono::time_point>>::min() --> mrpt::Clock::time_point"); cl.def_static("max", (mrpt::Clock::time_point (*)()) &std::chrono::time_point>>::max, "C++: std::chrono::time_point>>::max() --> mrpt::Clock::time_point"); cl.def("assign", (mrpt::Clock::time_point & (mrpt::Clock::time_point::*)(const mrpt::Clock::time_point &)) &std::chrono::time_point>>::operator=, "C++: std::chrono::time_point>>::operator=(const mrpt::Clock::time_point &) --> mrpt::Clock::time_point &", pybind11::return_value_policy::automatic, pybind11::arg("")); + + cl.def("to_double", [](const mrpt::Clock::time_point &t) { return mrpt::Clock::toDouble(t); }); + cl.def("__str__", [](const mrpt::Clock::time_point &t) { return mrpt::system::dateTimeLocalToString(t); }, "Gets the date and time of the given timestamp in local time."); } } diff --git a/python/src/std/stl_deque.cpp b/python/src/std/stl_deque.cpp index 1638b4d296..4c59840342 100644 --- a/python/src/std/stl_deque.cpp +++ b/python/src/std/stl_deque.cpp @@ -56,6 +56,11 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); + + cl.def("__iter__", [](const std::deque> &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); + } { // std::deque file:bits/stl_deque.h line:766 pybind11::class_>, std::shared_ptr>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_math_TPose2D_mrpt_bayes_particle_storage_mode_VALUE_t", ""); @@ -90,5 +95,10 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); + + cl.def("__iter__", [](const std::deque> &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); + } } diff --git a/python/src/std/stl_deque_1.cpp b/python/src/std/stl_deque_1.cpp index b164493360..69668158ed 100644 --- a/python/src/std/stl_deque_1.cpp +++ b/python/src/std/stl_deque_1.cpp @@ -64,6 +64,11 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n cl.def("pop_back", (void (std::deque::*)()) &std::deque::pop_back, "C++: std::deque::pop_back() --> void"); cl.def("swap", (void (std::deque::*)(class std::deque &)) &std::deque::swap, "C++: std::deque::swap(class std::deque &) --> void", pybind11::arg("__x")); cl.def("clear", (void (std::deque::*)()) &std::deque::clear, "C++: std::deque::clear() --> void"); + + cl.def("__iter__", [](const std::deque &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); + } { // std::deque file:bits/stl_deque.h line:766 pybind11::class_>, std::shared_ptr>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_maps_CRBPFParticleData_mrpt_bayes_particle_storage_mode_POINTER_t", ""); @@ -91,5 +96,10 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n cl.def("pop_back", (void (std::deque>::*)()) &std::deque>::pop_back, "C++: std::deque>::pop_back() --> void"); cl.def("swap", (void (std::deque>::*)(class std::deque > &)) &std::deque>::swap, "C++: std::deque>::swap(class std::deque > &) --> void", pybind11::arg("__x")); cl.def("clear", (void (std::deque>::*)()) &std::deque>::clear, "C++: std::deque>::clear() --> void"); + + cl.def("__iter__", [](const std::deque> &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); + } } diff --git a/python/src/std/stl_multimap.cpp b/python/src/std/stl_multimap.cpp index ccfa546840..2b4e8b2abc 100644 --- a/python/src/std/stl_multimap.cpp +++ b/python/src/std/stl_multimap.cpp @@ -56,6 +56,10 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const & cl.def("key_comp", (struct std::less (std::multimap > >,std::shared_ptr>::*)() const) &std::multimap>>, std::shared_ptr>::key_comp, "C++: std::multimap>>, std::shared_ptr>::key_comp() const --> struct std::less"); cl.def("count", (size_t (std::multimap > >,std::shared_ptr>::*)(const mrpt::Clock::time_point &) const) &std::multimap>>, std::shared_ptr>::count, "C++: std::multimap>>, std::shared_ptr>::count(const mrpt::Clock::time_point &) const --> size_t", pybind11::arg("__x")); cl.def("equal_range", (struct std::pair > >, struct std::_Rb_tree_iterator > > > (std::multimap > >,std::shared_ptr>::*)(const mrpt::Clock::time_point &)) &std::multimap>>, std::shared_ptr>::equal_range, "C++: std::multimap>>, std::shared_ptr>::equal_range(const mrpt::Clock::time_point &) --> struct std::pair > >, struct std::_Rb_tree_iterator > > >", pybind11::arg("__x")); + + cl.def("__iter__", [](const std::multimap > >,std::shared_ptr> &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); } { // std::map file:bits/stl_map.h line:100 pybind11::class_, std::shared_ptr>> cl(M("std"), "map_mrpt_containers_yaml_node_t_mrpt_containers_yaml_node_t_t", ""); @@ -82,5 +86,9 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const & cl.def("key_comp", (struct std::less (std::map::*)() const) &std::map::key_comp, "C++: std::map::key_comp() const --> struct std::less"); cl.def("count", (size_t (std::map::*)(const struct mrpt::containers::yaml::node_t &) const) &std::map::count, "C++: std::map::count(const struct mrpt::containers::yaml::node_t &) const --> size_t", pybind11::arg("__x")); cl.def("equal_range", (struct std::pair >, struct std::_Rb_tree_iterator > > (std::map::*)(const struct mrpt::containers::yaml::node_t &)) &std::map::equal_range, "C++: std::map::equal_range(const struct mrpt::containers::yaml::node_t &) --> struct std::pair >, struct std::_Rb_tree_iterator > >", pybind11::arg("__x")); + + cl.def("__iter__", [](const std::map &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); } } diff --git a/python/src/std/stl_vector.cpp b/python/src/std/stl_vector.cpp index f4c9f40137..6d067dc27c 100644 --- a/python/src/std/stl_vector.cpp +++ b/python/src/std/stl_vector.cpp @@ -62,5 +62,9 @@ void bind_std_stl_vector(std::function< pybind11::module &(std::string const &na cl.def("erase", (class __gnu_cxx::__normal_iterator > (std::vector::*)(class __gnu_cxx::__normal_iterator >, class __gnu_cxx::__normal_iterator >)) &std::vector::erase, "C++: std::vector::erase(class __gnu_cxx::__normal_iterator >, class __gnu_cxx::__normal_iterator >) --> class __gnu_cxx::__normal_iterator >", pybind11::arg("__first"), pybind11::arg("__last")); cl.def("swap", (void (std::vector::*)(class std::vector &)) &std::vector::swap, "C++: std::vector::swap(class std::vector &) --> void", pybind11::arg("__x")); cl.def("clear", (void (std::vector::*)()) &std::vector::clear, "C++: std::vector::clear() --> void"); + + cl.def("__iter__", [](const std::vector &o) { + return pybind11::make_iterator(o.begin(), o.end()); + }, pybind11::keep_alive<0, 1>()); } }