Skip to content
Snippets Groups Projects
Commit 90ff656d authored by jcarpent's avatar jcarpent
Browse files

[C++] Add check of registration at runtime

parent 6a502cde
No related branches found
No related tags found
No related merge requests found
...@@ -81,6 +81,7 @@ SET(HEADERS ...@@ -81,6 +81,7 @@ SET(HEADERS
src/map.hpp src/map.hpp
src/geometry.hpp src/geometry.hpp
src/memory.hpp src/memory.hpp
src/registration.hpp
src/angle-axis.hpp src/angle-axis.hpp
src/quaternion.hpp src/quaternion.hpp
) )
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <iostream> #include <iostream>
#include "eigenpy/eigenpy.hpp" #include "eigenpy/eigenpy.hpp"
#include "eigenpy/registration.hpp"
#include "eigenpy/exception.hpp" #include "eigenpy/exception.hpp"
#include "eigenpy/map.hpp" #include "eigenpy/map.hpp"
...@@ -206,6 +207,7 @@ namespace eigenpy ...@@ -206,6 +207,7 @@ namespace eigenpy
template<typename MatType,typename EigenEquivalentType> template<typename MatType,typename EigenEquivalentType>
void enableEigenPySpecific() void enableEigenPySpecific()
{ {
if(check_registration<MatType>()) return;
numpy_import_array(); numpy_import_array();
boost::python::to_python_converter<MatType,EigenToPy<MatType,MatType> >(); boost::python::to_python_converter<MatType,EigenToPy<MatType,MatType> >();
......
/* /*
* Copyright (c) 2015 LAAS-CNRS * Copyright (c) 2015-2016 LAAS-CNRS
* *
* This file is part of eigenpy. * This file is part of eigenpy.
* eigenpy is free software: you can redistribute it and/or * eigenpy is free software: you can redistribute it and/or
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
* with eigenpy. If not, see <http://www.gnu.org/licenses/>. * with eigenpy. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <eigenpy/exception.hpp> #include "eigenpy/exception.hpp"
#include "eigenpy/registration.hpp"
namespace eigenpy namespace eigenpy
...@@ -30,6 +31,8 @@ namespace eigenpy ...@@ -30,6 +31,8 @@ namespace eigenpy
void Exception::registerException() void Exception::registerException()
{ {
if(check_registration<eigenpy::Exception>()) return;
pyType = boost::python::class_<eigenpy::Exception> pyType = boost::python::class_<eigenpy::Exception>
("Exception",boost::python::init<std::string>()) ("Exception",boost::python::init<std::string>())
.add_property("message", &eigenpy::Exception::copyMessage) .add_property("message", &eigenpy::Exception::copyMessage)
......
/*
* 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__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment