22 #ifndef DATA_CONVERSION_H
23 #define DATA_CONVERSION_H
25 #include <boost/python.hpp>
35 template <
class T_IN,
class T_OUT>
37 static void convert(
const T_IN *, T_OUT &) {
39 s <<
"data conversion from " <<
typeid(T_IN).name() <<
" to type " <<
typeid(T_OUT).name()
40 <<
" is not implemented.";
47 namespace bpy = boost::python;
51 static void convert(
const T_IN *d1, bpy::object &d2)
54 if constexpr((std::is_class_v<T_IN> || std::is_union_v<T_IN>) && !std::is_same_v<std::string, T_IN> )
55 d2 = bpy::object(bpy::ptr(d1));
57 d2 = bpy::object(*d1);
59 catch (
const boost::python::error_already_set&) {
60 std::string error_msg =
"An error occurred while converting C++ data to Python. Please be sure you imported the Python module/s supporting the conversion of this data type";
67 template <
class T_OUT>
69 static void convert(
const bpy::object *d1, T_OUT &d2)
72 d2 = boost::python::extract<T_OUT>(*d1);
74 catch (
const boost::python::error_already_set&) {
75 std::string error_msg =
"An error occurred while converting Python to C++ data";
82 #endif //DATA_CONVERSION_H