14#include <boost/python/class.hpp>
15#include <boost/python/init.hpp>
17#pragma warning(disable : 4267)
19#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
20#include <boost/python/tuple.hpp>
25using boost::python::arg;
28namespace PythonInterface {
34template <
typename ElementType>
inline std::string
toString(
const ElementType &
value) {
35 std::ostringstream os;
48 std::ostringstream os;
49 os <<
"'" <<
value <<
"'";
54template <
typename SequenceType,
typename ElementType> std::string
toString(
const SequenceType &values) {
55 auto iend = values.end();
56 std::ostringstream os;
57 for (
auto itr = values.begin(); itr != iend;) {
71 using w_t = std::vector<ElementType>;
76 std::string retval(
"[");
77 retval += toString<w_t, ElementType>(values);
83 static void wrap(std::string
const &python_name) {
84 boost::python::class_<w_t, std::shared_ptr<w_t>>(python_name.c_str())
85 .def(boost::python::init<w_t const &>())
86 .def(boost::python::vector_indexing_suite<w_t, NoIndexingProxy>())
99 using w_t = std::set<ElementType>;
104 static void insert_set(
w_t &self,
w_t const &other) { self.insert(other.begin(), other.end()); }
109 if (i >= self.size()) {
110 PyErr_SetString(PyExc_IndexError,
"Index out of range");
111 boost::python::throw_error_already_set();
113 return *std::next(self.begin(), i);
117 return boost::python::make_tuple(boost::python::tuple(self));
123 std::string retval(
"set(");
124 retval += toString<w_t, ElementType>(values);
129 static void wrap(std::string
const &python_name) {
130 boost::python::class_<w_t, std::shared_ptr<w_t>>(python_name.c_str())
131 .def(boost::python::init<w_t const &>())
134 .def(
"__len__", &w_t::size, arg(
"self"))
135 .def(
"__contains__",
contains, (arg(
"self"), arg(
"element")))
136 .def(
"__getitem__",
getitem, (arg(
"self"), arg(
"index")))
139 .def(
"size", &w_t::size, arg(
"self"))
142 .def(
"insert",
insert_set, (arg(
"self"), arg(
"set")))
143 .def(
"extend",
insert_set, (arg(
"self"), arg(
"set")))
144 .def(
"erase", (std::size_t (
w_t::*)(
e_t const &))&w_t::erase, (arg(
"self"), arg(
"index")))
145 .def(
"clear", &w_t::clear, arg(
"self"))
double value
The value of the point.
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
std::string toString(const T &value)
Convert values to strings.
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.