FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/test/a_map_indexing_suite.cpp at python313 · boostorg/python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
boostorg
/
python
Public
Notifications
You must be signed in to change notification settings
Fork
223
Star
537
Code
Issues
173
Pull requests
34
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
test
/
a_map_indexing_suite.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (76 loc) · 1.92 KB
Breadcrumbs
python
/
test
/
a_map_indexing_suite.cpp
Copy path
File metadata and controls
92 lines (76 loc) · 1.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Copyright Joel de Guzman 2004. 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/suite/indexing/map_indexing_suite.hpp
>
#
include
<
boost/python/module.hpp
>
#
include
<
boost/python/def.hpp
>
#
include
<
boost/python/implicit.hpp
>
using
namespace
boost
::python
;
struct
A
{
int
value;
A
() : value(
0
){};
A
(
int
v) : value(v) {};
};
bool
operator
==(
const
A& v1,
const
A& v2)
{
return
(v1.
value
== v2.
value
);
}
struct
B
{
A a;
};
//
Converter from A to python int
struct
AToPython
{
static
PyObject*
convert
(
const
A& s)
{
return
boost::python::incref
(
boost::python::object
((
int
)s.
value
).
ptr
());
}
};
//
Conversion from python int to A
struct
AFromPython
{
AFromPython
()
{
boost::python::converter::registry::push_back
(
&convertible,
&construct,
boost::python::type_id< A >());
}
static
void
*
convertible
(PyObject* obj_ptr)
{
#
if
PY_VERSION_HEX >= 0x03000000
if
(!
PyLong_Check
(obj_ptr))
return
0
;
#
else
if
(!
PyInt_Check
(obj_ptr))
return
0
;
#
endif
return
obj_ptr;
}
static
void
construct
(
PyObject* obj_ptr,
boost::python::converter::rvalue_from_python_stage1_data* data)
{
void
* storage = (
(boost::python::converter::rvalue_from_python_storage< A >*)
data)-> storage.
bytes
;
#
if
PY_VERSION_HEX >= 0x03000000
new
(storage)
A
((
int
)
PyLong_AsLong
(obj_ptr));
#
else
new
(storage)
A
((
int
)
PyInt_AsLong
(obj_ptr));
#
endif
data->
convertible
= storage;
}
};
void
a_map_indexing_suite
()
{
to_python_converter< A , AToPython >();
AFromPython
();
class_< std::map<
int
, A> >(
"
AMap
"
)
.
def
(map_indexing_suite<std::map<
int
, A>,
true
>())
;
class_< B >(
"
B
"
)
.
add_property
(
"
a
"
,
make_getter
(&B::a, return_value_policy<return_by_value>()),
make_setter
(&B::a, return_value_policy<return_by_value>()))
;
}
Back
|
FazBrowse Home
|
New Git URL