11#include <boost/python/class.hpp>
12#include <boost/python/init.hpp>
14#pragma warning(disable : 4267)
16#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
17#include <boost/python/tuple.hpp>
22using boost::python::arg;
25namespace PythonInterface {
31template <
typename ElementType>
inline std::string toString(
const ElementType &
value) {
32 std::ostringstream os;
44template <>
inline std::string toString(
const std::string &
value) {
45 std::ostringstream os;
46 os <<
"'" <<
value <<
"'";
51template <
typename SequenceType,
typename ElementType> std::string toString(
const SequenceType &values) {
52 auto iend = values.end();
53 std::ostringstream os;
54 for (
auto itr = values.begin(); itr != iend;) {
68 using w_t = std::vector<ElementType>;
73 std::string retval(
"[");
74 retval += toString<w_t, ElementType>(values);
80 static void wrap(std::string
const &python_name) {
81 boost::python::class_<w_t, std::shared_ptr<w_t>>(python_name.c_str())
82 .def(boost::python::init<w_t const &>())
83 .def(boost::python::vector_indexing_suite<w_t, NoIndexingProxy>())
96 using w_t = std::set<ElementType>;
97 using e_t = ElementType;
101 static void insert_set(
w_t &self,
w_t const &other) { self.insert(other.begin(), other.end()); }
106 if (i >= self.size()) {
107 PyErr_SetString(PyExc_IndexError,
"Index out of range");
108 boost::python::throw_error_already_set();
110 return *std::next(self.begin(), i);
114 return boost::python::make_tuple(boost::python::tuple(self));
120 std::string retval(
"set(");
121 retval += toString<w_t, ElementType>(values);
126 static void wrap(std::string
const &python_name) {
127 boost::python::class_<w_t, std::shared_ptr<w_t>>(python_name.c_str())
128 .def(boost::python::init<w_t const &>())
131 .def(
"__len__", &w_t::size, arg(
"self"))
132 .def(
"__contains__",
contains, (arg(
"self"), arg(
"element")))
133 .def(
"__getitem__",
getitem, (arg(
"self"), arg(
"index")))
136 .def(
"size", &w_t::size, arg(
"self"))
139 .def(
"insert",
insert_set, (arg(
"self"), arg(
"set")))
140 .def(
"extend",
insert_set, (arg(
"self"), arg(
"set")))
141 .def(
"erase", (std::size_t(
w_t::*)(
e_t const &)) & w_t::erase, (arg(
"self"), arg(
"index")))
142 .def(
"clear", &w_t::clear, arg(
"self"))
double value
The value of the point.
Helper class which provides the Collimation Length for SANS instruments.
std::set< ElementType > w_t
static e_t getitem(w_t const &self, std::size_t i)
static boost::python::tuple getinitargs(w_t const &self)
static void insert_element(w_t &self, e_t const &x)
static void wrap(std::string const &python_name)
static void insert_set(w_t &self, w_t const &other)
static std::string to_string(const w_t &values)
static bool contains(w_t const &self, e_t const &x)
A struct to help export std::vector types.
static std::string to_string(const w_t &values)
static void wrap(std::string const &python_name)
a python wrapper
std::vector< ElementType > w_t
A typedef of a vector of template ElementTypes.