forked from boostorg/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.cpp
More file actions
83 lines (68 loc) · 1.53 KB
/
set.cpp
File metadata and controls
83 lines (68 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright Fady Essam 2019. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python/set.hpp>
namespace boost {
namespace python {
namespace detail {
detail::new_non_null_reference set_base::call(object_cref arg_)
{
return (detail::new_non_null_reference)
(expect_non_null)(
PySet_New(arg_.ptr())
);
}
set_base::set_base()
: object(detail::new_reference(PySet_New(NULL)))
{}
set_base::set_base(object_cref sequence)
: object(set_base::call(sequence))
{}
void set_base::add(object_cref x)
{
if (PyAnySet_CheckExact(this->ptr()))
{
if (PySet_Add(this->ptr(), x.ptr()) == -1)
throw_error_already_set();
}
else
{
this->attr("add")(x);
}
}
void set_base::discard(object_cref x)
{
if (PyAnySet_CheckExact(this->ptr()))
{
if (PySet_Discard(this->ptr(), x.ptr()) == -1)
throw_error_already_set();
}
else
{
this->attr("discrad")(x);
}
}
object set_base::pop()
{
return this->attr("pop")();
}
void set_base::clear()
{
this->attr("clear")();
}
long set_base::__len__()
{
return extract<long>(object(PySet_Size(this->ptr())))();
}
static struct register_set_pytype_ptr
{
register_set_pytype_ptr()
{
const_cast<converter::registration &>(
converter::registry::lookup(boost::python::type_id<boost::python::set>())
).m_class_object = &PySet_Type;
}
}register_set_pytype_ptr_;
}
}
}