/* * Copyright (c) hikyuu.org * * Created on: 2020-6-25 * Author: fasiondog */ #pragma once #ifndef HIKYUU_PYBIND_UTILS_H #define HIKYUU_PYBIND_UTILS_H #include #include namespace py = boost::python; template struct vector_to_python_list { static PyObject* convert(T const& x) { py::list pylist; for (auto const& d : x) { pylist.append(d); } return py::incref(pylist.ptr()); } }; // namespace boost::pythontemplatestructvector_to_python_list #define VECTOR_TO_PYTHON_CONVERT(vectorname) \ py::to_python_converter, false>() template T python_list_to_vector(py::list pylist) { size_t total = py::len(pylist); T result(total); for (size_t i = 0; i < total; i++) { result[i] = py::extract(pylist[i])(); } return result; } #endif // HIKYUU_PYBIND_UTILS_H