diff --git a/CMakeLists.txt b/CMakeLists.txt index a53c4e4ba01c79bbd32c8d16d07b960f35c115ff..dc4ab1504399a61fb25b1743789ed5c065a5bd7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,7 @@ SET(${PROJECT_NAME}_HEADERS ${${PROJECT_NAME}_SOLVERS_HEADERS} include/eigenpy/eigenpy.hpp include/eigenpy/exception.hpp + include/eigenpy/expose.hpp include/eigenpy/details.hpp include/eigenpy/fwd.hpp include/eigenpy/map.hpp diff --git a/include/eigenpy/angle-axis.hpp b/include/eigenpy/angle-axis.hpp index b1371237bd9407e63480f4ebbb9e81481c64a6ae..e7aca37a4e4a366ff3151ce4a57091bd263e0e4d 100644 --- a/include/eigenpy/angle-axis.hpp +++ b/include/eigenpy/angle-axis.hpp @@ -6,20 +6,35 @@ #ifndef __eigenpy_angle_axis_hpp__ #define __eigenpy_angle_axis_hpp__ +#include "eigenpy/fwd.hpp" + #include <boost/python.hpp> #include <Eigen/Core> #include <Eigen/Geometry> -#include "eigenpy/registration.hpp" - namespace eigenpy { namespace bp = boost::python; + + template<typename AngleAxis> class AngleAxisVisitor; + + namespace internal + { + template<typename Scalar> + struct call_expose< Eigen::AngleAxis<Scalar> > + { + typedef Eigen::AngleAxis<Scalar> type; + static inline void run() + { + AngleAxisVisitor<type>::expose(); + } + }; + } // namespace internal template<typename AngleAxis> class AngleAxisVisitor - : public boost::python::def_visitor< AngleAxisVisitor<AngleAxis> > + : public bp::def_visitor< AngleAxisVisitor<AngleAxis> > { typedef typename AngleAxis::Scalar Scalar; @@ -103,8 +118,6 @@ namespace eigenpy static void expose() { - if(register_symbolic_link_to_registered_type<AngleAxis>()) return; - bp::class_<AngleAxis>("AngleAxis", "AngleAxis representation of rotations.\n\n", bp::no_init) diff --git a/include/eigenpy/expose.hpp b/include/eigenpy/expose.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5ce9fc830404ddb2cc52b1e65e7c31237f27c202 --- /dev/null +++ b/include/eigenpy/expose.hpp @@ -0,0 +1,35 @@ +/* + * Copyright 2019, INRIA + */ + +#ifndef __eigenpy_expose_hpp__ +#define __eigenpy_expose_hpp__ + +#include "eigenpy/registration.hpp" + +namespace eigenpy +{ + namespace internal + { + /// + /// \brief Allows a template specialization. + /// + template<typename T> + struct call_expose + { + static inline void run() { T::expose(); } + }; + } // namespace internal + + /// + /// \brief Call the expose function of a given type T. + /// + template<typename T> + inline void expose() + { + if(not register_symbolic_link_to_registered_type<T>()) + internal::call_expose<T>::run(); + } +} + +#endif // ifndef __eigenpy_expose_hpp__ diff --git a/include/eigenpy/fwd.hpp b/include/eigenpy/fwd.hpp index 2c8870ce50b10c53fef81a6de40b871c4f1a7b47..d4469498887e3d2e6d787ff58ab2a27d4fc74902 100644 --- a/include/eigenpy/fwd.hpp +++ b/include/eigenpy/fwd.hpp @@ -26,5 +26,7 @@ #define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Unaligned #endif +#include "eigenpy/expose.hpp" + #endif // ifndef __eigenpy_fwd_hpp__ diff --git a/include/eigenpy/quaternion.hpp b/include/eigenpy/quaternion.hpp index ed289d0e43882c9795a09a5c9606a17b64afdc0d..2017d4ea14a942d63fc7613330071ba13546e110 100644 --- a/include/eigenpy/quaternion.hpp +++ b/include/eigenpy/quaternion.hpp @@ -6,6 +6,8 @@ #ifndef __eigenpy_quaternion_hpp__ #define __eigenpy_quaternion_hpp__ +#include "eigenpy/fwd.hpp" + #include <Eigen/Core> #include <Eigen/Geometry> @@ -27,9 +29,24 @@ namespace eigenpy namespace bp = boost::python; + template<typename QuaternionDerived> class QuaternionVisitor; + + namespace internal + { + template<typename Scalar, int Options> + struct call_expose< Eigen::Quaternion<Scalar,Options> > + { + typedef Eigen::Quaternion<Scalar,Options> type; + static inline void run() + { + QuaternionVisitor<type>::expose(); + } + }; + } // namespace internal + template<typename Quaternion> class QuaternionVisitor - : public boost::python::def_visitor< QuaternionVisitor<Quaternion> > + : public bp::def_visitor< QuaternionVisitor<Quaternion> > { typedef Eigen::QuaternionBase<Quaternion> QuaternionBase; @@ -203,8 +220,6 @@ namespace eigenpy static void expose() { - if(register_symbolic_link_to_registered_type<Quaternion>()) return; - bp::class_<Quaternion>("Quaternion", "Quaternion representing rotation.\n\n" "Supported operations " diff --git a/src/angle-axis.cpp b/src/angle-axis.cpp index 56999b9a6c5938f1ee44eca5858836482456af4b..f4e33ef0e56839457f1fbf57a379900462852f6c 100644 --- a/src/angle-axis.cpp +++ b/src/angle-axis.cpp @@ -13,6 +13,6 @@ namespace eigenpy { void exposeAngleAxis() { - AngleAxisVisitor<Eigen::AngleAxisd>::expose(); + expose<Eigen::AngleAxisd>(); } } // namespace eigenpy diff --git a/src/quaternion.cpp b/src/quaternion.cpp index 5690ef44f7da1466b69e45499c495041705d39bf..4ffa866c3537af1715493a65be342be9e1b6b79a 100644 --- a/src/quaternion.cpp +++ b/src/quaternion.cpp @@ -13,6 +13,6 @@ namespace eigenpy { void exposeQuaternion() { - QuaternionVisitor<Eigen::Quaterniond>::expose(); + expose<Eigen::Quaterniond>(); } } // namespace eigenpy