forked from BoostGSoC21/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.cpp
More file actions
executable file
·149 lines (119 loc) · 2.79 KB
/
object.cpp
File metadata and controls
executable file
·149 lines (119 loc) · 2.79 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright David Abrahams 2002. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/python/module.hpp>
#include <boost/python/object.hpp>
using namespace boost::python;
object call_object_3(object f)
{
return f(3);
}
object message()
{
return object("hello, world!");
}
object number()
{
return object(42);
}
object obj_getattr(object x, char const* name)
{
return x._(name);
}
object obj_const_getattr(object const& x, char const* name)
{
return x._(name);
}
void obj_setattr(object x, char const* name, object value)
{
x._(name) = value;
}
void obj_setattr42(object x, char const* name)
{
x._(name) = 42;
}
void obj_moveattr(object& x, char const* src, char const* dst)
{
x._(dst) = x._(src);
}
object obj_getitem(object x, object key)
{
return x[key];
}
object obj_getitem3(object x)
{
return x[3];
}
object obj_const_getitem(object const& x, object key)
{
return x[key];
}
void obj_setitem(object x, object key, object value)
{
x[key] = value;
}
void obj_setitem42(object x, object key)
{
x[key] = 42;
}
void obj_moveitem(object& x, object src, object dst)
{
x[dst] = x[src];
}
void obj_moveitem2(object const& x_src, object k_src, object& x_dst, object k_dst)
{
x_dst[k_dst] = x_src[k_src];
}
bool test(object y)
{
return y;
}
bool test_not(object y)
{
return !y;
}
bool test_attr(object y, char* name)
{
return y._(name);
}
bool test_not_attr(object y, char* name)
{
return !y._(name);
}
bool test_item(object y, object key)
{
return y[key];
}
bool test_not_item(object y, object key)
{
return !y[key];
}
BOOST_PYTHON_MODULE_INIT(object_ext)
{
module("object_ext")
.def("call_object_3", call_object_3)
.def("message", message)
.def("number", number)
.def("obj_getattr", obj_getattr)
.def("obj_const_getattr", obj_const_getattr)
.def("obj_setattr", obj_setattr)
.def("obj_setattr42", obj_setattr42)
.def("obj_moveattr", obj_moveattr)
.def("obj_getitem", obj_getitem)
.def("obj_getitem3", obj_getitem)
.def("obj_const_getitem", obj_const_getitem)
.def("obj_setitem", obj_setitem)
.def("obj_setitem42", obj_setitem42)
.def("obj_moveitem", obj_moveitem)
.def("obj_moveitem2", obj_moveitem2)
.def("test", test)
.def("test_not", test_not)
.def("test_attr", test_attr)
.def("test_not_attr", test_not_attr)
.def("test_item", test_item)
.def("test_not_item", test_not_item)
;
}
#include "module_tail.cpp"