Skip to content

Commit 3917a9c

Browse files
authored
Merge pull request #61 from jcarpent/devel
Registration
2 parents 4f72989 + 2bdf6b8 commit 3917a9c

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

cmake

include/eigenpy/angle-axis.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ namespace eigenpy
103103

104104
static void expose()
105105
{
106-
if(check_registration<AngleAxis>()) return;
107-
106+
if(register_symbolic_link_to_registered_type<AngleAxis>()) return;
107+
108108
bp::class_<AngleAxis>("AngleAxis",
109109
"AngleAxis representation of rotations.\n\n",
110110
bp::no_init)

include/eigenpy/quaternion.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ namespace eigenpy
203203

204204
static void expose()
205205
{
206-
if(check_registration<Quaternion>()) return;
207-
206+
if(register_symbolic_link_to_registered_type<Quaternion>()) return;
207+
208208
bp::class_<Quaternion>("Quaternion",
209209
"Quaternion representing rotation.\n\n"
210210
"Supported operations "

include/eigenpy/registration.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define __eigenpy_registration_hpp__
88

99
#include <boost/python.hpp>
10+
#include <boost/python/scope.hpp>
1011

1112
namespace eigenpy
1213
{
@@ -29,6 +30,30 @@ namespace eigenpy
2930

3031
return true;
3132
}
33+
34+
///
35+
/// \brief Symlink to the current scope the already registered class T.
36+
///
37+
/// \returns true if the type T is effectively symlinked.
38+
///
39+
/// \tparam T The type to symlink.
40+
///
41+
template<typename T>
42+
inline bool register_symbolic_link_to_registered_type()
43+
{
44+
namespace bp = boost::python;
45+
46+
if(eigenpy::check_registration<T>())
47+
{
48+
const bp::type_info info = bp::type_id<T>();
49+
const bp::converter::registration* reg = bp::converter::registry::query(info);
50+
bp::handle<> class_obj(reg->get_class_object());
51+
bp::scope().attr(reg->get_class_object()->tp_name) = bp::object(class_obj);
52+
return true;
53+
}
54+
55+
return false;
56+
}
3257
}
3358

3459
#endif // ifndef __eigenpy_registration_hpp__

0 commit comments

Comments
 (0)