9#include <boost/python/extract.hpp>
10#include <boost/python/object.hpp>
16namespace PythonInterface {
22template <
typename CType>
struct ExtractCType {
28 inline CType operator()(PyObject *
value) {
return boost::python::extract<CType>(
value); }
34template <>
struct ExtractCType<
std::string> {
40 inline std::string operator()(PyObject *
value) {
return boost::python::extract<std::string>(PyObject_Str(
value)); }
73 ExtractCType<DestElementType> elementConverter;
75 for (
size_t i = 0; i < length; ++i) {
76 dest[i] = elementConverter(PySequence_GetItem(
ptr(), i));
81 inline PyObject *
ptr()
const {
return m_obj.ptr(); }
83 inline std::size_t
srcSize()
const {
return static_cast<size_t>(PySequence_Size(
ptr())); }
87 throw std::invalid_argument(
"Length mismatch between python list & C array. python=" +
std::to_string(
srcSize()) +
double value
The value of the point.
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