17#define PY_ARRAY_UNIQUE_SYMBOL KERNEL_ARRAY_API
18#define NO_IMPORT_ARRAY
19#include <numpy/arrayobject.h>
21#include <boost/algorithm/string/predicate.hpp>
22#include <boost/python/extract.hpp>
26template <
typename HeldType>
struct StdVectorExtractor {
27 static std::vector<HeldType> extract(
const boost::python::object &
value) {
28 return boost::python::extract<std::vector<HeldType>>(
value.ptr());
31template <>
struct StdVectorExtractor<bool> {
32 static std::vector<bool> extract(
const boost::python::object & ) {
33 throw std::runtime_error(
"Unable to supported extracting std::vector<bool> from python object");
45template <
typename ContainerType>
47 const boost::python::object &
value)
const {
49 using DestElementType =
typename ContainerType::value_type;
52 if (boost::starts_with(
value.ptr()->ob_type->tp_name,
"std_vector")) {
59 }
else if (PySequence_Check(
value.ptr())) {
63 DestElementType scalar = boost::python::extract<DestElementType>(
value.ptr());
64 alg->
setProperty(name, std::vector<DestElementType>(1, scalar));
79template <
typename ContainerType>
80std::unique_ptr<Kernel::Property>
82 const boost::python::object &validator,
const unsigned int direction)
const {
83 using DestElementType =
typename ContainerType::value_type;
84 using boost::python::extract;
88 ContainerType valueInC;
90 if (boost::starts_with(defaultValue.ptr()->ob_type->tp_name,
"std_vector")) {
91 valueInC = StdVectorExtractor<DestElementType>::extract(defaultValue);
92 }
else if (PySequence_Check(defaultValue.ptr())) {
96 DestElementType scalar = boost::python::extract<DestElementType>(defaultValue.ptr());
97 valueInC = std::vector<DestElementType>(1, scalar);
100 std::unique_ptr<Kernel::Property> valueProp;
102 valueProp = std::make_unique<PropertyWithValue<ContainerType>>(name, valueInC, direction);
104 const IValidator *propValidator = extract<IValidator *>(validator);
105 valueProp = std::make_unique<PropertyWithValue<ContainerType>>(name, valueInC, propValidator->
clone(), direction);
114#define INSTANTIATE(ElementType) template struct DLLExport SequenceTypeHandler<std::vector<ElementType>>;
double value
The value of the point.
#define INSTANTIATE(TYPE)
Interface to PropertyManager.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
IValidator is the basic interface for all validators for properties.
virtual IValidator_sptr clone() const =0
Make a copy of the present type of validator.
The concrete, templated class for properties.
Thin object wrapper around a numpy array.
static bool check(const boost::python::object &obj)
Check if a python object points to an array type object.
bool isNone(PyObject *ptr)
Converter taking an input numpy array and converting it to a std::vector.
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...
std::unique_ptr< Kernel::Property > create(const std::string &name, const boost::python::object &defaultValue, const boost::python::object &validator, const unsigned int direction) const override
Call to create a name property where the value is some container type.
void set(Kernel::IPropertyManager *alg, const std::string &name, const boost::python::object &value) const override
Call to set a named property where the value is some container type.