10#include <boost/python/extract.hpp>
11#include <boost/python/object.hpp>
15namespace PythonInterface {
21template <
typename CType>
struct ExtractCType {
27 inline CType operator()(PyObject *
value) {
return boost::python::extract<CType>(
value); }
33template <>
struct ExtractCType<
std::string> {
39 inline std::string operator()(PyObject *
value) {
return boost::python::extract<std::string>(PyObject_Str(
value)); }
71 throwIfSizeMismatched(dest);
72 ExtractCType<DestElementType> elementConverter;
73 auto length = srcSize();
74 for (
size_t i = 0; i < length; ++i) {
75 dest[i] = elementConverter(PySequence_GetItem(ptr(), i));
80 inline PyObject *
ptr()
const {
return m_obj.ptr(); }
82 inline std::size_t
srcSize()
const {
return static_cast<size_t>(PySequence_Size(ptr())); }
85 if (srcSize() != dest.size()) {
86 throw std::invalid_argument(
"Length mismatch between python list & C array. python=" +
std::to_string(srcSize()) +
double value
The value of the point.
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...
void throwIfSizeMismatched(const TypedVector &dest) const
TypedVector operator()()
Converts the Python object to a C++ vector.
std::vector< DestElementType > TypedVector
PySequenceToVector(const boost::python::object &value)
void copyTo(TypedVector &dest)
Fill the container with data from the array.
boost::python::object m_obj
Python object to convert.
std::size_t srcSize() const