From 13c6dea8ffbc330f5af6ea386831c0e7e3e6cb6e Mon Sep 17 00:00:00 2001 From: Rohan Budhiraja <proyan@users.noreply.github.com> Date: Wed, 18 Aug 2021 21:27:54 +0200 Subject: [PATCH] [user-type] get class object for type exposed through boost python --- include/eigenpy/user-type.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/eigenpy/user-type.hpp b/include/eigenpy/user-type.hpp index a9b0ece5..8c194886 100644 --- a/include/eigenpy/user-type.hpp +++ b/include/eigenpy/user-type.hpp @@ -289,6 +289,28 @@ namespace eigenpy return true; } + + /// \brief Get the class object for a wrapped type that has been exposed + /// through Boost.Python. + template <typename T> + boost::python::object getInstanceClass() + { + // Query into the registry for type T. + namespace bp = boost::python; + bp::type_info type = bp::type_id<T>(); + const bp::converter::registration* registration = + bp::converter::registry::query(type); + + // If the class is not registered, return None. + if (!registration) { + //std::cerr<<"Class Not Registered. Returning Empty."<<std::endl; + return bp::object(); + } + + bp::handle<PyTypeObject> handle(bp::borrowed(registration->get_class_object())); + return bp::object(handle); + } + template<typename Scalar> int registerNewType(PyTypeObject * py_type_ptr = NULL) { -- GitLab