|
| 1 | +#include "set.hpp" |
| 2 | +#include <boost/python/ssize_t.hpp> |
| 3 | +#include <boost/python.hpp> |
| 4 | + |
| 5 | +namespace boost { |
| 6 | + namespace python { |
| 7 | + namespace detail { |
| 8 | + |
| 9 | + |
| 10 | + detail::new_non_null_reference set_base::call(object_cref arg_) |
| 11 | + { |
| 12 | + return (detail::new_non_null_reference) |
| 13 | + (expect_non_null)( |
| 14 | + PySet_New(arg_.ptr()) |
| 15 | + ); |
| 16 | + } |
| 17 | + |
| 18 | + set_base::set_base() |
| 19 | + : object(detail::new_reference(PySet_New(NULL))) |
| 20 | + {} |
| 21 | + |
| 22 | + set_base::set_base(object_cref sequence) |
| 23 | + : object(set_base::call(sequence)) |
| 24 | + {} |
| 25 | + |
| 26 | + void set_base::add(object_cref x) |
| 27 | + { |
| 28 | + if (PyAnySet_CheckExact(this->ptr())) |
| 29 | + { |
| 30 | + if (PySet_Add(this->ptr(), x.ptr()) == -1) |
| 31 | + throw_error_already_set(); |
| 32 | + } |
| 33 | + else |
| 34 | + { |
| 35 | + this->attr("add")(x); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + void set_base::discard(object_cref x) |
| 41 | + { |
| 42 | + if (PyAnySet_CheckExact(this->ptr())) |
| 43 | + { |
| 44 | + if (PySet_Discard(this->ptr(), x.ptr()) == -1) |
| 45 | + throw_error_already_set(); |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + this->attr("discrad")(x); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + object set_base::pop() |
| 54 | + { |
| 55 | + return this->attr("pop")(); |
| 56 | + } |
| 57 | + |
| 58 | + void set_base::clear() |
| 59 | + { |
| 60 | + this->attr("clear")(); |
| 61 | + } |
| 62 | + |
| 63 | + long set_base::__len__() |
| 64 | + { |
| 65 | + return extract<long>(object(PySet_Size(this->ptr())))(); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + static struct register_set_pytype_ptr |
| 70 | + { |
| 71 | + register_set_pytype_ptr() |
| 72 | + { |
| 73 | + const_cast<converter::registration &>( |
| 74 | + converter::registry::lookup(boost::python::type_id<boost::python::set>()) |
| 75 | + ).m_class_object = &PySet_Type; |
| 76 | + } |
| 77 | + }register_set_pytype_ptr_; |
| 78 | + |
| 79 | + } |
| 80 | + } |
| 81 | +} // namespace boost::python |
0 commit comments