FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pybind11/tests/test_class_sh_trampoline_basic.cpp at master · SimplexZhao/pybind11 · GitHub
SimplexZhao
/
pybind11
Public
forked from
pybind/pybind11
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pybind11
/
tests
/
test_class_sh_trampoline_basic.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (44 loc) · 1.88 KB
Breadcrumbs
pybind11
/
tests
/
test_class_sh_trampoline_basic.cpp
Copy path
File metadata and controls
57 lines (44 loc) · 1.88 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
#
include
"
pybind11_tests.h
"
#
include
<
memory
>
namespace
pybind11_tests
{
namespace
class_sh_trampoline_basic
{
struct
Abase
{
int
val =
0
;
virtual
~Abase
() =
default
;
explicit
Abase
(
int
val_) : val{val_} {}
int
Get
()
const
{
return
val *
10
+
3
; }
virtual
int
Add
(
int
other_val)
const
= 0;
//
Some compilers complain about implicitly defined versions of some of the following:
Abase
(
const
Abase &) =
default
;
Abase
(Abase &&)
noexcept
=
default
;
Abase &
operator
=(
const
Abase &) =
default
;
Abase &
operator
=(Abase &&)
noexcept
=
default
;
};
struct
AbaseAlias
: Abase, py::trampoline_self_life_support {
using
Abase::Abase;
int
Add
(
int
other_val)
const
override
{
PYBIND11_OVERRIDE_PURE
(
int
,
/*
Return type
*/
Abase,
/*
Parent class
*/
Add,
/*
Name of function in C++ (must match Python name)
*/
other_val);
}
};
int
AddInCppRawPtr
(
const
Abase *obj,
int
other_val) {
return
obj->
Add
(other_val) *
10
+
7
; }
int
AddInCppSharedPtr
(
const
std::shared_ptr<Abase> &obj,
int
other_val) {
return
obj->
Add
(other_val) *
100
+
11
;
}
int
AddInCppUniquePtr
(std::unique_ptr<Abase> obj,
int
other_val) {
return
obj->
Add
(other_val) *
100
+
13
;
}
}
//
namespace class_sh_trampoline_basic
}
//
namespace pybind11_tests
using
namespace
pybind11_tests
::class_sh_trampoline_basic
;
TEST_SUBMODULE
(class_sh_trampoline_basic, m) {
py::classh<Abase, AbaseAlias>(m,
"
Abase
"
)
.
def
(py::init<
int
>(),
py::arg
(
"
val
"
))
.
def
(
"
Get
"
, &Abase::Get)
.
def
(
"
Add
"
, &Abase::Add,
py::arg
(
"
other_val
"
));
m.
def
(
"
AddInCppRawPtr
"
, AddInCppRawPtr,
py::arg
(
"
obj
"
),
py::arg
(
"
other_val
"
));
m.
def
(
"
AddInCppSharedPtr
"
, AddInCppSharedPtr,
py::arg
(
"
obj
"
),
py::arg
(
"
other_val
"
));
m.
def
(
"
AddInCppUniquePtr
"
, AddInCppUniquePtr,
py::arg
(
"
obj
"
),
py::arg
(
"
other_val
"
));
}
Back
|
FazBrowse Home
|
New Git URL