diff --git a/include/eigenpy/quaternion.hpp b/include/eigenpy/quaternion.hpp index 6635d25dd0c5222591c1b9f178af07bd68df603d..fd2318914e3fdbe5c68ceb2563b0ded9f04f90f2 100644 --- a/include/eigenpy/quaternion.hpp +++ b/include/eigenpy/quaternion.hpp @@ -12,6 +12,49 @@ #include "eigenpy/exception.hpp" +namespace boost { namespace python { namespace converter { + + /// \brief Template specialization of rvalue_from_python_data + template<typename Quaternion> + struct rvalue_from_python_data<Eigen::QuaternionBase<Quaternion> const &> + : rvalue_from_python_data_eigen<Quaternion const &> + { + RVALUE_FROM_PYTHON_DATA_INIT(Quaternion const &) + }; + + template <class Quaternion> + struct implicit<Quaternion, Eigen::QuaternionBase<Quaternion> > + { + typedef Quaternion Source; + typedef Eigen::QuaternionBase<Quaternion> Target; + + static void* convertible(PyObject* obj) + { + // Find a converter which can produce a Source instance from + // obj. The user has told us that Source can be converted to + // Target, and instantiating construct() below, ensures that + // at compile-time. + return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) + ? obj : 0; + } + + static void construct(PyObject* obj, rvalue_from_python_stage1_data* data) + { + void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes; + + arg_from_python<Source> get_source(obj); + bool convertible = get_source.convertible(); + BOOST_VERIFY(convertible); + + new (storage) Source(get_source()); + + // record successful construction + data->convertible = storage; + } + }; + +}}} // namespace boost::python::converter + namespace eigenpy {