diff --git a/CMakeLists.txt b/CMakeLists.txt index 4962eb9b1df2e20a6498d078fb0af094424847cd..8acb0ef3541fb22c64eef8148a37497e690f1d83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ SET(HEADERS src/map.hpp src/geometry.hpp src/memory.hpp + src/registration.hpp src/angle-axis.hpp src/quaternion.hpp ) diff --git a/src/details.hpp b/src/details.hpp index 8ca96c9ebffe03201a6330d08944252cacc6694b..406b1338937e46d14fe81a7ec67bb45325b8496c 100644 --- a/src/details.hpp +++ b/src/details.hpp @@ -24,6 +24,7 @@ #include <iostream> #include "eigenpy/eigenpy.hpp" +#include "eigenpy/registration.hpp" #include "eigenpy/exception.hpp" #include "eigenpy/map.hpp" @@ -206,6 +207,7 @@ namespace eigenpy template<typename MatType,typename EigenEquivalentType> void enableEigenPySpecific() { + if(check_registration<MatType>()) return; numpy_import_array(); boost::python::to_python_converter<MatType,EigenToPy<MatType,MatType> >(); diff --git a/src/exception.cpp b/src/exception.cpp index b8ac24cad2b7e9063becd5d7ae31255b3172124e..e67b2987606b6d3b15b6c0cd1528a8a90ffb5879 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 LAAS-CNRS + * Copyright (c) 2015-2016 LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or @@ -14,7 +14,8 @@ * with eigenpy. If not, see <http://www.gnu.org/licenses/>. */ -#include <eigenpy/exception.hpp> +#include "eigenpy/exception.hpp" +#include "eigenpy/registration.hpp" namespace eigenpy @@ -30,6 +31,8 @@ namespace eigenpy void Exception::registerException() { + if(check_registration<eigenpy::Exception>()) return; + pyType = boost::python::class_<eigenpy::Exception> ("Exception",boost::python::init<std::string>()) .add_property("message", &eigenpy::Exception::copyMessage) diff --git a/src/registration.hpp b/src/registration.hpp new file mode 100644 index 0000000000000000000000000000000000000000..482335f38c961a717961c9421e45b86ba6d70d09 --- /dev/null +++ b/src/registration.hpp @@ -0,0 +1,45 @@ +/* + * Copyright 2016, Justin Carpentier, LAAS-CNRS + * + * This file is part of eigenpy. + * eigenpy is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * eigenpy is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. You should + * have received a copy of the GNU Lesser General Public License along + * with eigenpy. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __eigenpy_registration_hpp__ +#define __eigenpy_registration_hpp__ + +#include <boost/python.hpp> + +namespace eigenpy +{ + /// + /// \brief Check at runtime the registration of the type T inside the boost python registry. + /// + /// \tparam T The type to check the registration. + /// + /// \returns true if the type T is already registered. + /// + template<typename T> + inline bool check_registration() + { + namespace bp = boost::python; + + const bp::type_info info = bp::type_id<T>(); + const bp::converter::registration* reg = bp::converter::registry::query(info); + if (reg == NULL) return false; + else if ((*reg).m_to_python == NULL) return false; + + return true; + } +} + +#endif // ifndef __eigenpy_registration_hpp__