Skip to content

Commit 13c6dea

Browse files
committed
[user-type] get class object for type exposed through boost python
1 parent 4492a1a commit 13c6dea

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/eigenpy/user-type.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,28 @@ namespace eigenpy
289289
return true;
290290
}
291291

292+
293+
/// \brief Get the class object for a wrapped type that has been exposed
294+
/// through Boost.Python.
295+
template <typename T>
296+
boost::python::object getInstanceClass()
297+
{
298+
// Query into the registry for type T.
299+
namespace bp = boost::python;
300+
bp::type_info type = bp::type_id<T>();
301+
const bp::converter::registration* registration =
302+
bp::converter::registry::query(type);
303+
304+
// If the class is not registered, return None.
305+
if (!registration) {
306+
//std::cerr<<"Class Not Registered. Returning Empty."<<std::endl;
307+
return bp::object();
308+
}
309+
310+
bp::handle<PyTypeObject> handle(bp::borrowed(registration->get_class_object()));
311+
return bp::object(handle);
312+
}
313+
292314
template<typename Scalar>
293315
int registerNewType(PyTypeObject * py_type_ptr = NULL)
294316
{

0 commit comments

Comments
 (0)