32 #ifndef _MIRA_TOOLBOXES_PYTHON_PYTHONSET_H_ 33 #define _MIRA_TOOLBOXES_PYTHON_PYTHONSET_H_ 42 namespace mira {
namespace python {
46 template<
typename type>
53 for(
const auto& e : s) {
59 MIRA_THROW(XIO,
"Failed to convert value into a string");
70 return s.count(key)>0;
74 s.insert(std::move(key));
86 std::set_union(s.begin(), s.end(), other.begin(), other.end(),
87 inserter(result, result.begin()));
94 std::set_intersection(s.begin(), s.end(), other.begin(), other.end(),
95 inserter(result, result.begin()));
102 std::set_difference(s.begin(), s.end(), other.begin(), other.end(),
103 inserter(result, result.begin()));
110 std::set_symmetric_difference(s.begin(), s.end(), other.begin(), other.end(),
111 inserter(result, result.begin()));
118 MIRA_THROW(XInvalidParameter,
"objects of type python object are unhashable");
121 #define MIRA_PYTHONCONNECTOR_PYTHONSET_FUNCTIONS(type, name, footerfunctions) \ 122 class_<std::set<type> >(name, "mutable set") \ 123 .def("__repr__", &PythonSetAccessor<type>::str) \ 124 .def("__len__", &PythonSetAccessor<type>::size) \ 125 .def("__contains__", &PythonSetAccessor<type>::contains) \ 126 .def("add", &PythonSetAccessor<type>::add, "add element") \ 127 .def("__delitem__", &PythonSetAccessor<type>::remove) \ 128 .def("remove", &PythonSetAccessor<type>::remove, "remove element") \ 129 .def("__iter__", boost::python::iterator<std::set<type> >()) \ 130 .def("__hash__", block_hashing) \ 131 .def("union", &PythonSetAccessor<type>::set_union, "set union") \ 132 .def("__or__", &PythonSetAccessor<type>::set_union, "set union") \ 133 .def("intersection", &PythonSetAccessor<type>::set_intersection, "set intersection") \ 134 .def("__and__", &PythonSetAccessor<type>::set_intersection, "set intersection") \ 135 .def("difference", &PythonSetAccessor<type>::set_difference, "elements not in second set") \ 136 .def("__sub__", &PythonSetAccessor<type>::set_difference, "set difference") \ 137 .def("symmetric_difference", &PythonSetAccessor<type>::set_symmetric_difference, "elements unique to either set") \ 138 .def("__xor__", &PythonSetAccessor<type>::set_symmetric_difference, "symmetric set difference") \
static bool contains(const SetType &s, const type &key)
Definition: PythonSet.h:69
void block_hashing(boost::python::object)
Definition: PythonSet.h:116
#define MIRA_THROW(ex, msg)
static SetType set_symmetric_difference(const SetType &s, const SetType &other)
Definition: PythonSet.h:107
static SetType set_union(const SetType &s, const SetType &other)
Definition: PythonSet.h:83
static void add(SetType &s, type key)
Definition: PythonSet.h:73
PropertyHint type(const std::string &t)
static SetType set_intersection(const SetType &s, const SetType &other)
Definition: PythonSet.h:91
static SetType set_difference(const SetType &s, const SetType &other)
Definition: PythonSet.h:99
Include this instead of boost/python.hpp to reduce compile time warning spam from Boost internal inco...
static std::string str(const SetType &s)
Definition: PythonSet.h:49
std::set< type > SetType
Definition: PythonSet.h:48
static int size(const SetType &s)
Definition: PythonSet.h:65
Definition: PythonSet.h:47