Program Listing for File registration.hpp

Return to documentation for file (include/eigenpy/registration.hpp)

/*
 * Copyright 2014-2019, CNRS
 * Copyright 2018-2019, INRIA
 */

#ifndef __eigenpy_registration_hpp__
#define __eigenpy_registration_hpp__

#include "eigenpy/fwd.hpp"
#include "eigenpy/registration_class.hpp"

namespace eigenpy {

template <typename T>
inline bool check_registration() {
  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;
}

template <typename T>
inline bool register_symbolic_link_to_registered_type() {
  if (eigenpy::check_registration<T>()) {
    const bp::type_info info = bp::type_id<T>();
    const bp::converter::registration* reg =
        bp::converter::registry::query(info);
    bp::handle<> class_obj(reg->get_class_object());
    bp::incref(class_obj.get());
    bp::scope().attr(reg->get_class_object()->tp_name) = bp::object(class_obj);
    return true;
  }

  return false;
}

template <typename T, typename Visitor>
inline bool register_symbolic_link_to_registered_type(const Visitor& visitor) {
  if (eigenpy::check_registration<T>()) {
    const bp::type_info info = bp::type_id<T>();
    const bp::converter::registration* reg =
        bp::converter::registry::query(info);
    bp::handle<> class_obj(reg->get_class_object());
    bp::incref(class_obj.get());
    bp::object object(class_obj);
    bp::scope().attr(reg->get_class_object()->tp_name) = object;
    registration_class<T> cl(object);
    cl.def(visitor);
    return true;
  }

  return false;
}
}  // namespace eigenpy

#endif  // ifndef __eigenpy_registration_hpp__