11#include <boost/python/extract.hpp>
12#include <boost/python/list.hpp>
13#include <boost/python/object.hpp>
14#include <boost/variant.hpp>
29 std::vector<boost::recursive_variant_>>::type;
33 PyObject *rawptr =
obj.ptr();
36 if (PyList_Check(rawptr)) {
38 }
else if (PyBool_Check(rawptr)) {
39 out = extract<bool>(
obj);
40 }
else if (PyFloat_Check(rawptr)) {
41 out = extract<double>(
obj);
42 }
else if (PyLong_Check(rawptr)) {
43 out =
static_cast<int>(extract<long>(
obj));
44 }
else if (PyUnicode_Check(rawptr)) {
45 out = extract<std::string>(
obj);
46 }
else if (
auto extractor = extract<Mantid::API::Workspace_sptr>(
obj); extractor.check()) {
49 throw std::invalid_argument(
"Unrecognised Python type");
56 auto rawptr =
obj.ptr();
57 auto n = PyList_Size(rawptr);
58 auto vec = std::vector<PythonOutputT>();
60 for (Py_ssize_t i = 0; i <
n; ++i) {
90 virtual void operator()(std::vector<std::string>)
const = 0;
92 void operator()(std::vector<PyNativeTypeExtractor::PythonOutputT>
const &values)
const {
93 if (values.size() == 0)
95 const auto &elemType = values[0].type();
99 if (elemType ==
typeid(
bool)) {
100 applyVectorProp<bool>(values);
101 }
else if (elemType ==
typeid(
double)) {
102 applyVectorProp<double>(values);
103 }
else if (elemType ==
typeid(
int)) {
104 applyVectorProp<int>(values);
105 }
else if (elemType ==
typeid(std::string)) {
106 applyVectorProp<std::string>(values);
109 for (
const auto &val : values) {
110 boost::apply_visitor(*
this, val);
116 template <
typename ScalarT>
117 void applyVectorProp(
const std::vector<Mantid::PythonInterface::PyNativeTypeExtractor::PythonOutputT> &values)
const {
118 std::vector<ScalarT> propVals;
119 propVals.reserve(values.size());
124 std::transform(values.cbegin(), values.cend(), std::back_inserter(propVals),
126 return boost::get<ScalarT>(varadicVal);
128 }
catch (boost::bad_get &e) {
130 "A list with mixed types is unsupported as precision loss can occur trying to determine a common type."
131 " \nOriginal exception: "};
133 throw std::runtime_error(err + e.what());
double value
The value of the point.
std::vector< T > const * vec
double obj
the value of the quadratic function
The Logger class is in charge of the publishing messages from the framework through various channels.
void operator()(std::vector< PyNativeTypeExtractor::PythonOutputT > const &values) const
virtual void operator()(bool value) const =0
void applyVectorProp(const std::vector< Mantid::PythonInterface::PyNativeTypeExtractor::PythonOutputT > &values) const
virtual void operator()(std::vector< bool >) const =0
virtual void operator()(int value) const =0
virtual void operator()(std::vector< std::string >) const =0
virtual ~IPyTypeVisitor()=default
Dynamically dispatches to overloaded operator depending on the underlying type.
virtual void operator()(std::vector< double >) const =0
virtual void operator()(std::vector< int >) const =0
virtual void operator()(std::string) const =0
virtual void operator()(Mantid::API::Workspace_sptr) const =0
virtual void operator()(double value) const =0
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("DetermineSpinStateOrder")