@@ -97,6 +97,15 @@ namespace boost { namespace python { namespace detail {
9797 ::boost::python::detail::referent_size<StorageType&>::value
9898 > type;
9999 };
100+
101+ template <typename MatType, int Options, typename Stride>
102+ struct referent_storage <const Eigen::Ref<const MatType,Options,Stride> &>
103+ {
104+ typedef ::eigenpy::details::referent_storage_eigen_ref<const MatType,Options,Stride> StorageType;
105+ typedef aligned_storage<
106+ ::boost::python::detail::referent_size<StorageType&>::value
107+ > type;
108+ };
100109#endif
101110}}}
102111
@@ -167,7 +176,8 @@ namespace boost { namespace python { namespace converter {
167176#undef RVALUE_FROM_PYTHON_DATA_INIT
168177
169178 template <typename MatType, int Options, typename Stride>
170- struct rvalue_from_python_data <Eigen::Ref<MatType,Options,Stride> &> : rvalue_from_python_storage<Eigen::Ref<MatType,Options,Stride> &>
179+ struct rvalue_from_python_data <Eigen::Ref<MatType,Options,Stride> &>
180+ : rvalue_from_python_storage<Eigen::Ref<MatType,Options,Stride> &>
171181 {
172182 typedef Eigen::Ref<MatType,Options,Stride> T;
173183
@@ -202,6 +212,43 @@ namespace boost { namespace python { namespace converter {
202212 }
203213 };
204214
215+ template <typename MatType, int Options, typename Stride>
216+ struct rvalue_from_python_data <const Eigen::Ref<const MatType,Options,Stride> &>
217+ : rvalue_from_python_storage<const Eigen::Ref<const MatType,Options,Stride> &>
218+ {
219+ typedef const Eigen::Ref<const MatType,Options,Stride> T;
220+
221+ # if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
222+ && (!defined (__EDG_VERSION__) || __EDG_VERSION__ >= 245 ) \
223+ && (!defined (__DECCXX_VER) || __DECCXX_VER > 60590014 ) \
224+ && !defined (BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing this */
225+ // This must always be a POD struct with m_data its first member.
226+ BOOST_STATIC_ASSERT (BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,stage1) == 0);
227+ # endif
228+
229+ // The usual constructor
230+ rvalue_from_python_data (rvalue_from_python_stage1_data const & _stage1)
231+ {
232+ this ->stage1 = _stage1;
233+ }
234+
235+ // This constructor just sets m_convertible -- used by
236+ // implicitly_convertible<> to perform the final step of the
237+ // conversion, where the construct() function is already known.
238+ rvalue_from_python_data (void * convertible)
239+ {
240+ this ->stage1 .convertible = convertible;
241+ }
242+
243+ // Destroys any object constructed in the storage.
244+ ~rvalue_from_python_data ()
245+ {
246+ typedef ::eigenpy::details::referent_storage_eigen_ref<const MatType, Options,Stride> StorageType;
247+ if (this ->stage1 .convertible == this ->storage .bytes )
248+ static_cast <StorageType *>((void *)this ->storage .bytes )->~StorageType ();
249+ }
250+ };
251+
205252} } }
206253
207254namespace eigenpy
@@ -384,6 +431,10 @@ namespace eigenpy
384431 // Add conversion to Eigen::Ref<MatType>
385432 typedef Eigen::Ref<MatType> RefType;
386433 EigenFromPy<RefType>::registration ();
434+
435+ // Add conversion to Eigen::Ref<MatType>
436+ typedef const Eigen::Ref<const MatType> ConstRefType;
437+ EigenFromPy<ConstRefType>::registration ();
387438#endif
388439 }
389440 };
@@ -442,6 +493,26 @@ namespace eigenpy
442493 }
443494 };
444495
496+ template <typename MatType, int Options, typename Stride>
497+ struct EigenFromPy <const Eigen::Ref<const MatType,Options,Stride> >
498+ {
499+ typedef const Eigen::Ref<const MatType,Options,Stride> ConstRefType;
500+ typedef typename MatType::Scalar Scalar;
501+
502+ // / \brief Determine if pyObj can be converted into a MatType object
503+ static void * convertible (PyArrayObject * pyArray)
504+ {
505+ return EigenFromPy<MatType>::convertible (pyArray);
506+ }
507+
508+ static void registration ()
509+ {
510+ bp::converter::registry::push_back
511+ (reinterpret_cast <void *(*)(_object *)>(&EigenFromPy::convertible),
512+ &eigen_from_py_construct<ConstRefType>,bp::type_id<ConstRefType>());
513+ }
514+ };
515+
445516 // Template specialization for Eigen::Ref
446517 template <typename MatType>
447518 struct EigenFromPyConverter < eigenpy::Ref<MatType> >
0 commit comments